views:

57

answers:

3

I asked a similar question over here:(http://stackoverflow.com/questions/1495604/upload-clocking-script), but then changed it and realized it's a different question now.

I want to make a script called uploadtimer.sh which uploads files to various hosts and then notes the time the upload takes in a log file. Thanks to those who have helped me, I have a partial solution but I'm stuck:

I used this as a crontab (testing it for the first ten minutes after 11 am)

1,2,3,4,5,6,7,8,9,10     11     *     *     *          /usr/bin/time -a /usr/local/apache/sites/$MYEMPLOYER/upload_test/output.log  /usr/local/apache/sites/$MYEMPLOYER/upload_test/uploadtimer.sh

upload_test/ has these files in it:

upload_test/output.log upload_test/uploadtest.gif upload_test/uploadtimer.sh

output.log is a text file that I renamed as a .log file. It's blank. Before I put it there, I was getting messages that said "this file doesn't exist". I thought it'd create one for me but I guess not. After I created it, it kept saying in the crontab mails that I couldn't write to it until I changed its permissions, so I did.

uploadtest.gif is a gif

uploadtimer.sh is this:

#!/bin/sh

HOST='--myhost--'
USER='--login--'
PASSWD='--password--'
FILE='uploadtest.gif'

ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
put $FILE

quit
END_SCRIPT
exit 0

The message that cron sends to me is:

0.00user 0.00system 0:00.02elapsed 0%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+253minor)pagefaults 0swaps

But no ftp has taken place and nothing it written in output.log.

A: 

Create another script that runs the second command. Call the second script from cron.

You will need to make sure you are using absolute paths for everthing because cron starts in a different directory than the script.

Byron Whitlock
A: 
weiji
What version of cron requires tabs and not spaces?
glenn jackman
Sorry about that - I learned it that way from somewhere and just stuck with it that way. Mostly because I don't like using vi. Thanks for pointing out my slop - I've fixed my answer.
weiji
You aren't forced to use vi. If you prefer something like pico, use the command "VISUAL=/usr/bin/pico crontab -e". Better yet, if you have and editor preference, set the environment variables VISUAL and EDITOR to the full path of your editor in your .bashrc.
bstpierre
@bstpierre - good point. Although my issue is that the preference isn't stronger than the inertia :)
weiji
A: 

You might want to check out "ncftp". It would condense your upload command into "ncftpput -u $USER -p $PASSWD $HOST / $FILE", and then you wouldn't need the script at all, just put the whole command into your crontab:

0 2 * * * /usr/bin/time -a ~/output.log ncftpput -u $USER -p $PASSWD $HOST / $FILE
bstpierre
I tried to do it how you said:/usr/bin/time -a /usr/local/apache/sites/consumercompare/upload_test/output.log ncftpput -u nextadvi -p ne#541pal seemyreportsfree.net / /usr/local/apache/sites/consumercompare/upload_test/uploadtest.gifbut the ftp doesn't happen, the output.log is blank and the cron email I get is: 0.00user 0.00system 0:00.03elapsed 0%CPU (0avgtext+0avgdata 0maxresident)k0inputs+0outputs (0major+255minor)pagefaults 0swaps
pg