shell scripting while if string length != 0
Dave [Hawk-Systems]
dave at hawk-systems.com
Thu Jul 31 18:12:47 PDT 2003
for reasons best left unsaid, we need to pull in a file full of partial
commands, and run them via a shell script on occasion, removing each command as
we run it. Have managed to hack togetherthe following shell script, but and
stumped on something simple because of my lack of shell knowledge;
the file that holds out commands
<file_o_commands>
Server1 df -k
Server2 df -k
Server3 top | grep myprog
Server4 who
add new commands to the end of the file with
echo "Server2 who" >> /path/to/file_o_commands
then when we need to, run through the commands
<file_to_run_stuff>
#!/bin/sh
# get top command
DOCOMMAND=`head -n 1 /path/to/file_o_commands`
# remove that command
cat /path/to/file_o_commands | sed '1d' > /path/to/file_o_commands
# run that command
ssh ${DOCOMMAND}
this works as intended with 1 exception, we need to add a while in there to loop
through the file and stop processing an exit when `head -n 1
/path/to/file_o_commands` does not return a line.
I almost want to borrow -n from if
while [ -n (DOCOMMAND=`head -n 1 /path/to/file_o_commands`) ] do
...rest of script...
done
Anyone care to enlighten me a bit?
Dave
More information about the freebsd-questions
mailing list