2

I have two files, the first contains a series of names :

CONTAINER1 CONTAINER2 CONTAINER3 CONTAINER4 

And the second script runs when the sintaxis is ./script.sh CONTAINER1

 CONT=$1 PID=`opmnctl status -noheaders -fmt %prt30%pid7R | grep -w $CONT | awk '{print $3}'` netstat -anp | grep $PID | grep ESTABLISHED > $CONT-temp 

Is it possible to run the second script by parsing each line of the first file?. I'm new at bash, any help would be appreciated.

Thanks in advance

2
  • well actually its a small part of a bigger script, what it matters to me is how can i achieve that, basically with that command i get the established connections from a container of my application server.. Commented Feb 21, 2014 at 16:32
  • FYI, it's conventional to use lower-case names for variables which aren't either (1) shell built-ins, or (2) exported to the environment. Also, as a correctness issue, your second script should be quoting its expansions -- so grep "$pid" rather than grep $pid. Commented Feb 21, 2014 at 16:32

1 Answer 1

1

You can use xargs for this: it reads words from its stdin and appends them to the given command. Normally it takes several parameters at a time so it invokes the given command as few times as possible, but you can control that with the -L option:

xargs -L 1 echo "name is:" < containers.txt 

produces

name is: CONTAINER1 name is: CONTAINER2 name is: CONTAINER3 name is: CONTAINER4 

You would write

xargs -L 1 ./script.sh < containers.txt 
Sign up to request clarification or add additional context in comments.

1 Comment

you've make my day buddy...it was just what i needed

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.