HPE Community read-only access December 15, 2018
This is a maintenance upgrade. You will be able to read articles and posts, but not post or reply.
Hours:
Dec 15, 4:00 am to 10:00 am UTC
Dec 14, 10:00 pm CST to Dec 15, 4:00 am CST
Dec 14, 8:00 pm PST to Dec 15, 2:00 am PST
cancel
Showing results for 
Search instead for 
Did you mean: 

sftp cron job not working

 

sftp cron job not working

Hi all,
I'm trying to atoumate aa sftp file transfer to run as a cron job. If I run it interactively, it works fine.
sftp -b /home/rocky.coned.sftp rocky@sftp.remoteserver.com

coned.sftp looks like this:
put /home/rocky/coned.csv
quit

No error in cron log. Trying to run it as user rocky. Set up job using crontabs -e
Thanks,
Rocky
11 REPLIES

Re: sftp cron job not working

What does your mail say is wrong?
You probably need an absolute path for sftp.

Re: sftp cron job not working

Hi,
I tried it with absolute path and still not working. No message in mail.
Thanks,
Rocky
Suraj K Sankari
Honored Contributor

Re: sftp cron job not working

hi,

for sftp the first command you have to give absolute path like /usr/bin/sftp

Suraj

Re: sftp cron job not working

Hi,
Typo in first post

/usr/bin/sftp -b /home/rocky/coned.sftp rocky@sftp.remoteserver.com

coned.sftp looks like this:
put /home/rocky/coned.csv
quit

Thanks,
Rocky
Arturo Galbiati
Esteemed Contributor

Re: sftp cron job not working

Hi,
try
/usr/bin/sftp -b /home/rocky/coned.sftp rocky@sftp.remoteserver.com 1>tmp/sftp.log 2>&1

and post the content of /tmp/sftp.log

HTH,
Art
T G Manikandan
Honored Contributor

Re: sftp cron job not working

why dont you use scp instead of sftp ,

scp rocky@sftp.remoteserver.com:
Jozef_Novak
Respected Contributor

Re: sftp cron job not working

Not 100% sure on this, but doesn't sftp need a terminal associated with it ? That would explain the cron job failure.

J.
Ganesan R
Honored Contributor

Re: sftp cron job not working

Hi Rocky,

It suppose to work if you have configured password less login between source and remote server for rocky user.

We have similiar kind of setup and it is working. Try like this...

#vi /home/rocky/putjob

sftp rocky@sftp.remoteserver.com <<**
lcd /home/rocky
put coned.csv
**

:wq!

put the file putjob on crontab something like this..

30 * * * * /home/rocky/putjob >> /home/rocky/putjob.log 2>&1

Best wishes,

Ganesh.
Rita C Workman
Honored Contributor

Re: sftp cron job not working

Here's a thought...albeit not sftp.

Have your tried just using 'scp' instead?

Regards,
Rita
Steven E. Protter
Exalted Contributor

Re: sftp cron job not working

Shalom,

scp is a better tool for this job. Rita hits the nail on the head.

scp -p /home/rocky.coned.sftp rocky@sftp.remoteserver.com:///home/rocky/coned.csv

Before trying either, use this document to set up password free access properly.

http://www.hpux.ws/?p=10

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com

Re: sftp cron job not working

Hello All,
Thanks for the replies.
I solved the issue. I was trying to execute the command in the "rocky" crontab file. I put the command in a file name coned.cron and gave it a chmod 700. I put the coned.cron file in the "rocky" crontab and it worked. I think it didn't like the space in the command.
Thanks for your help.
Rocky