Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Crontab ?

Status
Not open for further replies.

Saeed42

ISP
Jul 4, 2001
147
I'm trying to setup a cron job for a script that does ftp backup once a day, but not quite sure what I'm doing wrong, I did the following

crontab -e [which opened up vi, entered the following and saved it as usual]
30 12 * * * /usr/local/bin/backmeup

now when I do crontab -l I get the following
30 12 * * * /usr/local/bin/backmeup

But still doesn't work, If I run the backmeup script it will do the job so I know the script works, so where am I going wrong, system time and date are correct


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Don't be content with being average. Average is as close to the bottom as it is to the top
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
Hi,
you set the job under the same user as you started it from hand ?
Did you have #!/bin/ksh as first line in your script ?
crontab did not have a shell so you'll have to start one inside your script

regards
Uwe
 
I think what Uwe means is that crontab itself doesn't have any environment variables, these need to be explicitly set within your script. Normally it's the PATH variable which causes the problem, so as the user who would normally start the job, issue an echo $PATH and copy this to be one of the first lines of your script. That way, cron knows where to find things. HTH. Post back if not.
 
The first line of the script takes care of that "#!/bin/bash", but still seem to be having problems with cron


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Don't be content with being average. Average is as close to the bottom as it is to the top
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
try redirecting your output to a file. If you don't get any output, try putting some echo statements in there to debug and see if it is running. Also put a sleep 60 at the beginning. That way you can do a ps -ef | grep backmeup to see if anything is running.
 
Saeed,
Something I do is in scripts I run as a crontab I always put the FULL path for everything. That is becasue of the path thing. You can bypass this by doing:

1) Create another script specifically for cron.

2) In the new script simply put:
su USERNAME -s /bin/sh or whatever shell you want -l -c "/usr/local/bin/backmeup"

So if you need to run the backmeup script as root using the Bash shell then it would resemble:
su root -s /bin/bash -l -c "/usr/local/bin/backmeup"

3) Save this new script and have cron run it instead of the backmeup script. The -l give the login shell.

Now I haven't tried this except when I am already logged in. I believe cron will start the job with the same permissions as the user but the path is not being exported. The -l should work. The -l is an lowercase L BTW.


 
I've followed your suggestion and I'm still having the same problem, it seems that the script does what it suppose to do upto a point and the then dies, unfortunately I'm not knowledgeable enough in Linux to find out why so I posted the script in the hope that someone else will see what is giving me all this grieve.

The script works upto the point where it needs to datestamp the compressed file
"mv /tmp/backmeup.tmp/backmeup.tar /tmp/backmeup.tmp/$backmeup_MACH_NAME.backmeup.$backmeup_VERSION.`date -I`.tar"






#!/bin/bash
#
backmeup_VERSION="ver2.0"
backmeup_MACH_NAME="ns1"

#
# Clean up the temp area, make the empty directory.
#
rm -R /tmp/backmeup.tmp
mkdir /tmp/backmeup.tmp

#
# The custom bits that configure the bespoke DNS
#
tar -cvf /tmp/backmeup.tmp/backmeup.tar /etc/PERSONALITY

#
# Master config bits.
#
tar -rvf /tmp/backmeup.tmp/backmeup.tar /var/master/

#
# Slave config bits.
#
tar -rvf /tmp/backmeup.tmp/backmeup.tar /var/slave/


#
# The custom scripts, like this one!
#
tar -rvf /tmp/backmeup.tmp/backmeup.tar /usr/local/bin

tar -rvf /tmp/backmeup.tmp/backmeup.tar /etc/TOOLS

#
# Now timestamp the tarfile and copy it to the home dir.
#
mv /tmp/backmeup.tmp/backmeup.tar /tmp/backmeup.tmp/$backmeup_MACH_NAME.backmeup.$backmeup_VERSION.`date -I`.tar

gzip /tmp/backmeup.tmp/$backmeup_MACH_NAME.backmeup.$backmeup_VERSION.`date -I`.tar

#
# Now dump the backup somewhere...
#
echo ...doing the ftp

#
# IMPORTANT: For security reasons the ftp passwords are not given here in the
# script, but use the default /root/.netrc file to store the login details
# e.g. /root/.netrc is a txt file with this in it:
# machine ftp.mydomain.net login ftp password <passwrd>
# machine 10.10.10.10 login ftp password <passwrd>
# obviously /root/.netrc needs to be chmod 700, chown / chgrp root

ftp -i ft.mydomain.net <<finito
lcd /tmp/backmeup.tmp
cd /restrict/DNS/ns1
binary
put $backmeup_MACH_NAME.backmeup.$backmeup_VERSION.`date -I`.tar.gz
bye
finito



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Don't be content with being average. Average is as close to the bottom as it is to the top
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
Thanks for your help guys, I finally got this to work, I slightly modified the line that I added to cron

59 2 * * * root cd /usr/local/bin; ./backmeup > backmeup.log &



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Don't be content with being average. Average is as close to the bottom as it is to the top
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top