Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Login, excute command, logout Script Help

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 01-11-2013
mutley2202 mutley2202 is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 9 October 2016, 10:07 AM EDT
Posts: 60
Thanks: 12
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 Unix and Linux 01-11-2013
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 30 November 2016, 10:00 AM EST
Location: NM
Posts: 10,874
Thanks: 457
Thanked 984 Times in 915 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 Unix and Linux 01-12-2013
mutley2202 mutley2202 is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 9 October 2016, 10:07 AM EDT
Posts: 60
Thanks: 12
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 Unix and Linux 01-12-2013
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 2 December 2016, 1:06 PM EST
Location: Aachen, Germany
Posts: 9,886
Thanks: 198
Thanked 2,940 Times in 2,745 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 Unix and Linux 01-12-2013
mutley2202 mutley2202 is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 9 October 2016, 10:07 AM EDT
Posts: 60
Thanks: 12
Thanked 0 Times in 0 Posts
Hi RudiC, Its not allowed due to internal policys unfortunatly.
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 08:18 PM.