Articles of perl

从expect / tcl传递多个参数到perl脚本

我在下面的脚本中遇到一些麻烦。 proc checkUser {userip} { set search "show users | include " set search_cmd [concat $search $userip] exp_send "$search_cmd\r" expect { -re "Vi.*" { set oui "uei.opennms.org/services/passiveServiceStatus" set host "localhost" set iface "–interface $userip" set service "–service Test" set parm1 "–parm 'passiveNodeLabel [getNodeName $userip]'" set parm2 "–parm 'passiveIpAddr $userip'" set parm3 "–parm 'passiveServiceName Test'" set […]

Linux如何在远程服务器的后台运行脚本?

我在一台linux机器上。 我想在删除服务器上运行四个Perl脚本。 每个脚本都会生成一个输出文件,但运行可能需要几个小时。 我想在后台运行脚本,如果我从服务器断开连接或退出shell提示符,它将继续运行。 这些脚本还在运行时向命令terminal输出行。 我希望能够检查脚本正在打印到命令terminal的print语句。 我通常会使用screen -S命令来创build一个屏幕。 然后按CTRL+A CTRL+D去附加,并screen -r重新连接到屏幕,但我所在的远程服务器没有屏幕。 而且我没有安装sudo的权限。 如何在远程服务器的后台同时运行这4个Perl脚本?

Perl Directory Finder不起作用?

我有一个脚本来查找目录和.tar.gz文件。 不pipe什么原因(这就是我希望你能帮助我的)我的 if ( -d $file ) 不返回,这是一个目录! 我的脚本: # specify the directory where you want to start the search my $directory = $ARGV[0]; my $directoryCount = 0; # Calling the Subroutine, which searches the File readDirectory($directory); sub readDirectory { my $directory = shift; my $searchfile = shift; my @directories; my $tarOuput; # a little […]

通过perl,linux和anyevent在分叉进程中启动并行任务的智能方式是什么?

我有AnyEvent :: Utils :: fork_call的问题。 我使用fork_call,然后做一些工作,之后,我应该结束我的fork_call,并开始新的并行任务。 我试过了: fork_call { # very important work # start new parallel task if (my $pid = fork) { # other important and very long work } } sub { # never reached this, while parallel task working } 我认为,任何事件fork_call正在等待所有的孩子完成他们的工作。 那么我怎样才能避免这个问题? 也许我应该摆脱父母的过程? 任何build议和意见,欢迎。 谢谢。

如何在单词(正则expression式,grep)之后停止search?

嗨,我想停止search,一旦我到了这个词的结尾。 例如: ls -al | grep adh 这就是我的search…我想停止“h” 我正在search的目录有adh两个实例,有adh2和adh …我只是想adh不adh2 ! 希望这是有道理的,任何问题,请问:) 仅供参考我是Linux / perl初学者!

使用perl XS链接到一个C共享库

我是PERL XS的新手,并且有一个关于调用Ansi C编写的共享库(.so)的问题。我似乎找不到任何可以准确显示如何执行此操作的好例子。 我去教程开始(Hello World和所有这些)位于这里: http://www.lemoda.net/xs/perlxstut/ 我想修改它以在C共享库中调用一个名为cpro_supported的函数。 libpmap.so: extern int cpro_supported(int); 这里有一些基础知识: Makefile.PL: use 5.008005; use ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( NAME => 'test', VERSION_FROM => 'lib/test.pm', # finds $VERSION PREREQ_PM => {}, # eg, Module::Name => 1.1 ($] >= […]

传输文件使用scp

我试图将大量的数据从一台服务器转移到另一台服务器上。 我试过使用 scp <file> <address@server:/path/to/scp/to 哪个起作用,但是对于大文件来说非常慢,并且要求我为每个scpinput一个密码。 我也试过在传输之前和之后进行压缩和解压缩,但速度更慢。 有更快的方法吗? 这是传输大量数据的最佳方式吗?

减去小时和分钟

我想从10小时零分钟减去17小时5分钟。 #!/usr/bin/perl use Time::Piece; my $t1 = Time::Piece->strptime( '10:00', '%H:%M' ); my $t2 = Time::Piece->strptime( '17:05', '%H:%M' ); my $t = $t2 – $t1; print $t->hour; print $t->min; 但我得到的错误 Can't locate object method "hour" via package "Time::Seconds" 我没有Time :: Piece的偏好。 它只是缝合stream行,已经安装在Linux上。 题 任何人都可以看到为什么会失败

我如何循环pipe道中的数据?

我发现一些Perl中的进程可以通过pipe道进行通信的代码。 例: if ($pid = fork) { close $reader; print $writer "Parent Pid $$ is sending this\n"; close $writer; waitpid($pid,0); } else { close $writer; chomp($line = <$reader>); print "Child Pid $$ just read this: `$line'\n"; close $reader; exit; } 现在我有以下问题: 是否有可能让读者从pipe道中读取,然后阻塞,直到新的数据从pipe道中像循环一样来? 如果是,当父进程没有数据发送时,杀死subprocess的方式是什么? 每个程序有多less个打开的读/写pipe道是有限制的? 例如,如果我叉十进程,并有20个pipe道(10读/ 10写)这是一个坏主意? 如果问题太基本,我很抱歉,但我的经验是用另一种语言的线程。

如何在perl中创build依赖进程

启动subprocess的最好方法是,当父进程终止时,subprocess也将被终止。 我可以看到我的过程像一棵树: 1 26152 26150 26150 ? -1 Sl 1000 0:00 /usr/bin/perl /usr/local/bin/disp 26152 26171 26150 26150 ? -1 S 1000 0:00 \_ /bin/bash /var/tmp/job_500 26171 26172 26150 26150 ? -1 S 1000 0:00 | \_ /usr/bin/perl /usr/local/bin/qrun /var/tmp/ml_500 600 26152 26174 26150 26150 ? -1 S 1000 0:00 \_ /bin/bash /var/tmp/job_1000 26174 26175 26150 […]