LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Enterprise Linux Forums > Linux - Enterprise
User Name
Password
Linux - Enterprise This forum is for all items relating to using Linux in the Enterprise.

Notices


Reply
  Search this Thread
Old 04-29-2012, 08:57 AM   #1
rhadmn
Member
 
Registered: Oct 2009
Location: Bangalore
Distribution: Redhat Linux, Solaris, CentOS
Posts: 35

Rep: Reputation: 1
Automate Logins Thru Shell Script


Hi All,

I have automated the logins to a number of servers through the shell script.
But I am left with few since they are not connected directly in the sense I need to connect to a particular intermediate host and from there I need to login to the intender server.

All these servers are unix only. But I am not aware how to invoke a shell from intermediate host and connect the intended destination server.

Kind request to please provide assistance on the same asap.

Note:- As of now the script prompt for the passwords during login.
Please let me know in case if there is any way to encrypt the password and put the same in the script.

Thanks In Advance.
 
Old 04-30-2012, 02:28 AM   #2
flamelord
Member
 
Registered: Jun 2011
Distribution: Arch Linux
Posts: 151

Rep: Reputation: 34
have you tried writing an expect script (rather than a straight shell script)?
 
Old 04-30-2012, 02:35 AM   #3
rhadmn
Member
 
Registered: Oct 2009
Location: Bangalore
Distribution: Redhat Linux, Solaris, CentOS
Posts: 35

Original Poster
Rep: Reputation: 1
Hi Flamelord,

Thanks for your response.
I have not tried expect since the password would be visible. Is there any way in shell to do the same ?? If not, could you please provide a good link for teh expect script ?
I have browsed thru a few and was not able to find a good one where in the password could be encrypted.
 
Old 04-30-2012, 07:41 PM   #4
flamelord
Member
 
Registered: Jun 2011
Distribution: Arch Linux
Posts: 151

Rep: Reputation: 34
how is your password encrypted?

expect lets you run arbitrary bash commands, so whatever method you are using to handle encrypted passwords in bash should be able to be extended to expect.


For prompting the user, take a look at this: http://stackoverflow.com/questions/6...for-a-password

Last edited by flamelord; 04-30-2012 at 07:47 PM.
 
1 members found this post helpful.
Old 05-01-2012, 07:37 AM   #5
rhadmn
Member
 
Registered: Oct 2009
Location: Bangalore
Distribution: Redhat Linux, Solaris, CentOS
Posts: 35

Original Poster
Rep: Reputation: 1
Hi Flamelord,

I would like to rather opt for prompting for the password than encrypting.
I went thru the URL you have provided and got a fair idea.

I got the expect script like below:-

set timeout -1
spawn $env(SHELL)
match_max 100000
expect -exact "]0;jerry@station1:~\[jerry@station1 ~\]\$ "
send -- "ssh tom@station1"
expect -exact "station1"
send -- "\r"
expect -exact "\r
tom@station1's password: "
stty -echo
expect -exact "\r
]0;tom@station1:~\[tom@station1 ~\]\$ "
send -- "ssh jerry@station2"
expect -exact "jerry@station2"
send -- "\r"
expect -exact "\r
jerry@station2's password: "
stty -echo
expect -exact "\r
]0;jerry@station2:~\[jerry@station2 ~\]\$ "
expect eof


It is working fine. But once I get the password prompt I am not able to type anything there and the script is throwing me back.
When I tried to give the passwords and I was able to login to the destination machine through the intermediate server but again was not able to execute any commands.

Request to please check the above expect script and advice in case if I am missing somthing.

Thanks In Advance.
 
Old 05-01-2012, 04:35 PM   #6
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 15.2
Posts: 1,339

Rep: Reputation: 260Reputation: 260Reputation: 260
I would suggest to use an ssh-key to log in. Running an ssh agent in the background would even allow to connect to several machines after you entered the passphrase once.

Then an ssh tunnel created by the option -L could give you access to a secondary machine behind a gateway and by using agent forwarding the same already enabled ssh-key (something like: “ssh -L 1234:server2:22 server1 &” and then “ssh -p 1234 localhost”).

A good Howto about this.
 
  


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
Automate Shell Script For FTP Ashish Sood Linux - General 5 01-22-2012 08:41 AM
Shell Script to automate website login vinaytp Linux - Newbie 2 09-05-2011 04:12 AM
Is it Possible to Automate this Procees using shell script!! anishkumarv Linux - Newbie 8 05-20-2011 07:22 AM
shell script to automate TELNET daggulasreedhar Programming 5 08-02-2007 12:13 PM
Automate FTP session using Shell Script kalyanofb Programming 2 04-07-2007 08:44 AM

LinuxQuestions.org > Forums > Enterprise Linux Forums > Linux - Enterprise

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