Automate the menu options using shell script

I have a menu option which will look as follows
Select a menu option
1.change password
2.login as root user
3.show system version
4.quit
Select> 1
please enter the new password: unix
reenter the new password: unix
press any key to enter
(then displays again the menu options to enter the value)
Select a menu option
1.change password
2.login as root user
3.show system version
4.quit
Select>4
#

Question: the above the shell script in the linux
Now i want to automate the above script using shell scripting and create the report for the same

Can any body help me on this
what i tried is
1.Create a shell script
2.all the menu option values as inputs in the test file
3. generated outputs in the output file
4.Now i need to validate the values
for ex:1 changed the password successfully.............
5.I also need to generate the report for the same.

Please help me on this.

Thanks
Shiva

If this is calling the supplied passwd command, then it will be difficult. The thing is that passwd will empty/ignore the input buffer you may supply and this is to stop people trying to subvert or bypass it.

There are some brute-force methods, but they increase the risk to compromising you accounts and losing access so you can't undo it.

My guess is that you want to automate setting your password across multiple servers which each have a simple menu system on them. Not a good plan. If you want to tie machines together in such a way, consider using one of:-

  • SSH keys
  • LDAP
  • NIS

Can you confirm what you really want to do/bypass?

Robin

Hi Robin,

Actually the code of the menu items and corresponding calls to each option already done by some developers
may task is to test the options are working correctly or not.
i am giving one more example for
when i enter 3, the system version will be displayed by running a command "sudo /opt/systeminfo/version.sh"
output displayed for the input:
System Information:
------------------------
Version:1.0.0.1
Build number:12

Now using the automated script for this option
1.start the menu
2.Enter the value 3
3.Validate whether the Version and build number are similar to what exit in version
4.Display the report
Now i can be able to do 1 and 2 steps but how to do the step3 and step4...

So a totally different thing to what you asked for in the first place? Count me out from assistance.

Thanks Robin,

See i gave explanation for option1 in my main post
For understanding provided explanation for option3..

My intention is to automate the options present in the Menu and validate the outputs using shell scripting.

The code i wrote for my automation script

#!/bin/bash
/bin/bash -c  "su shelladmin  <  /tmp/testfile > /tmp/outputfile"

shelladmin is where the menu options are present.
This will take the input options in the testfile and prints everything in the outputfile
testfile has
1
unix
unix

4

EOF
Thanks
Shivakumar