Possible Duplicate:
executing a sh script from the cron
I'm having issues with a script that I created and am trying to run via cron. The script works perfectly fine when manually executed, but when i put it into /etc/cron.hourly
, some parts don't work. I've seen similar questions ask this and the answer generally refers to cron's limited environment and something about using full paths. Here's a similar question: executing a sh script from the cron
Here is a stripped down version of the script I'm trying to run.
#!/bin/sh
#Run download script to download product data
cd /home/dir/Scripts/Linux
sh script1.sh
#Run import script to import product data to MySQL
cd /home/dir/Mysql
sh script2.sh
#Download inventory stats spreadsheet and rename it
cd /home/dir
wget http://www.url.com/file1.txt
mv file1.txt sheet1.csv
#Remove existing export spreadsheet
rm /tmp/sheet2.csv
#Run MySQL queries in "here document" format
mysql database_name << EOF
--Drop old inventory stats table
truncate table table_name1;
--Load new inventory stats into table
Load data local infile '/home/dir/sheet1.csv' into table table_name1 fields terminated by ',' optionally enclosed by '"' lines terminated by '\r\n';
--MySQL queries to combine product data and inventory stats here
--Export combined data in spreadsheet format
group by p.value into outfile '/tmp/sheet2.csv' fields terminated by ',' optionally enclosed by '"' lines terminated by '\r\n';
EOF
I know that part of it is working because /tmp/sheet2.csv
is being deleted as per the 16th line. However, no new /tmp/sheet2.csv
is being exported, as it should be at the end of the script.
Any ideas on how to fix this? I'm not too advanced, so I'm not clear on how to resolve the issue of cron's limited environment.