1843342 Members
3585 Online
110214 Solutions
New Discussion

UNIX Scripting

 
Elaine Pang
New Member

UNIX Scripting

How do I simulate keyboard input into my script? I am writing a script to shut down one of my application programs. The command to shut it down is sc stop. The application will pause and ask for a password to be entered. How do I put the password in the script so that the application won't pause for the password? Please help !!!
3 REPLIES 3
James A. Donovan
Honored Contributor

Re: UNIX Scripting

This may or may not work, depends on how the application was written...

#!/bin/sh
/dir/dir/sc stop <password
EOF

Replace /dir/dir and password with whatever is appropriate for your needs.
Remember, wherever you go, there you are...
Joseph A Benaiah_1
Regular Advisor

Re: UNIX Scripting

You could try writing a script that does the following:

#!/usr/bin/sh

echo xxxxx | "sc stop"


The above says that echo xxxxx(which represents your password) to the command sc stop. This should work although it is not advisable to put the password in a shell script as it is a security risk.

Regards,

Joseph.
Brian Markus
Valued Contributor

Re: UNIX Scripting

Try a program called "Expect" It will expect certain things from a script that's interactive. Then do something. http://expect.nist.gov/
It's really good for automating interactive applications.
When a sys-admin say's maybe, they don't mean 'yes'!