I am trying to write a script that connects to remote server, pings other server (IP as argument) and outputs the result.
So here is what I wrote:
#!/bin/bash
# IP as argument
IP=$1
# Remote connection
ssh -p 22 [email protected]
# Pinging and saving only latency results to RESULT
RESULT=`ping -i 2 -c 4 $IP | grep icmp_seq | awk '{print $7}' | cut -b 6-12`
# Outputs the result
echo $RESULT
But I am getting an error:
Name or service not known name tester.myserver.com
Of course tester.myserver.com is just example but if I manually type that ssh command with my real remote server address it does work. So I've really no idea why this won't work as a script.
sshcommand will block until you exit it, and thenpingetc. will be executed on the local machine, right?