Re: Writing Shell script to interactively control another shell script??
- From: nospamplssteve@xxxxxxxxx
- Date: 15 Jan 2007 06:23:17 -0800
Thanks just what I needed,
script.sh |&
exec 4>&p
10: exec 5<&p
11:
12: cat namefile
13:
14: # read the names from a file "namefile"
15: while read uname; do
16: print -u4 $uname
17: read -u5 dndname
Just another question
How do I redirect the output for the coprocess to a file??
I tried using exec 5>"test.log" new to this stuff.......but does not
work
any sample code would be helpful.
Janis Papanagnou wrote:
nospamplssteve@xxxxxxxxx wrote:
Using Solaris,
Say you want to write a shell script to control another simple menu
entry shell script like the following testscript.sh file
///////////////////////
themenu()
{
echo "MENU"
echo "1 - Check Status and other stuff "
echo "2 - Run program"
echo "3 - Exit"
echo ""
}
while true
do
themenu
read input
case $input
1) //check status and do some other stuff ;;
2) //start program and other background processes;;
3) break;; //exit loop and program
*) ;;
done
//////////////////////////////////////////////////////////////////
What I want to automate is do the following
Press 1 to check status then do a grep "Program is running fine"
if "Program is running fine" then Press 3 to exit
else
Press 2 to start program then press 3 to exit
No I don,t want to use Expect or tcl so can I do this using shell
script only with out modifying the original shell script???
I could create a shell script that has the following which just starts
the program/background processes and exit but it does not check the
status beforehand.....and redirection only allows you to
send input from a file and read the output from file after the program
ends......
sh testscript.sh<<EOF
2
3
EOF
If you need clarifications on my question pls ask
Any help would be much appreciated. Thanks
I am not sure I understood what you want (and you didn't tell us which
shell you need to use), but...
You may want to inspect ksh's co-process facilities. It allows you to
start a program in the background
program args |&
that is still attached to the main script through a bidirectional pipe
that you can write to and read from with
print -p whatever your program expects
read -p some data returned
By re-assigning (re-directing) the co-process filedescriptors you may
use more than one co-process in your script, if necessary.
BTW, ksh also supports menus if you like (see 'select' command).
Janis
.
- References:
- Writing Shell script to interactively control another shell script??
- From: nospamplssteve
- Re: Writing Shell script to interactively control another shell script??
- From: Janis Papanagnou
- Writing Shell script to interactively control another shell script??
- Prev by Date: Re: Writing Shell script to interactively control another shell script??
- Next by Date: Re: Writing Shell script to interactively control another shell script??
- Previous by thread: Re: Writing Shell script to interactively control another shell script??
- Next by thread: Re: Writing Shell script to interactively control another shell script??
- Index(es):
Relevant Pages
|
|