-
Notifications
You must be signed in to change notification settings - Fork 13
/
keepalive
executable file
·57 lines (45 loc) · 1.32 KB
/
keepalive
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/opt/perl-5.6.1/bin/perl
#
# Keep an ssh session alive (for port forwarding). Not sure whether
# this is actually of use, since it's tocket's java app TCP connection
# which needs to be kept alive and that's done via shiver-pointer on
# the client WM.
#
# $Id$
use strict;
use warnings;
my $ESCAPE = '~@@';
use lib '/home/lonlxadm/lib/perl5';
use FindBin '$RealScript';
use Getopt::Long;
use lib '/home/aspiers/lib/perl5';
use Expect;
@ARGV or usage();
sub usage {
die <<EOF;
Usage: $RealScript connect-command [arg1 [arg2 ...]]
Connect to remote site, get a prompt, then hit $ESCAPE
EOF
}
my $exp = new Expect;
$exp->slave->clone_winsize_from(\*STDIN);
#$exp->slave->stty(qw(raw -echo));
$exp->log_user(0);
$exp->spawn(@ARGV) or die "Cannot spawn $ARGV[0]: $!\n";
print "Login and get a prompt, then hit $ESCAPE\n";
$exp->interact(\*STDIN, $ESCAPE);
print "\nEscape received; switching to keepalive mode.\n";
# Send a control-U to cancel escape sequence
$exp->send("\cu\n");
$exp->expect(1, "\n"); # flush expect queue
$exp->send("cat > /dev/null\n");
$exp->expect(1, "\n"); # flush expect queue
#$exp->expect(0);
my $mins = 0;
while (1) {
$exp->send("$mins minute" . ($mins == 1 ? '' : 's') . " of keepalive; press C-c to disconnect\n");
sleep 1; # yuk
$exp->expect(1, "\n"); # flush expect queue
sleep 60;
$mins++;
}