Sftp in a crontab


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sftp in a crontab
# 1  
Old 02-08-2018
Sftp in a crontab

Hello All,

My below scripts is not working in crontab by when executed manually it works

Code:
#!/usr/bin/expect

spawn sftp username@ip_address
expect "password:"
send "passwd\n";
expect "sftp>"
send "cd /path/paht2/path3\n"
send "put /export/home/file_*.csv\n"
expect "sftp>"
send "bye\n"
interact

Here is the crontab
Code:
35 18 * * * /path/path2/path3/scripts.sh  > /export/home/log 2>&1

Can anyone give me a hint?
Moderator's Comments:
Mod Comment Please use CODE tags (not ICODE tags) for full-line and multi-line sample input, output, and code segments.

Last edited by Don Cragun; 02-08-2018 at 02:10 PM.. Reason: Change ICODE tags to CODE tags.
# 2  
Old 02-08-2018
Try sourcing your .profile and see if it helps:-
Code:
35 18 * * * . ~/.profile; /path/path2/path3/scripts.sh  > /export/home/log 2>&1

# 3  
Old 02-08-2018
Hi Yoda, thanks..but i had the same problem, it sends a file with 0 bytes.
# 4  
Old 02-08-2018
It might work better if you used keys instead of using a brute-forcing tool to inject passwords. Then you could do scp /export/home/file_*.csv username@ip_address:/path/paht2/path3 and it would run without prompting or stalls.
# 5  
Old 02-11-2018
Hello Corona, this is too is not helping. The file is not being sent to the remote path.
# 6  
Old 02-11-2018
Redirect error also to log and check what is going on when the script runs in cron:-
Code:
35 18 * * * . ~/.profile; /path/path2/path3/scripts.sh  > /export/home/log 2>/export/home/log 

# 7  
Old 02-11-2018
Please what does this do ~/.profile; when i put it in the cron it does not work at all
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Crontab

Hello, I have a situation with crontab command on AIX , when i run a script with crontab i receive empty output , when i run it manually i have information in it,beside the empty output ,SAS log is empty too, i don't know why isn't creating it , could someone told me how could verify crontab... (3 Replies)
Discussion started by: rimob
3 Replies

2. Shell Programming and Scripting

Needed SFTP script from windows to UNIX server and from UNIX to windows server(reverse SFTP)

hi guys, i need a script to sftp the file from windows to unix server ....(before that i have to check whether the file exists in the windows server or not and again i have to reverse sftp the files from unix to windows server..... regards, Vasa Saikumar. (13 Replies)
Discussion started by: hemanthsaikumar
13 Replies

3. Shell Programming and Scripting

Sftp : not able to print the echo statements after the sftp transfer

I had the below sftp script working perfectly but the problem is I am not able to send the echo statements . #!/bin/sh echo "Starting to sftp..." sftp admin@myip << END_SCRIPT cd /remotepath/ lcd /localpath/ mget myfiles*.csv bye END_SCRIPT echo "Sftp successfully." echo echo... (11 Replies)
Discussion started by: scriptscript
11 Replies

4. Red Hat

Chroot sftp users, remote sftp login shows wrong timestamp on files

Hello, I have a weird issue, I have RHEL 5.7 running with openssh5.2 where sftpgroup OS group is chroot. I see the difference difference in timestamp on files, when I login via ssh and SFTP, I see four hour difference, is something missing in my configuration. #pwd... (8 Replies)
Discussion started by: bobby320
8 Replies

5. Programming

SFTP fails from crontab but works from terminal

Dear community, I'm driving crazy with a strange issue. I have a simple script to transfer a file to a remote system:#!/bin/bash echo "put /tmp/server.log" > /tmp/server1_transfer.sftp sftp -b /tmp/server1_transfer.sftp user@10.99.1.2:Between client and server there is a SSH KEY, so if I run... (15 Replies)
Discussion started by: Lord Spectre
15 Replies

6. Shell Programming and Scripting

SFTP-how to log individual sftp command error while executing shell script

Hi, I have situation where i need to automate transferring 10000+ files using sftp. while read line do if ; then echo "-mput /home/student/Desktop/folder/$line/* /cygdrive/e/folder/$line/">>sftpCommand.txt fi done< files.txt sftp -b sftpCommand.txt stu@192.168.2.1 The above... (1 Reply)
Discussion started by: noobrobot
1 Replies

7. AIX

Crontab

How can i schedule a batch job/script to run every minute every day? Thanks (3 Replies)
Discussion started by: mrn6430
3 Replies

8. AIX

SFTP Failed---Request for subsystem 'sftp' failed on channel 0

Hi, While I am trying SFTP my machine to another unix machine , it was working fine till 10 min back. But now i am getting the below error "Request for subsystem 'sftp' failed on channel 0" Could you please someone help me to solve or analyise the root cause... Cheers:b:, Mahiban (0 Replies)
Discussion started by: mahiban
0 Replies

9. UNIX for Advanced & Expert Users

Crontab in HP-UX

Hello! I have a problem on adding a new crontab. Currently we have a running jobs scheduled on a crontab and they are all successfully running. However, when adding or inserting a new scheduled job, the script doesn't work. Is there any limitations on this? Please advise. Thank you very... (13 Replies)
Discussion started by: Tris
13 Replies

10. UNIX for Dummies Questions & Answers

Crontab help

I have made changes to crontab using: crontab -e I then save them with :wq but the changes aren't being seen. The file mod date has not changed. What am I doing wrong? (2 Replies)
Discussion started by: ssmiths001
2 Replies
Login or Register to Ask a Question