Hi guys,
Is been a while since I was last here requesting help. Now I need some of that LQ magic. I have a script file that extracts data for a date range, create a zip file for the data and then ftp it to a remote server.
Now the script is working perfectly if it is run manually, but now I want it to execute automaticly. So I use the crontab, but for some reason the script fails when run from the crontab.
Code:
#!/bin/bash
# Today's date formatted:
TODAY=`date +'%m-%d-%Y'`
# Get individual elements
MONTH=`echo $TODAY | cut -d'-' -f1`
DAY=`echo $TODAY | cut -d'-' -f2`
YEAR=`echo $TODAY | cut -d'-' -f3`
if [[ `expr $DAY + 1` -eq 1 ]]; then
if [[ $MONTH -eq 1 ]]; then
MONTH=12
YEAR=`expr $YEAR - 1`
else
MONTH=`expr $MONTH - 1`
fi
fi
MONTH=`expr $MONTH - 1`
if [[ `echo $MONTH | wc -c` -eq 2 ]]; then
MONTH=0$MONTH
fi
# Previous day in the same format, without hyphens
START_DATE=$YEAR$MONTH"01"
END_DATE=$YEAR$MONTH"31"
# move old DB files to /tmp/
mv DB8* /tmp/
mv ID8* /tmp/
mv IN8* /tmp/
echo "Running Dispensary extract for Date range" $START_DATE "to" $END_DATE
rm NHDATA.*
APPWHEXT $START_DATE $END_DATE
echo "Running Frontshop extract for Date range" $START_DATE "to" $END_DATE
APAP850 $START_DATE $END_DATE
echo "Extracts completed successfully"
FILENAME=$1
zip $FILENAME DB8* IN8* ID8*
SCRIPT=`basename $0`
if [ -z "$1" ] ; then
echo "$SCRIPT: Usage: `basename $0` File-one File-two File-three"
exit 1
fi
USER="my_user"
SERVER="my_ip"
DIRECTORY="/extracts"
PASSWORD="my-pass"
echo -e "\nStarting to try transmitting extract to $SERVER...\n"
while [ -n "$1" ] ; do
cat << EOF > /tmp/ftpput_script.$$
user ${USER} ${PASSWORD}
binary
cd $DIRECTORY
put "$FILENAME"
bye
EOF
cat /tmp/ftpput_script.$$ | ftp -n ${SERVER}
echo -e "Processed: $FILENAME";
shift
done
rm -f /tmp/ftpput_script.$$
echo -e "\nExtract uploaded!!!!..."
mv DB8* /tmp/
mv ID8* /tmp/
mv IN8* /tmp/
mv $FILENAME /tmp/
exit 0
command to run the script from the commandline
Code:
sh /usr/bin/extract.sh server.zip
Any Ideas???
Karel