I have a code like this :
set -e
set -x
folderName=$(echo `date +%Y/%m/%d/`);
fileName=x.x.x.x.x.x.x.log
cp x.x.x.x.x.x/$1 $fileName
gzip $fileName
s3cmd put $fileName.gz s3://x.x.x.x.x/$folderName
rm $fileName.gz
This is working fine if I run like this :
./shell logfilelocation
And when I added into the crontab like this :
* * * * * /home/x.x.x/testing/s3 -f x.x.x.log >> /tmp/mys3Log
And I waited! The file mys3Log gets created. But there is no content in it! I expect the result of command execution ( as I have used set -e ; set -x in my code ) should go into the mys3Log file as I’m doing a redirect there.
But something is going wrong. I’m very new to bash programming and cron.
Where I’m making the mistake?
Thanks in advance.
crondon’t have the same environment like in interactive shell, so at the beginning of the script, after the shebang, add :And remove
set -eto see what’s going on.In your
crontab, to log errors & output (STDERR,STDOUT), you need to do :Moreover, on line 4 of your script, you are using the variable
$namethats is never declared.Last but not least, like Janauary said, add the
#!/bin/bashshegang on the first line and ensure that your script have executable rights. :chmod +x script.sh