Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to automate login procedure? 2

Status
Not open for further replies.

mgrabovac

Technical User
Oct 16, 2002
4
US
Hi guys,
I would like to ask all Unix experts on this forum one question.
I need to write shell script which will automate login/password procedure.I need to call Unix command &quot;su - <username> &quot; and to supply password for selected username in the script.
Thanks in advance for all answers.
Alex
 
Hi Alex,

my suggestion is to install Secure Shell.

The authentication can then be realised via private/public key rather than a password. If you transfer a user's public key to a remote server that he wants to connect to, then this user can login over the SSH protocol without being prompted for his password. This method is much safer than telnet, r-commands, ftp anyway.
Another advantage is the encryption of the whole session and the guaranteed data integrity!

Have a look at or to get the details.

HTH,

mrjazz [pc2]
 
Yes, you can do this.
Use expect.

here is a sample script:
#!/usr/bin/expect

log_user 0
set timeout 1200

proc debug {} {
global argv
if {[regexp &quot;debug&quot; $argv]} {
exp_internal 1
} else {
send_user &quot;No debug enabled.\n&quot;
}
}

proc sup { pass } {
global timeout
set rootprompt &quot;root@[exec uname -n]:.*&quot;
spawn -noecho su
expect {
-re &quot;Passwor.+&quot; {
send &quot;$pass\r&quot;
expect {
-re &quot;$rootprompt&quot; {
send_user &quot;\nRoot login successful..\n&quot;
send &quot;\r&quot;
interact {
&quot;quit&quot; {send_user &quot;\n&quot; ; exit}
}
}
}
}
-re &quot;^(su:) .+&quot; {
send_user &quot;Bad password..\n&quot;
return
}
}
}
debug
send_user &quot;Password: &quot;
stty -echo
expect_user -re &quot;(.*)\n&quot; {set pass $expect_out(1,string)}
stty echo
sup $pass
 
Hi all,
thanks for all your responses.
I'll try some of the proposed solutions and see how it works.
Thanks again.
alex
 
Expect would be my first choice too. IBM Certified Confused - MQSeries
IBM Certified Flabbergasted - AIX 5 pSeries System Administration
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top