Re: Scripting



Calab wrote:
Looking to create a small script that will process the output of one command and run another command

Output looks like this
38914 - system1 online -
38915 - system1 online -
38922 - system1 online -
11013 - system2 offline -
21914 - system3 busy -
21916 - system3 busy -
20355 - system4 offline -

If I recieved the above output, I'd want to run the following commands

syscheck system2
syscheck system4

This should be simple to do, but I've not got a clue how to script on a Linux PC.

Any pointers? Suggestions?

Thanks!



#!/bin/bash
for i in $(command)
do
j=$(echo "$i" | cut -f4)
k=$(echo "$i" | cut -f3)
[ "$j" = "busy" ] && syscheck "$k"
done
#

where "command" gives your table, "cut" assumes tabs are the column delimiters. - man cut

HIH

--
c.e@xxxx

.



Relevant Pages

  • Scripting
    ... Looking to create a small script that will process the output of one command ... Any pointers? ...
    (alt.os.linux)
  • Re: Scripting
    ... "cut" assumes tabs are the column delimiters. ... For some reason, $i does not contain the complete line. ... Tried a very simple run and you can see that each line output by the ls -l command is split up. ...
    (alt.os.linux)
  • Re: Scripting
    ... "cut" assumes tabs are the column delimiters. ... For some reason, $i does not contain the complete line. ... Tried a very simple run and you can see that each line output by the ls -l command is split up. ...
    (alt.os.linux)