LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-21-2010, 01:07 PM   #1
samarudge
Member
 
Registered: Nov 2010
Posts: 33

Rep: Reputation: 0
Using Expect To Execute Remote Commands


I'm trying to get Expect to execute commands on a remote server using SSH with username/password authentication
My current expect script is
Code:
#!/usr/bin/expect -f
spawn ssh -tq root@my_hostname "whoami"
match_max 10000
expect "*?word:*"
send -- "my_password\r"
send -- "\r"
expect eof
But this returns
Code:
spawn ssh root@my_hostname whoami
root@my_hostname's password: 
root
But all I need is the last line, also I need the script to return the exit code of the command run.

I'm aware this is insecure.
I cannot use key based ssh authentication, the servers are Amazon EC2 servers that are never running for more than 12 hours so every time I start a new one it has a new hostname so the keys are invalid.

Bar that, is there a better solution to this problem?

Last edited by samarudge; 12-22-2010 at 04:37 PM.
 
Old 12-22-2010, 09:04 AM   #2
ChrisAbela
Member
 
Registered: Mar 2008
Location: Malta
Distribution: Slackware
Posts: 572

Rep: Reputation: 154Reputation: 154
Since you have control on access to the LAN, I would use rsh.
 
Old 12-22-2010, 04:37 PM   #3
samarudge
Member
 
Registered: Nov 2010
Posts: 33

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by ChrisAbela View Post
Since you have control on access to the LAN, I would use rsh.
But other servers on Amazon EC2 would have access so I still want to use secure shell
 
Old 09-22-2011, 04:10 AM   #4
cm3l1k1
LQ Newbie
 
Registered: Sep 2011
Posts: 3

Rep: Reputation: Disabled
Hi, here is my script which can help you:


Thank you

---------- Post added 09-22-11 at 10:10 AM ----------

http://www.security-portal.cz/clanky...le-servers-ssh
 
  


Reply



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
Execute commands on remote system madhi Linux - Software 3 06-20-2008 10:31 AM
Execute commands or scripts on a remote server gurl4sh25 Linux - Software 3 06-27-2007 09:04 PM
bash - execute commands on a remote machine capture results, etc dkrysak Programming 1 11-18-2005 01:50 PM
execute multiple ssh remote commands tom221 Linux - Newbie 2 01-28-2005 01:00 PM
Automae telnet log in and execute commands (expect and send) rajatgarg Linux - Networking 0 06-24-2004 11:37 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:05 PM.

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
Open Source Consulting | Domain Registration