Author Topic: FTP transfer logging  (Read 2462 times)

hans

  • Guitar Addict
  • Jackass In Charge
  • Posts: 3523
  • Karma: +46/-18
FTP transfer logging
« on: October 28, 2008, 11:07:12 AM »
I need to troubleshoot a Linux script that transfers an encrypted file to another server. The script works if I run it from the command line but for some reason it's not working when run from cron. We've got a log method in the script wrapping all the actions and I'm seeing all the messages, but each morning when I check the folder, the file isn't there. Is there any additional stuff I can do to see what might be going on? We check the $? variable after the FTP section and it's returning 0 so...

Here's the FTP part of the script:

Code: [Select]
ftp -n $HOST <<END_SCRIPT
user $USER $PASSWD
binary
cd subdirectory
put $THE_DATE-filename.gpg
quit
END_SCRIPT
This signature intentionally left blank.

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14310
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Re: FTP transfer logging
« Reply #1 on: October 28, 2008, 11:25:37 AM »
Does the cron job have the same permissions/rights/access as you?

hans

  • Guitar Addict
  • Jackass In Charge
  • Posts: 3523
  • Karma: +46/-18
Re: FTP transfer logging
« Reply #2 on: October 28, 2008, 11:50:53 AM »
It should, I'm running it as the same user (and I used that user to create the cron job).

I added the -v  to the ftp command and piped it into my log file, so I guess I'll know more tomorrow. It's odd though since the rest of script is doing everything it's supposed to be except for the file transfer. I'm guessing it might be something around the time we're doing the transfer and maybe we're not actually connecting to the FTP site.

I've been reading that the FTP exit code is not really reliable for reporting problems. Hopefully the verbose flag will shed some light.
This signature intentionally left blank.

hans

  • Guitar Addict
  • Jackass In Charge
  • Posts: 3523
  • Karma: +46/-18
Re: FTP transfer logging
« Reply #3 on: October 28, 2008, 02:17:46 PM »
Well, it turns out it looks like it's something to do with my GPG command that it's not finding the public key to encrypt the file (thus FTP is choking since the file isn't there). Odd though that it works from the command line. So now I have to try and figure out why cron doesn't work like bash for encrypting.
This signature intentionally left blank.

webwhy

  • Jackass IV
  • Posts: 608
  • Karma: +15/-10
Re: FTP transfer logging
« Reply #4 on: October 28, 2008, 02:30:47 PM »
cron sets up a minimized environment compared to a users session (i.e. .profile, etc is usually not executed when the script runs in cron).

if your depending on anything that is available in the your user environment (a path to an executable for example) it may not be available in the cron environment.

hans

  • Guitar Addict
  • Jackass In Charge
  • Posts: 3523
  • Karma: +46/-18
Re: FTP transfer logging
« Reply #5 on: October 28, 2008, 02:48:30 PM »
Think I got it fixed. Needed to add /usr/local to the path declaration in the script to get GPG to work right. Stupid cron not setting up the same environment.
This signature intentionally left blank.

hans

  • Guitar Addict
  • Jackass In Charge
  • Posts: 3523
  • Karma: +46/-18
Re: FTP transfer logging
« Reply #6 on: October 28, 2008, 03:35:42 PM »
OK, that didn't exactly "fix" it, when I moved it to run under the system crontab it still has issues, so for now it's going to run as root's crontab until I can figure out what I need to add to the script to get the system cron to use the keys that root has access to.
This signature intentionally left blank.