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

    隨筆檔案

    文章分類

    文章檔案

    新聞分類

    新聞檔案

    相冊

    收藏夾

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 97热久久免费频精品99| 国产高清在线精品免费软件| 亚洲乱码在线播放| 成年人视频在线观看免费| 欧洲亚洲国产精华液| 亚洲高清国产拍精品26U| 丁香花免费完整高清观看| 另类小说亚洲色图| 久久亚洲春色中文字幕久久久| 免费看美女被靠到爽的视频| 久久性生大片免费观看性| 亚洲电影在线播放| 亚洲av成人一区二区三区在线观看| 99热在线观看免费| 最好2018中文免费视频| 亚洲ts人妖网站| 亚洲无av在线中文字幕| 免费看无码自慰一区二区| 久久精品国产影库免费看| 亚洲av无码一区二区三区在线播放| 亚洲av永久无码精品漫画| 国产v片免费播放| 最好看的中文字幕2019免费| 国产成人无码免费看片软件| 色老板亚洲视频免在线观| 亚洲AV日韩精品久久久久久久| 蜜臀91精品国产免费观看| 日韩精品无码一区二区三区免费 | 在线看片无码永久免费视频| 久久一区二区免费播放| 国产精品亚洲专区无码不卡| 亚洲最大黄色网址| 亚洲精品无码MV在线观看 | 亚洲午夜爱爱香蕉片| 毛片a级毛片免费播放下载| 无码少妇精品一区二区免费动态| 一级做a爰片性色毛片免费网站| 亚洲色大网站WWW永久网站| 亚洲小说区图片区| 亚洲欧洲日韩国产综合在线二区| 亚洲综合久久夜AV |