SFTP not working in cron


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting SFTP not working in cron
# 1  
Old 06-28-2006
SFTP not working in cron

Hi,

I have a simple script that is trying to put a file that resides on a local machine to a remote machine. It runs fine manually but does not complete when scheduling to run in cron. Here is what the script looks like. Any idea what I am doing wrong here?

#!/bin/ksh
cd /path
sftp remoteuser@remotehost:/path <<EOF
mput Test.txt
bye
# 2  
Old 06-28-2006
Code:
#!/bin/ksh
cd /path
sftp remoteuser@remotehost:/path <<EOF
mput Test.txt
bye
EOF

I'm assuming that leaving off EOF was a typo.

sftp used that way requires that authentication keys be set up on the remote host.
What local user is authenticated to remoteuser on the remotehost? And is the script running as that user, ie., do you su to the required local user?
# 3  
Old 06-28-2006
Jim,

Thanks for your reply. We have generated keys on both the source and destination machines authenticating the user. We are running the script from this user. If I type it manually from a command prompt "TestSFTP.sh", it works fine. However when I put it in cron it doesn't.

As a further test, I put in an additional line in cron to send me an email.

#!/bin/ksh
mailx -s "Test" myemail@myemail.com < /path/TestSFTPcron.txt
cd /localpath
sftp remotename@remotehost:/remotepath <<EOF
mput Test.txt
bye
EOF

When I do this, it also works completely fine when I run it manually. However, in cron I so receive the email but the file is not put on the remote machine.

It looks like the script is partially working...

Last edited by ewilson0265; 06-28-2006 at 04:56 PM..
# 4  
Old 06-28-2006
okay - you need to have the script run by cron as that user - use the man page for su to show you how to do that.
# 5  
Old 12-02-2007
Hi,

Have you go this problem resolved ? even I am facing a similar problem. My script works fine when run manually from command prompt, but it is failing when put in to the crontab. How did you fix this problem?

Thanks.
Abhi.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Mget with SFTP is not working

hi Team, I am connecting from one (A) linux server to another(C)/any linux server by sftp on A linux server: sftp userid@C password: mget is Not working fine I am using mget to pull the files. it shows mget as invalid command. But from (B) Linux server to (C) /to Any server Linux... (15 Replies)
Discussion started by: johnsnow
15 Replies

2. Shell Programming and Scripting

sftp autologin is working but ...

Dears, I am new to linux scripting and I was look for a way to auto login to a server using sftp to download a file. I found one and it is working fine. But i don't know the meaning of <<EOF in the code. Any one explain it to me: #!/bin/sh HOST=yourservername USER=yourusername ... (1 Reply)
Discussion started by: torabi
1 Replies

3. Shell Programming and Scripting

Script not working in cron but working fine manually

Help. My script is working fine when executed manually but the cron seems not to catch up the command when registered. The script is as follow: #!/bin/sh for file in file_1.txt file_2.txt file_3.txt do awk '{ print "0" }' $file > tmp.tmp mv tmp.tmp $file done And the cron... (2 Replies)
Discussion started by: jasperux
2 Replies

4. Shell Programming and Scripting

Script is not working from cron while working manually

Hello, I am facing a very strange problem when I run my script manuallu ./Fetchcode which is using to connect with MKS integrity from linux end it workks fine but when I run it from cron it doesn't work.Can someone help me 1) How could I check my script when it is running from cron like... (3 Replies)
Discussion started by: anuragpgtgerman
3 Replies

5. UNIX for Advanced & Expert Users

SFTP Not Working With CRON

Hello - I have a production stream that is scheduled with cron to run each Monday morning. The jobs in the stream perform tasks including FTP get, load to a DB table, and report processing. About a month ago I was directed to begin using sftp in these jobs and since then the jobs... (12 Replies)
Discussion started by: PatrickPurfield
12 Replies

6. UNIX for Dummies Questions & Answers

Problem automating sFTP transfer using script in cron

Hi Newbie here I am having problems with automating sFTP transfers. Just to save time - SCP is not an option as sFTP is stipulated by controllers of far end server. Ineed to automate sFTP transfer of a single file, once a day to a remote server to which i have no control over. I am using:... (6 Replies)
Discussion started by: robbien
6 Replies

7. UNIX for Dummies Questions & Answers

Unable to sftp with cron (once more time...)

Hi, I have been searching for older posts and I've found many entries with identical problems, but I was not able to find the solution (or when I thought I found it, my trial didn't worked :(). Anyway, here is my question. I wrote a sftp.sh file that runs perfect from command line. It uses scp... (6 Replies)
Discussion started by: Kronos
6 Replies

8. UNIX for Dummies Questions & Answers

sftp in cron

Hi, I am running simple script to automate sftp transfer to remote box. I have setup public/private keys to have sftp connect automatically and have test script that list remote directory: #!/bin/ksh echo "OK, starting now..." sftp userid@host <<EOI cd dir ls -lt bye EOI... (2 Replies)
Discussion started by: r1omen
2 Replies

9. Solaris

SFTP not exiting when run from cron

I am using a script to transfer a file from a unix host to another unix host. The code snippet for sftp in the script is as below. sftp -oIdentityFile=$ID_FILE_NAME -oNumberOfPasswordPrompts=0 $REMOTE_USERID@$REMOTE_HOST <<EOF cd incoming put $REPORT_FILE... (2 Replies)
Discussion started by: msabhilash
2 Replies

10. Solaris

SFTP errorcode 1 when run on cron but runs manually

I am trying to run a sript on cron to SFTP data to a company. Private and public keys are set up. When I run this manully it works fine, however it was failing when run on cron. I have narrowed down the problem - it fails at the code that says if the error code is 0 then continue . . . I... (2 Replies)
Discussion started by: Heidi.Ebbs
2 Replies
Login or Register to Ask a Question