This topic has been archived. It cannot be replied.
-
工作学习 / IT技术讨论 / 一个有关在shell里调用perl的问题,有人能帮我吗?
-qoo(QOO);
2003-8-8
(#1323699@0)
-
有, next question?
-mssg(mssg);
2003-8-8
(#1323717@0)
-
谢谢你,是这样的.
-qoo(QOO);
2003-8-8
{611}
(#1323738@0)
-
Does "alert.sh" have execution permission?
-shaomiao(少淼);
2003-8-8
(#1323762@0)
-
yes. In alert.sh, " mail -s " has been successfully called.
-qoo(QOO);
2003-8-8
(#1323782@0)
-
what do you mean "auto execute", by CRONTAB? If you use CRONTAB, you cannot use echo to output text to screen, but can redirect to a file
-wander2001(猫行天下);
2003-8-8
(#1323772@0)
-
NO. It's using a program to do so other than crontab. Crontab is scheduled job only.As I said, "mail -s" can be successfully called up so alert.sh has no problem to be automatically called up. I was hung up at perl portion.
-qoo(QOO);
2003-8-8
{141}
(#1323785@0)
-
Try to use full path of perl?
-wade(wade);
2003-8-8
(#1323787@0)
-
Tried but in vain.
-qoo(QOO);
2003-8-8
(#1323803@0)
-
You mean you already tried the full path for "perl" command , not your perl script?
-wander2001(猫行天下);
2003-8-8
(#1323819@0)
-
yes. New script:---------------------------------------------
#!/bin/sh
while read line
do
echo $line | mail -s "test alert" abc@company.ca;
echo $line | /usr/bin/perl /opt2/getdesc.pl | /usr/bin/perl /opt2/snort/notify/snortnotify.pl -f /opt2/snort/notify/notify.conf;
done
-------------------------------------------------
-qoo(QOO);
2003-8-8
{324}
(#1323826@0)
-
What is the error code?
-wade(wade);
2003-8-8
(#1323824@0)
-
What if I could do some debug?! I didn't see any error, neither did I know where to find the error.
-qoo(QOO);
2003-8-8
(#1323837@0)
-
If the code not hang there, type echo $? as soon as the code exit
-wade(wade);
2003-8-8
(#1323854@0)
-
I guess the problem is some over-looked detail.Try something like:
#!/bin/sh
touch /tmp/content.$$
touch /tmp/err.$$
while read line
do
echo $line >> /tmp/content.$$
echo $line | /usr/bin/perl /opt2/getdesc.pl | /usr/bin/perl /opt2/snort/notify/snortnotify.pl -f /opt2/snort/notify/notify.conf 1> /tmp/err.$$ 2>&1
echo $? >> /tmp/err.$$
done
Then,
cat /tmp/err.<pid>
What is the return code? Any error message?
cat /tmp/content.<pid> | alert.sh
Does the perl portion work fine?
-shaomiao(少淼);
2003-8-8
{458}
(#1323862@0)
-
why not just do a "echo input lines | sh -x alert.sh 1>/tmp/alert.sh.$$ 2>&1" ?
-ztech(zoo technician);
2003-8-8
(#1323874@0)
-
He/she has done that from command line and it worked fine.
-shaomiao(少淼);
2003-8-8
(#1323888@0)
-
估计是你调用perl的时候出的问题,因为你在自动跑 壳程序(shell) 的时候 路径(path) 没有设置,试试这个:在你的unix shell里面敲一行 which perl
然后把那个输出贴到你的 壳程序里面去, 把所有的 perl 命令全部换成这个输出
-tztz(退休老团长);
2003-8-8
{112}
(#1324376@0)
-
Give me your input, please! Thx
-qoo(QOO);
2003-8-8
(#1323808@0)
-
When it runs without manual input, how does it get the input? What is your command line?
-ztech(zoo technician);
2003-8-8
(#1323821@0)
-
My program will do some pattern matching. Once it matches, it will trigger this alert.sh and pipe matched text to this shell script.
-qoo(QOO);
2003-8-8
(#1323834@0)
-
I see. replace mail with /usr/bin/mail and perl with /usr/bin/perl. Commend out the perl script to see if mail works. And then replace each perl with a simple perl that writes to a file.. U get the idea.
-ztech(zoo technician);
2003-8-8
(#1323842@0)
-
OH, IN YOUR JAVA/PERL/SHELL/SED/AWK PROGRAM, REPLACE "sh" with "/bin/sh" OR EVEN "/bin/bash" which ever is more appropriate.
-ztech(zoo technician);
2003-8-8
(#1323849@0)
-
谢谢大家的指点,我发现问题在这里, shell script里:echo $line | /usr/bin/perl /opt2/getdesc.pl | /usr/bin/perl /opt2/snort/notify/snortnotify.pl
第一个pipe后没有把结果传个第二个pl做为输入.若我改成:
echo $line | /usr/bin/perl /opt2/getdesc.pl >> /var/log/test.output;
cat /var/log/test.output | /usr/bin/perl /opt2/snort/notify/snortnotify.pl;
就可以了. 但是我还是希望用pipe来连接两个perl的输入输出.各位大虾能再帮我想想这个pipe的问题吗? 谢谢了.
-qoo(QOO);
2003-8-11
{400}
(#1327850@0)
-
让俺瞅瞅你的getdesc,pl, 是不是没有用标准输出 (print) ?
-tztz(真爽);
2003-8-11
(#1327986@0)
-
这次终于发现问题所在了.不是上面pipe的问题.其实是:echo $line 后系统自动在原来的文本前加了一个<33>(不太明白为什么会加了这么个东西.),由于这个增加,使得perl里不能再匹配到文本了.
-qoo(QOO);
2003-8-11
{123}
(#1328065@0)