I set up a cronjob yesterday to excute this morning at 4am. The problem I am experiencing is that the script that is executed cannot find specified files which it is suppose to run like my file.sql and other various scripts which are in the same directory as the exucutable script.
Do I need to specify the paths of the file.sql script or could it be that the cronjob executes in it's own directory?
The best thing I can recommend would be to use full path names in the script to other jobs you are calling.
Also, cron normally changes directory to your home directory - this of course depends on your version/release of cron. So even if you execute the $HOME/cronscripts/tmp.job script, it will execute as if you were sitting in your home directory and typed cronscripts/tmp.job
Another quick hint that has made it easier when building scripts that call other executables:
If you have a bunch of files in similar or the same directory, use variables:
It just seems to keep it simpler, plus, if you ever have to move your script, they're easier to "fix".
I managed to add a "cd" command to the directory I am calling the script from which seems to sort the problem out. I am however going to play around with it as you suggested.
Most environments are setup so that when you log into unix you login through a profile that sets your default paths, etc for your session. cron does not get these unless you set them.
if your script is ksh you can put a statement in the script to set your environment... ie - if your default profile is the system profile in the /etc (maintained by the admin) you can put
. /etc/profile
in your script and it will set your environment for you. Note the space between the . and the /etc
If you then want to see your environment settings, you can use command set and put it out to a file.
example: set >/tmp/oc$$.set where oc$$ will be your proccess id.
How to set cronjob for 48 hours.
I can set for 2 days as shown below.
* * */2 * *
It is creating confusion for 30 days & 31 days per month. (3 Replies)
I'm running a few cronjobs under a differnt user name that basically do the same thing:
/usr/bin/find /home/userid/userid/archives -mtime +30 -type f -exec /usr/bin/gzip -1vN {} \\\; ; /usr/bin/mv /home/userid/userid/archives/*.gz /msgs/archive_msgs >/dev/null 2>&1
Seems to be working except... (12 Replies)
Dear all,
I wrote a script and set it as a cron job to automatically download the data from the website.
Here is the problem, when I run this script in terminal, it works well, while it can not download the files when I run it as a cron job, I feel so weird.
The script as follows:... (28 Replies)
Hi I am very new to linux. I want to run a cronjob every 15 minutes that checks a directory for files. If the directory contains more than ten files I want it to send an email to me.
All I have is this...
*/15 * * * * ls -l | wc -l | | mail -s "This is just a test"
I would... (2 Replies)
hi everyone I'm newbie in this forum hope I can get some help here :)
I have a command in crontab that executed every 1 minute
sometime this command need more than 1 minute to finish
the problem is, the crontab execute this command although it's not finish processing yet and causing the system... (7 Replies)
Hi,
I want to schedule a script on daily basis in morning 8:00 A.M and 5:00 P.M , how can i achieve this, i want the parameter
0 ? * * *
what will be the second parameter in my case.
Regards (1 Reply)
hi
iam new at unix.iam running a cronjob,which i want to run on the first day of every month at 1AM.this is what i have specified:
00 01 1 * *
is this corect? (1 Reply)
Dear Guru,
I have submitted some cronjobs that has been running for quite sometimes. However, today I counter some cronjob did not run. Can you please explain what causes this to happen. Any system setting that limit number of cronjob per minutes to be started, etc?
Thanks.
Kelly (1 Reply)
Please can someone help me. I need to set up a cron job to measure CPU usage, Disk I/O and memory usage over a period of 1 minute along with the number of users logged into the system. I also need to send it to another user besides myself every hour. Please can someone help me! Thanks. (4 Replies)