title: Bash script - connect to remote server and get results
body: <p>I am trying to write a script that connects to remote server, pings other server (IP as argument) and outputs the result.</p>
  
  <p>So here is what I wrote:</p>
  
  <pre><code>#!/bin/bash
  # IP as argument
  IP=$1
  # Remote connection
  ssh -p 22 pinger@tester.myserver.com
  # 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
  </code></pre>
  
  <p>But I am getting an error:</p>
  
  <pre><code>Name or service not known name tester.myserver.com
  </code></pre>
  
  <p>Of course <code>tester.myserver.com</code> 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.</p>