i need some advice as i am being driven crazy by Cron on my Fedora 8 box.
i have a basic script that is stored in
/tmp/myscript.sh
Here is a copy of the code within that script.
#!/bin/bash
AFolderName="archivefolder"
AFileName="archive.zip"
echo "setting variables"
if [ -d $AFolderName ]
then
rm -r $AFolderName
fi
echo "checked if folder exists"
mkdir $AFolderName
cd $AFolderName
echo "about to zip"
zip -r $(date +%Y%m%d)_$AFileName /var/www/*
echo "zipped"
echo "about to s3"
s3cmd put $(date +%Y%m%d)_$AFileName s3://mytestbucket
echo "s3ed"
cd ..
rm -r $AFolderName
echo "done"
i have done crontab -e and added a job according to the formatting for it, and the job appears to run as i get a log file in the temp folder. however there is nothing in the logfile and nothing gets uploaded to amazon...
here is whats in crontab
*/10 * * * * root /tmp/myscript.sh > /tmp/ms.log
what am i doing wrong? there is no hint anywhere to what the problem is. by the way the script HAS to run as root.
Agree that you need to login as root or
$ sudo su
to really become root, then do your# crontab -e
and take the "root" out of your crontab line -- as it looks like you found out it doesn't like.Then you can run your script as root -- pretty much as you already had it.
Are you sure that the file has the execute flag flipped, (
ls -l /tmp/myscript.sh
) and that /tmp isn't mounted noexecute? (mount
) The empty log file will be created by the shell, simply due to the redirect. But that doesn't mean the script is actually running. And since you didn't redirect error output, you'll never see that message. (Although it was probably mailed to the root user?)Besides the above, some things to try:
A) Run the script manually, from the command line. Make sure it actually does something.
B) You may want to import in a profile file at the start of the script. Otherwise, you can wind up missing path and environment variables your script may need.
C) Redirect error output from the cron job. Either to the same file, with
2>&1
at the end, or to a separate file with2> diff_file.txt
. This will probably give you some insight as to what went wrong.--Christopher Karel
correct way to-do this was
Here is a copy of the code within that script sudo was needed on the s3cmd line.
crontab needs to have ROOT removed.
*/10 * * * * /tmp/myscript.sh > /tmp/ms.log