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

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.

1 Like

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.

Consider using/installing (cf. man )

You said

  • does this mean it is forbidden by policies or you don't know how to?

Hi RudiC, Its not allowed due to internal policys unfortunatly.