Sftp commands not working in shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sftp commands not working in shell script
# 1  
Old 02-12-2013
Linux Sftp commands not working in shell script

hi,

i am having 2 linux boxes as source and 1 linux box as destination.i want to create a shell script containing code to transfer a csv file from either of the 2 linux boxes (file will be present in just one box, i need to check both the boxes to see which box has the csv file) to 3rd linux box using sftp. suppose i am running this script from 3rd linux box, based on searches i have written the following script.
Code:
#/bin/sh
sftp username@host1ip
cd remote_host_file_path
mget filename
rm filename
quit
cd home_path
mv filename path_where_file_needs_to_be_copied

sftp username@host2ip
cd remote_host_file_path
mget filename
rm filename
quit
cd home_path
mv filename path_where_file_needs_to_be_copied

when i run this script through command prompt i get an error like this:
Code:
cannot find mget or mget not a command
cd not a command
rm not a command

if i give any echo command in this it is printing the echo value.can someone please help me out with this script. i have verified the keys..so it doesnt ask me to enter the password for connecting to remote host. also when i am running all the commands one by one from command prompt the script is working absolutely fine.

Last edited by Franklin52; 02-13-2013 at 05:12 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 02-12-2013
sftp does not read the script, but you can redirect input:
Code:
sftp username@host1ip <<!
cd remote_host_file_path
mget filename
rm filename
!

set up trust with PPKeys so no password is necessary, or (bad choice, password security issues) run it under expect, as password is read from /dev/tty not stdin. I bet sftp has options like ftp to make it more script friendly . . . . https://www.unix.com/man-page/opensolaris/1/sftp/
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Simple sftp script not working - Please help

I have the below sftp script to transfer a file from a linux host(source) to another linux host(target). Public key is already set up in target host and I am able to transfer file using sftp from source to target. But not sure why the below script(ftp_script) is not working. Any help in this... (3 Replies)
Discussion started by: Armaan
3 Replies

2. Shell Programming and Scripting

Spawn sftp and Shell commands

Hi everyone, I'm no killer in shell scripting, that is why I've searched and found a little script that explained how to do what I wanted to do : a FTP transfer from distant servers. I adapted it cause as such, it didn't work. As I needed to do some very simple shell commands (erase and... (2 Replies)
Discussion started by: mederik
2 Replies

3. Shell Programming and Scripting

Shell : sftp autologin not working ...

Hi folks, for sftp autologin, while browing in unix.com forums.. I got the below code. I tried to execute that code but no luck. #!/bin/sh HOST=yourservername USER=yourusername PASS=yourpassword echo "sftping file ..." lftp -u ${USER},${PASS} sftp://${HOST} <<EOF cd /tmp get tmpfile... (7 Replies)
Discussion started by: scriptscript
7 Replies

4. Shell Programming and Scripting

sftp automation script not working

Hi all , can any one tell me how to code SFTP automation script ? I searched lots of forums but i didn't get any useful information:( I don't want auto Login script > like if u run the script it should automatically login into specific account and etc.. Just i want the following things... (4 Replies)
Discussion started by: sravan008
4 Replies

5. 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

6. Shell Programming and Scripting

Commands not working in script file

Hi All, I have created a shell script having some general copying and moving commands. Commands are working fine in Shell but while executing the shell script it is showing an error mv: cannot stat `/apps/orarpt/in/*': No such file or directory command is mv $IN_DIR* $ARCHIVE_DIR where... (5 Replies)
Discussion started by: maindola.amit
5 Replies

7. Shell Programming and Scripting

Parameters passed to commands but not working in Bash shell

Hi, I am trying to do this thing useing my shell bash ( sorry for my english ) I have in a file 63 hostnames, i wanna ask to the DHCP admin, to reserv that reserves 63 IP addresses of this hosts, using their mac address. I have thinked this script: for ((i=1;i<63;i++)); do arp $(head... (10 Replies)
Discussion started by: Cypress
10 Replies

8. Shell Programming and Scripting

execute shell commands with in sftp

Hi All, Please let me know how do I execute some of the shell commands like cat, find ,grep within sftp. Any help in this regard would be greatly appreciated. Thanks, (5 Replies)
Discussion started by: tommy1
5 Replies

9. Shell Programming and Scripting

How to get shell commands working through ruby?

Hi all, I am a newbie currently trying to execute shell commands from ruby instead of a shell script.(This method is conceived only for solaris so no issues with porting to other OS and all) Eg: Consider the command 'ls" with a shell script ,I would use it like this bash# ls <all the... (4 Replies)
Discussion started by: wrapster
4 Replies

10. Shell Programming and Scripting

pwd & cd commands not working in shell script

Here is my script #!/bin/bash pwd cd /var/lib/pgsql Both "pwd" and "cd" are not executed is there any other way i can change the current working directory to /var/lib/pgsql pls help! (9 Replies)
Discussion started by: perk_bud
9 Replies
Login or Register to Ask a Question