Date: Thu, 31 Jul 2003 21:12:41 -0400 From: "Dave [Hawk-Systems]" <dave@hawk-systems.com> To: "FreeBSD Questions" <freebsd-questions@FreeBSD.ORG> Subject: shell scripting while if string length != 0 Message-ID: <DBEIKNMKGOBGNDHAAKGNMEGJCPAC.dave@hawk-systems.com>
next in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?DBEIKNMKGOBGNDHAAKGNMEGJCPAC.dave>