Ibrahim M. Ghazal
2014-May-14 16:20 UTC
Waiting until tunnel (ssh -w) is set up before running command
When using VPN tunnelling (-w option), is there a way to know when the tunnel is actually up? I want to use this in a script that automatically sets up the tunnel by running ssh -w then running ifup [1]. The -f option doesn't help because it returns after connecting to the server but before the tunnel is up. Sleeping for a few seconds does work, but it just feels too hacky. The LocalCommand option seems to work, for example: ssh -w 0:1 "-oLocalCommand=ifup tun0" "-oPermitLocalCommand=yes" myserver.example.org true However, the man page says: "The command is run synchronously and does not have access to the session of the ssh(1) that spawned it." Is the above invocation guaranteed to work or was it just luck that LocalCommand was executed after the tunnel is set up? More importantly, is there a standard way for using ssh -w in scripts? [1] I'm on Fedora, ifup works because I've set up /etc/sysconfig/network-scripts/ifcfg-tun0 and /etc/sysconfig/network-scripts/route-tun0
Apparently Analagous Threads
- [PATCH] Allow matching HostName against Host entries
- [RFC/PATCH] ssh: config directive to modify the local environment
- [PATCH] LocalPreCommand: Support for executing command before ssh connection (like port knock before ssh)
- Uniquely Identifying the Local TTY of an SSH Connection
- Feature request: "SetupCommand" invoked before connecting