<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    jojo's blog--快樂憂傷都與你同在
    為夢想而來,為自由而生。 性情若水,風起水興,風息水止,故時而激蕩,時又清平……
    posts - 11,  comments - 30,  trackbacks - 0
    #!/opt/TLCLperl/bin/perl -w
    #!/usr/local/bin/perl -w

    #
    # use ssh to execute perl script remotely
    #

    # You can change PERL and REMOTE_CMD constants to reflect your real
    # environment...

    use constant PERL => 'perl'; # maybe "/usr/local/bin/perl"
    use constant REMOTE_CMD => 'ssh';
    use constant CAT_CMD => 'cat';

    use strict;
    use vars qw($VERSION);
    $VERSION = '1.00';

    use constant USAGE => <<EOU;

    Usage:

    $0 ""
    [-v] ""
    [-r<remote command flags>] ""
    [-R<remote command>] ""
    [-Q<perl path>] ""
    [<usual perl flags>] ""
    <[<remote user>@]remote_host>[,...] ""
    [<local_script.pl | -e 'perl code'>] ""
    [<script args>]

    EOU

    # options for command line parsing
    my $verbose; # -v
    my @remote_opts; # opts for ssh/remote command
    my $remote_cmd; # ssh substitute
    my @perl_opts; # opts for remote perl
    my $perl_cmd; # remote perl path

    # extract options. This is very simple parsing of options and force
    # the args to be precisely ordered.
    while(defined $ARGV[0] and $ARGV[0]=~/^-/) {
    $_=shift;
    if (/^-v/) { $verbose=1 }
    elsif (/^-r(.*)/) { push @remote_opts,$1 }
    elsif (/^-R(.*)/) { $remote_cmd=$1 }
    elsif (/^-Q(.*)/) { $perl_cmd=$1 }
    else { push @perl_opts,"'$_'" }
    }

    # use the default REMOTE_CMD
    $remote_cmd||=REMOTE_CMD;

    # read remote machine name:
    my $machines=shift or die "error: remote machine not specified"n".USAGE;
    my @machines=split(',',$machines);

    # script name... when available:
    my $file=shift;

    # get the perl code to run remotely:
    my $code;
    if(defined $file and $file eq '-e') {
    # perl code is in cmd line after the -e switch.
    $code=shift or die "error: no perl code after '-e'"n".USAGE;
    }
    else {
    if (defined $file) {
    if($file=~/(.+):(.+)/) {
    # read perl code from remote file
    open(F,"$remote_cmd '$1' ".CAT_CMD." '$2'|")
    or die "error: unable to read remote file '$2' from '$1' ($!)"n";
    }
    else {
    # read perl code from file.
    open(F,"< $file")
    or die "error: unable to open '$file' ($!)"n";
    }
    }
    else { *F=*STDIN } # read perl code from stdin
    {
    # slurp the file to $code
    local $/=undef;
    $code=<F>;
    }
    # gets perl path and flags for first line in src file if available:
    if ($code=~/"A"#!(.*)$/m) {
    my $line=$1;
    if ($line=~/"s*("S+)"s*(.*)/) {
    $perl_cmd||=$1;
    # anything in the line after the perl path will be considered to
    # be flags. I know this could be improved.
    push @perl_opts,$2 if defined $2;
    }
    }
    }

    # use the default PERL location if it is yet unknow
    $perl_cmd||=PERL;

    # convert code to hex string
    my $packed = unpack "h*",$code;

    # this is the remote program to decode and run the script:
    my $decoder = q{'BEGIN{eval"sub _R{".(pack"h*",shift)."}"}_R(@ARGV)'};
    # There was a simpler decoder but it didn't works with the -n flag so
    # I have changed it...
    # my $decoder = q{'eval pack"h*",shift'};

    # format script args with "'" between them:.
    my $args='';
    {
    local $"="' '";
    $args="'@ARGV'" if @ARGV;
    }

    foreach my $machine (@machines) {
    # complete ssh cmd. Remote command is escaped.
    my $cmd="$remote_cmd @remote_opts $machine ".
    quotemeta "$perl_cmd @perl_opts -e $decoder $packed $args";

    # print cmd if verbosity enabled
    print STDERR "remote cmd:"n$cmd"n"n" if $verbose;

    # run it and report problems
    system($cmd)
    and print STDERR "Unable to exec ($!)."nRemote command was:"n$cmd"n"n";
    }

    #################################################
    # documentation:


    =head1 NAME

    sperl - runs perl scripts in remote machines through ssh


    =head1 SCRIPT CATEGORIES

    Networking
    UNIX/System_administration
    Perl/Utilities


    =head1 README

    sperl is some kind of enhanced perl that lets you work in a network
    environment and run scripts and oneliners in remote machines without
    the need to


    =head1 USAGE

    $ sperl "
    [-v] "
    [-r<remote command flags>] "
    [-R<remote command>] "
    [-Q<perl path>] "
    [<usual perl flags>] "
    <[<remote user>@]remote_host>[,...] "
    [<[<[<user>@]machine>:]script.pl | -e 'perl code'>] "
    [<script args>]


    =head1 INSTALLATION

    To install sperl, copy it to some place in your path like
    /usr/local/bin/sperl and allow execution of it with C<chmod 755
    /your/path/to/sperl>.

    If you want, you can edit the script and change the PERL and
    REMOTE_CMD constants at the beginning to match your real environment.


    =head1 DESCRIPTION

    C<sperl> lets you run a locally stored perl script in a remote machine
    for which ssh (or equivalent) access is available.

    It doesn't need any special module installed in local or remote
    machines, just plain perl.

    If there isn't script name in the command line, neither C<-e> option,
    sperl will try to read the code form stdin as perl use to do.

    It's possible to take the script file from another remote machine
    with the syntax C<machine:/path/to/script.pl> or even
    C<user@machine:/path/to/script.pl>.

    It's also possible to include several remote host names separated by
    commas and the script will be run in all of them. For example C<hippo,bugs,bill@www.microsoft.com>


    =head1 OPTIONS

    C<sperl> accepts the same command line options as C<perl> does. The
    options are passed unchanged to the remote perl interpreter so some of
    them like C<-S> are nonsense.

    Additionally, it accepts some specific options:

    =over

    =item -rE<lt>remote command flagsE<gt>

    pass options to ssh. For instance C<-r-v>

    =item -RE<lt>remote commandE<gt>

    specify the command to use in place of ssh to connect to the remote
    machine. for instance C<-Rrsh>.

    =item -QE<lt>remote perl pathE<gt>

    specify the location of the perl interpreter in the remote
    machine. By default, sperl will try to look for the perl path in the
    script first line, if it uses the notation C<#!/path/to/perl>. As its
    last resource it expects perl to be in the PATH.

    =item -v

    dumps the remote command to stderr before running it. This is primary
    for debugging purposes.

    =back


    =head1 EXAMPLES

    [salvador@hippo:~]$ sperl admin@willy "
    > -e 'print "hello from ".`hostname`'
    hello from willy

    # the -t option force ssh to allocate a new tty...
    [salvador@hippo:~]$ sperl -w -r-t willy -e 'print $count+1,""n"'
    Use of uninitialized value at (eval 1) line 1.
    1

    # you can even invoke the perl debugger remotely:
    [salvador@hippo:~]$ sperl -d -r-t willy -e 1

    Loading DB routines from perl5db.pl version 1.0401
    Emacs support available.

    Enter h or `h h' for help.

    main::(-e:1): BEGIN{eval"sub _R{".(pack"h*",shift)."}"}_R(@ARGV)
    DB<1> p `hostname`
    p `hostname`
    willy

    DB<2> ...

    # running the same code in several machines:
    [salvador@hippo:~]$ sperl bugs,willy,hippo -e "
    > 'chomp($h=`hostname`);print "hello from $h!!!"n"'
    hello from bugs!!!
    hello from willy!!!
    hello from hippo!!!



    =head1 CHANGES

    =over

    =item sperl 1.00 Thu Sep 23 1999

    First public release

    =back


    =head1 BUGS AND LIMITATIONS

    This is a beta release so expect errors in it.

    Lots of spelling errors in the docs... Help me!!!

    The order of the options in the command line is very inflexible.

    Switch parsing for the first line of the script is not very clever and
    it will produce unexpected results if something complex is there.

    Scripts with C<__END__> or C<__DATA__> sections will fail.

    I don't know if there is any possibility to make this to work in
    Microsoft's world.


    =head1 AUTHOR

    Salvador Fandiño García <salvador@cesat.es, fandino@usa.net>


    =head1 SEE ALSO

    L<perl(1)>, L<ssh(1)> or L<rsh(1)>, L<perlrun(1)>.


    =cut
    posted on 2009-08-06 12:08 Blog of JoJo 閱讀(557) 評論(0)  編輯  收藏 所屬分類: 每日一記My Script

    <2025年5月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    常用鏈接

    留言簿(6)

    隨筆檔案

    文章分類

    文章檔案

    新聞分類

    新聞檔案

    相冊

    收藏夾

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 久久精品国产精品亚洲精品| 亚洲精品视频免费观看| 精品亚洲成AV人在线观看| aa毛片免费全部播放完整| 亚洲第一区在线观看| 青青免费在线视频| 亚洲无码精品浪潮| 亚洲精品黄色视频在线观看免费资源| 国产jizzjizz视频全部免费| 亚洲成AV人影片在线观看| 免费鲁丝片一级在线观看| 亚洲精品成a人在线观看夫| 国产精品麻豆免费版| 国产精品成人亚洲| AV在线亚洲男人的天堂| 久久www免费人成看国产片| 亚洲人色婷婷成人网站在线观看| 国产情侣久久久久aⅴ免费 | 免费真实播放国产乱子伦| 国产亚洲视频在线观看| 亚洲深深色噜噜狠狠爱网站| 免费看黄的成人APP| 亚洲日本一区二区三区| 成人无遮挡裸免费视频在线观看 | 免费夜色污私人影院网站电影| 亚洲高清无码在线观看| 拍拍拍无挡视频免费观看1000| 亚洲酒色1314狠狠做| 国产桃色在线成免费视频 | 亚洲精品国产高清在线观看| 亚洲国模精品一区| 大地影院MV在线观看视频免费| 亚洲成年人免费网站| 波多野结衣免费视频观看| a在线视频免费观看| 亚洲免费视频观看| 亚洲国产午夜中文字幕精品黄网站| 中文字幕日本人妻久久久免费| 亚洲高清中文字幕免费| 在线精品亚洲一区二区三区| 国产91免费视频|