File: ssh.pl

package info (click to toggle)
libexpect-perl 1.21-1.1
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 256 kB
  • sloc: perl: 2,030; makefile: 38
file content (165 lines) | stat: -rw-r--r-- 4,503 bytes parent folder | download | duplicates (2)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/usr/bin/perl
#
#      A Simple Terminal Resizing Example
#      GPL version 2. See the COPYING file
#
# This script is a simple example of how handle terminal
# window resize events (transmitted via the WINCH signal)
# -- Jeff Carr <jcarr@linuxmachines.com>
#

if( ! defined $ARGV[0] ) {
	print "Usage: ssh.pl <host> <username> <password>\n";
	exit;
}

my ($host, $username, $password) = @ARGV;

use Expect;
use IO::Pty;

my $spawn = new Expect;
$spawn->raw_pty(1);  

# This gets the size of your terminal window
$spawn->slave->clone_winsize_from(\*STDIN);

my $PROMPT;

# This function traps WINCH signals and passes them on
sub winch {
	my $signame = shift;
	my $pid = $spawn->pid;
	$shucks++;
	print "count $shucks,pid $pid, SIG$signame\n";
	$spawn->slave->clone_winsize_from(\*STDIN);
	kill WINCH => $spawn->pid if $spawn->pid;
}
$SIG{WINCH} = \&winch;  # best strategy

$spawn=Expect->spawn("ssh $username\@$host");
# log everything if you want
# $spawn->log_file("/tmp/autossh.log.$$");

my $PROMPT  = '[\]\$\>\#]\s$';
my $ret = $spawn->expect(5,
	[ qr/\(yes\/no\)\?\s*$/ => sub { $spawn->send("yes\n"); exp_continue; } ],
	[ qr/assword:\s*$/ 	=> sub { $spawn->send("$password\n"); exp_continue; } ],
	[ qr/ogin:\s*$/		=> sub { $spawn->send("$username\n"); exp_continue; } ],
	[ qr/REMOTE HOST IDEN/ 	=> sub { print "FIX: .ssh/known_hosts\n"; exp_continue; } ],
	[ qr/$PROMPT/ 		=> sub { $spawn->send("echo Now try window resizing\n"); } ],
);

# Hand over control
$spawn->interact();
exit;
#!/usr/bin/perl
#
#      A Simple Terminal Resizing Example
#      GPL version 2. See the COPYING file
#
# This script is a simple example of how handle terminal
# window resize events (transmitted via the WINCH signal)
# -- Jeff Carr <jcarr@linuxmachines.com>
#

if( ! defined $ARGV[0] ) {
	print "Usage: ssh.pl <host> <username> <password>\n";
	exit;
}

my ($host, $username, $password) = @ARGV;

use Expect;
use IO::Pty;

my $spawn = new Expect;
$spawn->raw_pty(1);  

# This gets the size of your terminal window
$spawn->slave->clone_winsize_from(\*STDIN);

my $PROMPT;

# This function traps WINCH signals and passes them on
sub winch {
	my $signame = shift;
	my $pid = $spawn->pid;
	$shucks++;
	print "count $shucks,pid $pid, SIG$signame\n";
	$spawn->slave->clone_winsize_from(\*STDIN);
	kill WINCH => $spawn->pid if $spawn->pid;
}
$SIG{WINCH} = \&winch;  # best strategy

$spawn=Expect->spawn("ssh $username\@$host");
# log everything if you want
# $spawn->log_file("/tmp/autossh.log.$$");

my $PROMPT  = '[\]\$\>\#]\s$';
my $ret = $spawn->expect(5,
	[ qr/\(yes\/no\)\?\s*$/ => sub { $spawn->send("yes\n"); exp_continue; } ],
	[ qr/assword:\s*$/ 	=> sub { $spawn->send("$password\n"); exp_continue; } ],
	[ qr/ogin:\s*$/		=> sub { $spawn->send("$username\n"); exp_continue; } ],
	[ qr/REMOTE HOST IDEN/ 	=> sub { print "FIX: .ssh/known_hosts\n"; exp_continue; } ],
	[ qr/$PROMPT/ 		=> sub { $spawn->send("echo Now try window resizing\n"); } ],
);

# Hand over control
$spawn->interact();
exit;
#!/usr/bin/perl
#
#      A Simple Terminal Resizing Example
#      GPL version 2. See the COPYING file
#
# This script is a simple example of how handle terminal
# window resize events (transmitted via the WINCH signal)
# -- Jeff Carr <jcarr@linuxmachines.com>
#

if( ! defined $ARGV[0] ) {
	print "Usage: ssh.pl <host> <username> <password>\n";
	exit;
}

my ($host, $username, $password) = @ARGV;

use Expect;
use IO::Pty;

my $spawn = new Expect;
$spawn->raw_pty(1);  

# This gets the size of your terminal window
$spawn->slave->clone_winsize_from(\*STDIN);

my $PROMPT;

# This function traps WINCH signals and passes them on
sub winch {
	my $signame = shift;
	my $pid = $spawn->pid;
	$shucks++;
	print "count $shucks,pid $pid, SIG$signame\n";
	$spawn->slave->clone_winsize_from(\*STDIN);
	kill WINCH => $spawn->pid if $spawn->pid;
}
$SIG{WINCH} = \&winch;  # best strategy

$spawn=Expect->spawn("ssh $username\@$host");
# log everything if you want
# $spawn->log_file("/tmp/autossh.log.$$");

my $PROMPT  = '[\]\$\>\#]\s$';
my $ret = $spawn->expect(5,
	[ qr/\(yes\/no\)\?\s*$/ => sub { $spawn->send("yes\n"); exp_continue; } ],
	[ qr/assword:\s*$/ 	=> sub { $spawn->send("$password\n"); exp_continue; } ],
	[ qr/ogin:\s*$/		=> sub { $spawn->send("$username\n"); exp_continue; } ],
	[ qr/REMOTE HOST IDEN/ 	=> sub { print "FIX: .ssh/known_hosts\n"; exp_continue; } ],
	[ qr/$PROMPT/ 		=> sub { $spawn->send("echo Now try window resizing\n"); } ],
);

# Hand over control
$spawn->interact();
exit;