I have a script that shows all the instances on AWS that I'm running:
$/home/scripts/show_instances.sh
i-f66d2de0 running 10.148.17.40
i-fxxdbbe0 running 10.148.20.60
(...)
What I'd like to do is to take the first IP, pipe to ssh and connect to the server automatically. I tried this:
$/home/scripts/show_instances.sh | tail -1 | awk '{print $3}' | xargs ssh
But is not working: it connects to the server but after the first command that I type (i.e. ls), the terminal just seems to be waiting for something and nothing happens (I'm on mac connecting to Unix), so I have to exit the instance with ctrl+c. Some suggestions?
xargsis buying you anything in this case. If your headline is really your Q, thenssh $(..../show_instances.sh | awk 'NR==1{print $3}') ..other ssh stuff ...(using cmd-substitution$(...)) should solve your problem. (don't need tail). Otherwise it seems that your Q may be about "how do I usexargs). Good luck.$( )) for obtaining this (I can't show you how backticks work because they are used for formatting purposes on StackOverflow website)./home/scripts/show_instances.sh | tail -1 | awk '{print $3}'Thank you!$(... cmds sub );-) .. Backticks are your backup, if you get stuck using an ancient system that doesn't support$(..). Also, read about theawkinternal variableNR, you don't needtailfor this case. Good luck.