Reputation: 381
I am trying to create a script and that run a program and when this program is run it says either DB already running or Port is already being used by another process(Means already running)
If it is already running I wish to create a if- else statement and wish to add 1 to a file if already running but if not running add 0 to file
This is my tcl file named test
#!/usr/bin/expect -f
set f [open a2.txt w]
cd /opt/Uni-SON/
spawn ./Aprogram start
expect {
"Port is already being used by another process"
puts $f 1
puts "sadsadasdsaa"
}
puts $f 0
This is my test2 file which is bash file
#!/bin/bash
./test
value=$(<a2.txt)
rm -rf a2.txt
if [ $value -eq 0 ]
then
echo Not being used
else
echo Already Being used
fi
ERROR :It is not adding data to the file but if I put the exact same statement puts $f 1
outside the expect brackets it works
What is wrong ?
How do I do it?
Upvotes: 0
Views: 24
Reputation: 137797
The problem with this statement:
expect {
"Port is already being used by another process"
puts $f 1
puts "sadsadasdsaa"
}
is that it's triggering the case where you have a set of things to wait for. You probably want to change it to:
expect {
"Port is already being used by another process" {
puts $f 1
puts "sadsadasdsaa"
}
}
Which is to say when that message is found, do the little script (two puts
calls) associated with it. You can wait for several things at once too, and that's where expect
becomes very powerful!
Upvotes: 1