LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-26-2010, 05:45 AM   #1
simplycomplex
LQ Newbie
 
Registered: May 2010
Posts: 4

Rep: Reputation: 0
Question [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

Last edited by simplycomplex; 05-26-2010 at 07:37 AM. Reason: solved
 
Old 05-26-2010, 06:06 AM   #2
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Debian, OS X
Posts: 1,298

Rep: Reputation: 102Reputation: 102
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
*
 
Old 05-26-2010, 06:13 AM   #3
simplycomplex
LQ Newbie
 
Registered: May 2010
Posts: 4

Original Poster
Rep: Reputation: 0
modified, bad paste from openoffice. The're just spaces.
 
Old 05-26-2010, 07:08 AM   #4
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
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
 
Old 05-26-2010, 07:17 AM   #5
simplycomplex
LQ Newbie
 
Registered: May 2010
Posts: 4

Original Poster
Rep: Reputation: 0
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 ?

Last edited by simplycomplex; 05-26-2010 at 07:23 AM. Reason: synthax
 
Old 05-26-2010, 07:25 AM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by simplycomplex View Post
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

Last edited by catkin; 05-26-2010 at 07:26 AM. Reason: Added missing "set $PATH or "
 
Old 05-26-2010, 07:36 AM   #7
simplycomplex
LQ Newbie
 
Registered: May 2010
Posts: 4

Original Poster
Rep: Reputation: 0
Smile

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
time script without using crontab sunlinux Linux - Newbie 10 05-28-2010 02:18 AM
Runs Multiple shell script inside a main script using crontab srimal Linux - Newbie 4 10-22-2009 07:19 PM
crontab and a bash script seefor Linux - General 6 01-27-2009 04:41 PM
How to run this script in Crontab baig Linux - Newbie 2 11-30-2008 03:34 PM
Using crontab in a bash script nro Linux - Newbie 3 08-26-2005 09:04 PM


All times are GMT -5. The time now is 10:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration