<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)

    隨筆檔案

    文章分類

    文章檔案

    新聞分類

    新聞檔案

    相冊

    收藏夾

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 成全视频在线观看免费高清动漫视频下载| 人妻18毛片a级毛片免费看| 综合久久久久久中文字幕亚洲国产国产综合一区首 | 亚洲伊人tv综合网色| 成人片黄网站色大片免费观看APP| 亚洲区小说区图片区| 亚洲欧洲综合在线| j8又粗又长又硬又爽免费视频 | 在线视频免费观看高清| 亚洲色偷偷综合亚洲AV伊人| 456亚洲人成影院在线观| 91免费播放人人爽人人快乐| 亚洲无人区一区二区三区| 日韩精品无码免费专区午夜| 久久夜色精品国产嚕嚕亚洲av| 亚洲丶国产丶欧美一区二区三区| 午夜一级毛片免费视频| 亚洲欧美在线x视频| 毛片免费vip会员在线看| 成人婷婷网色偷偷亚洲男人的天堂| 日本不卡视频免费| 特级毛片在线大全免费播放| 亚洲色精品88色婷婷七月丁香| 一级毛片免费观看| 国产精品亚洲一区二区麻豆| 精品无码AV无码免费专区 | 免费一看一级毛片人| 亚洲日本va在线观看| 日本特黄特色aa大片免费| 一级做a爰性色毛片免费| 国产一级做a爱免费视频| aa毛片免费全部播放完整| 亚洲va中文字幕无码| 亚洲精品乱码久久久久久蜜桃图片 | 免费A级毛片无码久久版| 精品国产麻豆免费人成网站| 在线亚洲人成电影网站色www| 日韩精品极品视频在线观看免费 | 国外成人免费高清激情视频| 中文字幕不卡高清免费| 亚洲αv在线精品糸列|