LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-06-2014, 01:33 PM   #1
edimanic
LQ Newbie
 
Registered: Jan 2014
Posts: 10

Rep: Reputation: Disabled
Pass parameter to SFTP password based script


Hello ,

i am not able to pass the parameters to the script at the time of calling .

script call --> ./pqr.sh userid

Error :
can't read "1": no such variable
while executing
"spawn sftp -v -oPort=22 $1@host

Script pqr.sh#
==================================================
#!usr/bin/expect
spawn sftp -v -oPort= 22 $1@host
expect "Password!\r"
send "password\r"

expect sftp>
send "cd dir\r"

expect sftp>
send "put filename\r"

expect sftp>
send "bye\r"
interact
===================================================


if i hardcode userid insted of passing while calling script is working fine .
 
Old 02-06-2014, 01:36 PM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,060

Rep: Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852
your doing it wrong... use keys instead of passwords.

also scp is meant for automated machines whereas sftp prompts and waits for human input.

next time use [code] tags.
 
Old 02-06-2014, 02:04 PM   #3
edimanic
LQ Newbie
 
Registered: Jan 2014
Posts: 10

Original Poster
Rep: Reputation: Disabled
is there any way by which i can get above script working .
 
1 members found this post helpful.
Old 02-06-2014, 04:48 PM   #4
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora
Posts: 2,630

Rep: Reputation: 495Reputation: 495Reputation: 495Reputation: 495Reputation: 495
https://stackoverflow.com/questions/...to-ssh-command

that link might help. what you are doing is VERY insecure and DANGEROUS, not a good idea. the Expect script is NOT MUCH BETTER. as pointed out above, its best to use ssh keys (read the links in my signature) for this type of automated scripting. Also you might want to look into lftp vs sftp. IIRC lftp can also perform ssh type connections.
 
1 members found this post helpful.
Old 02-06-2014, 05:06 PM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 15,374

Rep: Reputation: 1649Reputation: 1649Reputation: 1649Reputation: 1649Reputation: 1649Reputation: 1649Reputation: 1649Reputation: 1649Reputation: 1649Reputation: 1649Reputation: 1649
Command line arguments use a different syntax vs a bash script. This might help:

http://en.wikipedia.org/wiki/Expect
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How can pass both an optional flag and unrelated required parameter to a bash script? abefroman Programming 2 10-07-2013 12:19 PM
How to make sftp connection password based in Unix script pradeepdee6 Linux - Newbie 7 02-22-2013 02:09 PM
how to pass command-line parameter to shell script? Kropotkin Linux - Newbie 12 07-25-2011 09:24 AM
how to pass in a parameter to a perl script new_2_unix Linux - Newbie 2 12-09-2007 12:48 AM


All times are GMT -5. The time now is 02:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration