ssh - Start a Perl script remotely over LAN or WiFi -
scenario
laptop a: have perl script automates ftp/upload download. let me call ftp_script.pl. run script , rest.
system b: now, @ different location. want trigger perl script(ftp_script.pl) remotely laptop b(from home) only using perl script. want know what possible ways trigger perl script using perl script?
requirements:
- i want start perl script (say ftp_script.pl) sitting home remote system (located in office) public ip know.
- i want start perl script (say ftp_script.pl) 1 laptop other connected on lan via hub.
is possible achieve?
ps: don't know perl scripting.
we need have mechanism @ remote host can pick requested connection on specified port, , handle debugger interaction command line can use netcat reduce dependencies on external programs, , give better idea happening behind scenes, can use following program
#!/usr/bin/perl -w use strict; use getopt::long; use io::socket; use term::readline; use constant bignum => 65536; our $previous_input; # set host , port. $host = shift || 'localhost'; $port = shift || 12345; # on 1024 please die("usage: $0 hostname portno") unless ($host =~ /\w+/ && $port =~ ^\d+$/); print "listening on $host:$port\n"; $term = new term::readline 'local prompter'; $out; { # strict subs complains stdout, turn off moment. no strict 'subs'; $out = $term->out || stdout; } $out->autoflush(1); # open socket debugger connect to. $sock = new io::socket::inet( localhost => $host, localport => $port, proto => 'tcp', listen => somaxconn, reuse => 1); $sock or die "no socket :$!"; $new_sock = $sock->accept(); # try pick remote hostname prompt. $remote_host = gethostbyaddr($sock->sockaddr(), af_inet) || 'remote'; $prompt = "($remote_host)> "; ($buf, $input # read output debugger, read debugger input. while (1) { # drop out if remote debugger went away. exit 0 unless sysread($new_sock, $buf, bignum); print $out $buf; # drop out if got end-of-file locally (warning: # causes remote perl drop dead because socket goes away). exit 0 unless defined($input = $term->readline($prompt)); print { $new_sock } munge_input($input); # add line terminal history. $term->addhistory($input) if $input =~ /\s/; } # debugger interaction can confused if string gets # passed null. clean here. sub munge_input { $actual_input = shift; $actual_input = "\n" unless defined $actual_input;
note whichever program choose listener, need select port number higher 1024 unless you’re running root (not idea) on machine.you can debug perl program remote machine using perldb_opts
perldb_opts="remoteport=192.168.0.7:12345" perl helloworld hello world process id(2798)
ip address:port number
Comments
Post a Comment