SFTP fails from crontab but works from terminal


 
Thread Tools Search this Thread
Top Forums Programming SFTP fails from crontab but works from terminal
# 8  
Old 08-16-2012
Quote:
Originally Posted by Corona688
You have openssh then, which supports -i. See man sftp.
Nope Smilie
Code:
sftp -b /tmp/server1_transfer.sftp -i /root/.ssh/authorized_keys user@10.99.1.2:


Code:
X-Cron-Env: <USER=root>
sftp: illegal option -- i
usage: sftp [-1Cv] [-B buffer_size] [-b batchfile] [-F ssh_config]
            [-o ssh_option] [-P sftp_server_path] [-R num_requests]
            [-S program] [-s subsystem | sftp_server] host
       sftp [[user@]host[:file [file]]]
       sftp [[user@]host[:dir[/]]]
       sftp -b batchfile [user@]host

# 9  
Old 08-16-2012
Note the current working directory when the script is run manually.
Try making the first line of your script a cd to that directory.
# 10  
Old 08-16-2012
Quote:
Originally Posted by methyl
Note the current working directory when the script is run manually.
Try making the first line of your script a cd to that directory.
Same result: Smilie
Permission denied (publickey,password).
Couldn't read packet: Connection reset by peer

---------- Post updated at 01:18 PM ---------- Previous update was at 12:57 PM ----------

Well, I can use succesfully the REXEC command from crontab, providing USERNAME and PASSWORD.

Now I need to tranfer the file, I tried some methods:
SFTP: Doesn't work from crontab
SCP (OpenSSH): Doesn't work since the destination server is HP OpenVMS and for some reason it can't accept the SCP protocol
Simple FTP: Does't work, since I receive the following error message
Code:
Connected to 10.99.1.2.
220 FTP Server (Version 5.6) Ready.
502 AUTH is unimplemented.
502 AUTH is unimplemented.
KERBEROS_V4 rejected as an authentication type

At this point, Is there any other way to copy this file to remote OpenVMS server?
# 11  
Old 08-16-2012
sftp accept ssh options through the -o option:
Code:
sftp -o IdentityFile=$HOME/.ssh/id_rsa

Does your key have a pass phrase? Maybe you are running ssh-agent. Your interactive shell has the env SSH_AUTH_SOCK set, but not for the cron job.
# 12  
Old 08-17-2012
ftp -vu host # The 'u' disables auto-authentication
passive # I believe vms requires passive mode
Then try the 'user' command
# 13  
Old 08-17-2012
Well, thanks all for hints,
I resolved the issue using NCFTP (ncftp(1) manual page)

It also allow me to setup a timeout when one of the destination server is down (i.e. for maintenance). This avoid the script hangs awaiting for long timeout:
Code:
/usr/local/bin/ncftpput -t $ftp_timeout -r 1 -u $username -p $password $server1 / /tmp/server.log 2> /dev/null

-t = Timeout in seconds
-r = The retry attempts
# 14  
Old 08-18-2012
You do realize this makes your password visible in plaintext to the entire system for the entire duration of the connection, yes!?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace string works on command-line but fails when run from shell script

I wish to replace "\\n" with a single white space. The below does the job on command-line: $ echo '/fin/app/scripts\\n/fin/app/01/sql' | sed -e 's#\\\\n# #g'; /fin/app/scripts /fin/app/01/sql However, when i have the same code to a shell script it is not able to get me the same output:... (8 Replies)
Discussion started by: mohtashims
8 Replies

2. Shell Programming and Scripting

Find command works on Linux but fails on Solaris.

Hi, I am looking for a generic find command that works on both Linux and Solaris. I have the below command that works fine on Linux but fails on solaris.find /web/config -type f '(' -name '*.txt' -or -name '*.xml' -name '*.pro' ')' Fails on SunOS mysolaris 5.10 Generic_150400-61 sun4v sparc... (1 Reply)
Discussion started by: mohtashims
1 Replies

3. Shell Programming and Scripting

Need to know why crontab -e fails

more cron.txt 1 * * * * /u/ways.sh 2>&1 >/dev/null bash-4.1$ export EDITOR=vi bash-4.1$ crontab -e <cron.txt Vim: Warning: Input is not from a terminal Vim: Error reading input, exiting... Vim: Finished. The crontab file was not changed. bash-4.1$ echo $? 1 bash-4.1$ uname -a SunOS... (3 Replies)
Discussion started by: mohtashims
3 Replies

4. Shell Programming and Scripting

sed works on Linux but fails on Solaris

Hi, On Linux i get the desired ouput: echo "<value>WEB_USER</value>" | sed 's/\(<value>\|<\/value>\)//g'Output: Executing the same command on Solaris: echo "<value>WEB_USER</value>" | sed 's/\(<value>\|<\/value>\)//g'Output: I need to get the desired output on Solaris i.e. WEB_USER and... (4 Replies)
Discussion started by: mohtashims
4 Replies

5. Shell Programming and Scripting

awk works on Linux but fails on Solaris

On linux i have the below command working fine. awk '/<app-deploy>/{A=1;++i} /<\/app-deploy>/{print >> "found"i".tmp";A=0} A{;print >> "found"i".tmp"}' deploy.xml But the same is failing on Solaris Output: awk: syntax error near line 1 awk: bailing out near line 1 uname -a SunOS mymac 5.10... (5 Replies)
Discussion started by: mohtashims
5 Replies

6. Shell Programming and Scripting

Grep works on Linux but fails on Solaris

Hi, On linux i have the below command working fine. grep -o '<name>.*</name>' deploy.tmp | sed 's/\(<name>\|<\/name>\)//g' deploy.tmp But the same is failing on Solaris uname -a SunOS mymac 5.10 Generic_150400-23 sun4v sparc sun4v Can you tell me how can i get it work on Solaris ?... (6 Replies)
Discussion started by: mohtashims
6 Replies

7. Shell Programming and Scripting

SED command works in terminal, but not Applescript

The following command works perfectly in Terminal, but not in Applescript. (Returns "unknown token" error for square brackets.) (new to site. sorry.) I have an Applescript that is designed to find and remove any square-bracketed text, including the square brackets. I ran the following code from... (1 Reply)
Discussion started by: Phillip Acosta
1 Replies

8. Shell Programming and Scripting

Help wth Net::FTP in script sometimes fails but wsftp always works

Hi, I have a script that transfers files from a Solaris server to target unix servers. The script uses Net::FTP->put to write the files, which can be any number of files, not always the same. This script works flawlessly to many servers. For one particular instance of the script,... (3 Replies)
Discussion started by: csgonan
3 Replies

9. Shell Programming and Scripting

how it works ? sftp

Hi, I am curious about this script , how it is running ..? #!/bin/sh echo "OK, starting now..." ftp remotehost <<EOF When I run , it is asking OK, starting now... Password:Name (remotehost): SHould I enter only password ? and explain me how it works.. thanks in advance.. (3 Replies)
Discussion started by: hegdeshashi
3 Replies

10. Shell Programming and Scripting

Cron job fails, but works fine from command line

I have a very basic script that essentially sends a log file, via FTP, to a backup server. My cron entry to run this every night is: 55 23 * * * /usr/bin/archive_logs The script runs perfectly when executed manually, and actually worked via cron for about three weeks. However, it mysteriously... (3 Replies)
Discussion started by: cdunavent
3 Replies
Login or Register to Ask a Question