<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片| 天天看免费高清影视| 亚洲国产一区二区三区在线观看| 最近中文字幕无吗免费高清 | 亚洲精品色午夜无码专区日韩| 午夜免费国产体验区免费的| 亚洲视频人成在线播放| 成人免费777777被爆出| 亚洲AV无码久久精品蜜桃| 最近最好最新2019中文字幕免费| 亚洲日本在线免费观看| 久久精品网站免费观看| 国产亚洲蜜芽精品久久| 亚洲熟妇无码AV在线播放 | www.免费在线观看| 亚洲无mate20pro麻豆| 国产成人精品123区免费视频| 免费中文字幕视频| 久久久亚洲精品无码| 最新欧洲大片免费在线| 特级一级毛片免费看| 国产AV无码专区亚洲AV男同| 国产精品入口麻豆免费观看| 亚洲熟妇无码AV| 久久亚洲中文字幕精品一区| 久久久久久国产精品免费无码| 亚洲综合色婷婷在线观看| 亚洲熟女乱综合一区二区| 114级毛片免费观看| 亚洲a∨无码精品色午夜| 亚洲熟妇无码八AV在线播放| 黄页网站在线观看免费高清| 一日本道a高清免费播放| 亚洲国产高清视频在线观看| 亚洲国产综合人成综合网站| 91麻豆国产免费观看| 免费一级特黄特色大片|