LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 05-24-2011, 05:29 AM   #1
najee1987
LQ Newbie
 
Registered: May 2011
Posts: 3

Rep: Reputation: Disabled
spawn with Expect script


Hi all,

I am trying to create an expect script that will automate ssh login. In ssh first I have to login as ssh user and then su - to login as root. root login using ssh is disabled. I tried spawn one after other but it doesn't work. I want to know is it possible to execute two spawn in an expect script, if then how?.
 
Old 05-24-2011, 05:45 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,415

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
you don't want to spawn twice at all. from the expect perspective you are not spawning a new process, you're just reading a stream of characters from ssh and sending other ones back. It has no idea whatsoever what these letters and numbers mean.

Can you not just use a preshared key for this? Whilst root password logins should be disabled, it's not uncommon to still permit shared key logins for root, making this much simpler, and probably removing the need for expect completely.
 
Old 05-24-2011, 06:12 AM   #3
najee1987
LQ Newbie
 
Registered: May 2011
Posts: 3

Original Poster
Rep: Reputation: Disabled
Hi,

I agree that using ssh key is safe. But I want that to be done using expect because for one system what I have to do is login to secure user and then login as root user since it is required and for the other one first I have to login to one machine and from that machine I have to ssh login to another machine. What I am trying to do is automate this process using expect script. Please let me know is there a way do that using expect script.
 
Old 05-24-2011, 06:19 AM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,415

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
I already told you there is. You just need to appreciate what expect does and doesn't know about at a process level.
 
0 members found this post helpful.
Old 05-24-2011, 07:37 AM   #5
kute
LQ Newbie
 
Registered: May 2011
Posts: 1

Rep: Reputation: Disabled
If I understand your problem correctly,
you want shell on remote machine for root user.

You do not need to do spawn twice.
You have to spawn as follow

ssh <username>@<server ip> "su"

It will first ask for password for <username>. After receiveing it will execute su command.
Wait for "password:" there and send root password on receiving.
After that drop to interactive mode.
 
1 members found this post helpful.
Old 05-25-2011, 02:53 AM   #6
najee1987
LQ Newbie
 
Registered: May 2011
Posts: 3

Original Poster
Rep: Reputation: Disabled
Thumbs up it worked finally

i tried with ssh <username>@<server ip> "su" but i was getting the error standard in must be a tty. But anyway the problem got solved. I wrote some additional line to expect the user prompt and send the commands to terminal rather than try to spawn a process.
Thank you kute for your suggestion
 
  


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 On
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 10:06 PM
exp_i_parse_states: : file16 is not an expect channel - use spawn -open to convert pcs1976 Programming 0 03-15-2011 08:58 AM
send: spawn id exp1025 not open in tcl/expect bharatbsharma Programming 3 04-22-2010 03:04 AM
Expect interpreter, spawn and cat Ricio Programming 11 08-16-2008 06:55 PM
Unexpected curly braces in expect script spawn command & bash suid problem slinx Programming 1 05-02-2008 02:47 PM


All times are GMT -5. The time now is 08:01 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration