[X-Unix] Bash scripting Question
Eric F Crist
ecrist at secure-computing.net
Tue Aug 22 20:17:27 PDT 2006
Russell,
I would ask first if there is a different exit code for someone being
connected and nobody being connected. You can check this by running
fmsadmin and checking the exit code immediately afterward. First,
run fmsadmin with someone connected to the flash server. After it
executes, type "echo $?" at the command line (minus the quotes). You
should get a number and your command line again. Write this code
down and execute fmsadmin again, this time with everyone
disconnected. After it executes, type "echo $?" again, without the
quotes. You may get the same number, but lets hope it's different.
Now, IF and only IF you have two different exit codes, something like
the following should work for you:
#!/bin/sh
#End script after 210 seconds or exit code of 0.
## Initialize the variables. ##
starttime=$(date +%s)
# Set this variable to the number of seconds you want the program
# to run before timing out.
endtime=210
exitnow=0
runtime=0
calctime=0
exitcode=99
## Time to do the dirty work. ##
while [ "$exitnow" -ne "1" ]; do
if [ "$runtime" -lt "$endtime" ]; then
if [ "$exitcode" -ne "0" ]; then
fmsadmin status Clients
exitcode=$?
echo "Running for $runtime seconds."
else
exitnow=1
fi
else
exitnow=1
fi
calctime=$(date +%s)
runtime=$(( $calctime - $starttime))
done
echo "Exited at `date`."
Any questions, let me know.
Eric Crist
On Aug 22, 2006, at 11:11 AM, Russell McGaha wrote:
> Folks;
> I've got a situation where I running a script and need to wait
> till the output of a command is null:
>
> ex.
> NotNull = true
> While NotNull
> do
> fmsadmin status Clients #[returns a list of connected clients;
> I'd like to got thru
> this loop until either the output of the command is null or
> About 2-5 minutes have gone by]#
> done
>
> Can anyone give ANY pointers or examples on how to do this?
>
> Russell
>
> PS. I'm on the digests so PLEASE cc me directly
> _______________________________________________
> X-Unix mailing list
> X-Unix at listserver.themacintoshguy.com
> http://listserver.themacintoshguy.com/mailman/listinfo/x-unix
>
> Listmom is trying to clean out his closets! Vintage Mac and random
> stuff:
> http://search.ebay.com/_W0QQsassZmacguy1984
>
-----
Eric F Crist
Secure Computing Networks
More information about the X-Unix
mailing list