I am trying to write a script to make a ssh tunnel persist. I am writing it to check the existence of the tunnel on port 3307 and if it is not found start it:
#!/usr/local/bin/bash
# ~/my_tunnel.sh
tunnel_up=`ps ax|grep 3307`
if [ "${tunnel_up}" = "" ]; then
ssh -fNg -C -L 3307:127.0.0.1:3306
bob@db.webstakez.com & 2>/dev/null
fi
I believe that this is not working because the grep is returning a value for the actual grep command even when the tunnel is down. As an example, I check for anything on port 3308 since the tunnel is up:
$ ps waux|grep 3308
10014 18755 0.0 0.0 1428 440 pts/0 S 12:53 0:00 grep 3308
This is a Linux system, 2.4.20-021stab028.3.777-enterprise #1 and grep does not act this way on my freebsd box. What can I do to so that this will not return the actual grep?
TIA,
Bob