1

I want to write a script using a for loop and ssh, to log in several server. After logging in using awk command I want to get 7th column printed as output.

I tried the script below but couldn't worked out.

I created a list of IP's in /tmp/list.

for i in `cat /tmp/list`
do
echo $i
echo "***********"
ssh $i |grep tsm |awk -F : '{print $7, "\t"}'
echo
done
lgeorget
  • 13,914

1 Answers1

2

pssh makes this much easier, but for your simple use case ssh will also work.

While what you have above could have worked, provided the server is set up to run a command and exit on login (which is somewhat unlikely) you probably meant something like this:

ssh $i <command> | grep tsm | ...

If you really need to check a login banner for tsm, try using the command exit to immediately return back from the ssh rather than starting an interactive shell:

ssh $i "exit" | grep tsm | ...
Steve Bonds
  • 1,276