Probably the output is going to:
std.err
You can try:
eval vncviewer $machine:149 > /tmp/${machine}_vnc_status.txt 2>&1 &
Question
I am trying to write a shell script that checks to see if vncservers are created or not. The idea is to execute "vncviewer MACHINE_NAME" and based on the textual output I can decide whether there's a server created or not (I basically look for "unable")
linuxMachineList="grd-ies-rh6-03"
for machine in $linuxMachineList
do
echo "Pinging $machine..."
echo -n '' > /tmp/${machine}_vnc_status.txt
eval vncviewer $machine:149 &> /tmp/${machine}_vnc_status.txt&
proc_id=$!
kill -9 $proc_id
grep -i unable /tmp/${machine}_vnc_status.txt > /dev/null
if [ $? == 0 ]
then
echo "Error: $machine does not respond"
else
echo "$machine is OK!"
fi
done
the problem is that because vncviewer invokes a popup window, I need to automatically kill the vncviewer process because I have a big list of machines and can't afford to interact with each popup window. So the solution was to save the process ID in "proc_id" using $!. But I read that $! is only effective with processes that are invoked in the background. And here comes the problem, when I invoke vncviewer in the background and redirect stderr&stdout to a file, it seems that it does actually write to the file when it is finished/closed but not killed. So now I have an empty text file no matter what since I always interrupt the vncviewer operation by killing it before it writes to the output file which I use to make the decision.
Any help?
Pas de solution correcte
Autres conseils
Probably the output is going to:
std.err
You can try:
eval vncviewer $machine:149 > /tmp/${machine}_vnc_status.txt 2>&1 &