What I am basically trying to achieve is to automate something I do every time I start work.

In this order, I

  1. VPN connection
  2. Open new gnome-terminal tab
  3. SSH into a remote machine

I have this so far:

WID=$(xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)"| awk '{print $5}')
xdotool windowfocus $WID
xdotool type --delay 1 --clearmodifiers "sudo openvpn --config 'conn1.ovpn'"
xdotool key Return

xdotool key ctrl+shift+t
wmctrl -i -a $WID
sleep 1

while ! $(/usr/bin/fping -q; do sleep 1;done

xdotool type --delay 3 --clearmodifiers "ssh machine1"
sleep 3
xdotool key Return

The problem I am having is that the SSH commands require the VPN connection to be open first. I thought that by putting the last sleep command in, that the code would wait for 3 seconds before hitting enter.

What is actually happening is that the openvpn command is not running until after the last sleep, so the SSH command fails.

Can someone please point me in the direction I need to be heading for this.


Put a waiting loop before starting ssh:

while ! $(/usr/bin/fping -q <openvpn remote endpoint ip>); do sleep 1;done
|improve this answer|||||
  • When I do this, the VPN connection won't run. The new tab opens but both tabs appear to be waiting for the IP to be available – Wildcard27 Nov 8 '17 at 0:09
  • @Wildcard27 do you mean that with the ping loop the VPN doesn't go up anymore? – Zip Nov 8 '17 at 0:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.