LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 08-02-2013, 02:15 PM   #1
IAnilkumar
LQ Newbie
 
Registered: Nov 2012
Posts: 3

Rep: Reputation: Disabled
Help on expect


I am writing a script to connect to a remote host and run a command. I wanted to use expect for this. Here it is below:

#!/bin/bash
#!/usr/bin/expect
ssh -o StrictHostKeyChecking=no -l pin100 slc02gnh.us.oracle.com
expect "Password: "
send "pin100\n"



The above code is not working as it displays the "Password: " and waits for the password. It is not taking send.

What is wrong with above.
 
Old 08-02-2013, 06:12 PM   #2
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
You don't need #!/bin/bash if you're running it with expect.
And you probably need to add spawn:
Code:
#!/usr/bin/expect
spawn ssh -o StrictHostKeyChecking=no -l pin100 slc02gnh.us.oracle.com
expect "Password: "
send "pin100\n"
Maybe also need to expect another acknowledgement reply and in the end interact with it
Code:
...
interact
Can't test here sorry.
 
Old 08-04-2013, 11:03 AM   #3
IAnilkumar
LQ Newbie
 
Registered: Nov 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
I could able to resolve the issue. Here is the script now:

#!/usr/bin/expect -f
spawn ssh -o StrictHostKeyChecking=no -l aindraka slc02gnh.us.oracle.com
expect "Password: "
send "Gothika1\r"
expect eof

But now i wanted to extend the script in such a way that if wanted to run few system admin commands after logging into the remote server.
First i tried running running few basic commands but it is not successful. can somebody help how to proceed from here.

Anil
 
Old 08-04-2013, 11:31 AM   #4
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
I wonder if you really should expect the prompt and not eof. I don't know the behavior of eof yet, but are you certain that you're really able to log-in through it?
 
  


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
Expect script: how do i send function key F12 in an expect script alix123 Programming 4 09-01-2013 09:06 PM
[SOLVED] /usr/bin/expect : Script to check server load using both expect and bash Soji Antony Programming 1 07-27-2010 11:27 PM
expect: line seems to match exactly, however expect thinks not deadeyes Linux - General 5 06-16-2010 06:05 PM
Calling expect scripts from other expect scripts sevapopov Linux - Software 3 04-03-2008 09:33 PM
Expect how to? e-freak Programming 2 09-24-2005 04:49 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:12 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