Login, excute command, logout Script Help | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Login, excute command, logout Script Help

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-11-2013
mutley2202 mutley2202 is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 28 October 2014, 8:08 PM EDT
Posts: 29
Thanks: 2
Thanked 0 Times in 0 Posts
Login, excute command, logout Script Help

Good Evening all,
After spending the last week or so reading many posts I decided to register and join in. This is my first post on the forum so please forgive me as im new to this, Im after some help in throwing together a quick basic script without using expect to change the password on several routers.

All i need to do is below

ssh username@hostname

then you will be prompted for a password so the script needs to enter the password.

Commands that need entering

password change

then you will be prompted for current password so script to enter current password

you will then be prompted to enter new password so again script to enter

then you are requested to confirm the password again.

logout then start over again on the next router.

unfortunatly i am unable to create password less login either...

Any help you guys can offer would be very much appreciated.

Thanks

Last edited by mutley2202; 01-11-2013 at 06:57 PM..
Sponsored Links
    #2  
Old 01-11-2013
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 21 November 2014, 4:36 PM EST
Location: NM
Posts: 10,279
Thanks: 287
Thanked 814 Times in 756 Posts
You cannot easily 'enter a password' with ssh, it is built to bypass most attempts at that.
The passwd command is also that way. You will need to bypass those problems which involves some advanced techniques.

What you will have to do is one of these:

1. If you are root or an admin, ssh to the remote box and do password changes one by one manually

2. install the "expect" application and create an expect script to answer all the prompts. You outlawed that already.

3. write a pty emulator in C that can become the sessions leader/terminal owner.
see:
Solaris Systems Programming
download: source code The code you want is called pty.c It is meant for Solaris, but with minor changes it will work on linux.
It is basically like expect in that it allows batch interaction with passwords embedded.

Which BTW is a terrible idea.

Since you have a few routers, this post sat unaswered for a while, maybe you could have completed the task manually. If you want a longterm solution consider #2 or #3.
The Following User Says Thank You to jim mcnamara For This Useful Post:
mutley2202 (01-12-2013)
Sponsored Links
    #3  
Old 01-12-2013
mutley2202 mutley2202 is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 28 October 2014, 8:08 PM EDT
Posts: 29
Thanks: 2
Thanked 0 Times in 0 Posts
Thanks for your advice much appreciated, this is a task I have to so on a regular basis so will defiantly be looking at my options.
    #4  
Old 01-12-2013
RudiC RudiC is offline Forum Advisor  
Registered User
 
Join Date: Jul 2012
Last Activity: 22 November 2014, 2:29 PM EST
Location: Aachen, Germany
Posts: 4,682
Thanks: 78
Thanked 1,158 Times in 1,088 Posts
Consider using/installing (cf. man )
Quote:
NAME
chpasswd - update passwords in batch mode
You said
Quote:
unfortunatly i am unable to create password less login either...
- does this mean it is forbidden by policies or you don't know how to?
Sponsored Links
    #5  
Old 01-12-2013
mutley2202 mutley2202 is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 28 October 2014, 8:08 PM EDT
Posts: 29
Thanks: 2
Thanked 0 Times in 0 Posts
Hi RudiC, Its not allowed due to internal policys unfortunatly.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Login and logout logs in server kancherla.sree Solaris 10 07-07-2011 07:29 AM
Login/Logout script tthaler OS X (Apple) 3 11-23-2009 05:55 PM
Login and logout time of a session sharif UNIX for Advanced & Expert Users 1 03-10-2008 06:10 AM
detecting login or logout nortypig Shell Programming and Scripting 8 08-27-2006 09:30 PM
Login and logout script jhansrod UNIX for Dummies Questions & Answers 1 06-06-2005 07:54 AM



All times are GMT -4. The time now is 01:48 AM.