App::PersistentSSH - Kick an ssh control master around on OSX using scutil
% persisshtent --host your.host.com
This POE component will keep an SSH control master alive, depending on network status.
It uses the OSX command line tool scutil to get notification on changes to the State:/Network/Global/IPv4 configuration key. Whenever this key is changed scutil -r will be used to check if the specified host is directly reachable (without creating a connection using e.g. PPP), and if so spawn ssh.
State:/Network/Global/IPv4
scutil -r
If the host is not reachable, ssh is stopped.
Add something alongs the lines of
Host * ControlPath /tmp/%r@%h:%p
to your ssh_config, in order to configure the path that the ssh control master will bind on. ControlMaster auto is not needed.
ControlMaster auto
The advantage over ControlMaster auto is that if you close your initial ssh, which is the control master under auto all subsequently made connections will also close. By keeping a daemonized, managed instance of ssh this problem is avoided.
auto
ssh
Use ssh -v yourhost to verify that the connection really is going through the control master.
ssh -v yourhost
You can create a launchd service for this using http://lingon.sourceforge.net/. I use:
<key>Disabled</key> <false/> <key>KeepAlive</key> <true/> <key>Label</key> <string>pasta ssh</string> <key>ProgramArguments</key> <array> <string>/usr/local/bin/perl</string> <string>/Users/nothingmuch/Perl/App-PersistentSSH/bin/persisshtent</string> <string>--verbose</string> <string>--host</string> <string>pasta.woobling.org</string> </array>
The host to connect to. Must be a valid ipaddress/hostname, not just an ssh config host entry.
Pass -v to ssh.
-v
Additional options for ssh, useful for tunnelling etc.
Spawn the POE component.
new_with_options comes from MooseX::Getopt.
new_with_options
Calls "run" in POE::Kernel.
This module is maintained using Darcs. You can get the latest version from http://nothingmuch.woobling.org/code, and use darcs send to commit changes.
darcs send
Yuval Kogman <nothingmuch@woobling.org>
Copyright (c) 2008 Yuval Kogman. All rights reserved This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install App::PersistentSSH, copy and paste the appropriate command in to your terminal.
cpanm
cpanm App::PersistentSSH
CPAN shell
perl -MCPAN -e shell install App::PersistentSSH
For more information on module installation, please visit the detailed CPAN module installation guide.