LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   [SOLVED] script+crontab (https://www.linuxquestions.org/questions/linux-newbie-8/%5Bsolved%5D-script-crontab-810175/)

simplycomplex 05-26-2010 04:45 AM

[SOLVED] script+crontab
 
Hello,
I need help please.
One of my script don't execute itself using crontab although it works manually.

=> /var/log/cron
/var/log/cron show these 2 lignes at sheduled time
May 26 09:59:01 COMPUTER crond[26439]: (root) CMD (/usr/local/bin/script)
May 26 09:59:01 COMPUTER crond[26438]: (root) MAIL (mailed 77 bytes of output but got status 0x0001 )
When i launch it manually the job is done and a third line appears :
May 26 10:15:01 COMPUTER crond[27784]: (root) CMD (LANG=C LC_ALL=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg --lock-file /var/lock/mrtg/mrtg_l --confcache-file /var/lib/mrtg/mrtg.ok)

I am root and i use crontab -e to modify the crontab.
Root is the owner of the script and rights are ok

=> The script is :
#!/bin/bash

nas1=10.91.0.198:/mnt/NAS1
mnt1=/media/nas20091

if mount.nfs $nas1 $mnt1
then
rsync -rltDv --del --ignore-errors --force /home/ $mnt1/SLR/script/ > /var/log/nas/rapport_script_du_`date +\%d-\%m-\%y`.log
umount $mnt1
else
echo echec
fi

=> crontab -l :*
#comments
23 30 * * 1,3,5 /usr/local/bin/script

service crond is ok and restarted*after each modification, crontab is ok i tested it with others scripts.
it is a centos 5.2

ps : sorry for my english, i am french

vikas027 05-26-2010 05:06 AM

What are these * in your script ?

Code:

#!/bin/bash
*
nas1=10.91.0.198:/mnt/NAS1
mnt1=/media/nas20091
*
if mount.nfs $nas1 $mnt1
then
******* rsync -rltDv --del --ignore-errors --force /home/ $mnt1/SLR/script/ > /var/log/nas/rapport_script_du_`date +\%d-\%m-\%y`.log
******* umount $mnt1
else
******* echo echec
fi
*


simplycomplex 05-26-2010 05:13 AM

modified, bad paste from openoffice. The're just spaces.

PMP 05-26-2010 06:08 AM

1. Redirect the standard error and standard out to a file to see for any possible error.
Modify your crontab entry to

Code:

23 30 * * 1,3,5 /usr/local/bin/script >> /tmp/script.out 2>&1
2. This script will execute @ 11:30 PM on mon, wed, fri. I hope you are checking the result after this only

3. It is a good practice to use absolute path to commands specially when the script is expected to be run via crond

simplycomplex 05-26-2010 06:17 AM

1. /usr/local/bin/savenas1lumeve: line 6: mount.nfs: command not found
echec

2. yes, i checked the result after this.

=> i don't understand the result (mount.nfs: command not found), do i need something more to launch it by crontab although it works when i launch the script directly ?

catkin 05-26-2010 06:25 AM

Quote:

Originally Posted by simplycomplex (Post 3981614)
i don't understand the result (mount.nfs: command not found), do i need something more to launch it by crontab althought It works when i lauch the script directly ?

cron sets a limited $PATH. The workaround is either to set $PATH or give the full path for every command. If choosing the former, put something like this at the beginning of the script (you could check what $PATH is when yoou are logged on as root and adjust accordingly)
Code:

export PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin

simplycomplex 05-26-2010 06:36 AM

I added this line at the beginning of the script and it works.
thanks a lot ! ;)


All times are GMT -5. The time now is 05:25 AM.