?
Solved

what are these modules in perl script

Posted on 2016-07-31
4
Medium Priority
?
129 Views
Last Modified: 2016-08-01
I have written a script to send me an email when a new post in a forum comes out. however, when I run this script I got the folloing error:

[jyu@jenkins-test ~]$ crontab -l
40 */2 * * * /home/jyu/script/mit.pl
[jyu@jenkins-test ~]$ /home/jyu/script/mit.pl
/home/jyu/script/mit.pl: line 4: use: command not found
/home/jyu/script/mit.pl: line 5: use: command not found
/home/jyu/script/mit.pl: line 6: use: command not found
/home/jyu/script/mit.pl: line 7: use: command not found
/home/jyu/script/mit.pl: line 8: use: command not found
/home/jyu/script/mit.pl: line 9: use: command not found
/home/jyu/script/mit.pl: line 12: use: command not found
/home/jyu/script/mit.pl: line 14: my: command not found
/home/jyu/script/mit.pl: line 16: my: command not found
/home/jyu/script/mit.pl: line 18: my: command not found
/home/jyu/script/mit.pl: line 20: my: command not found
/home/jyu/script/mit.pl: line 22: my: command not found
/home/jyu/script/mit.pl: line 24: my: command not found
/home/jyu/script/mit.pl: line 26: syntax error near unexpected token `"xiaoyaogu",'
/home/jyu/script/mit.pl: line 26: `main( "xiaoyaogu", $encoding, $selector );'
[jyu@jenkins-test ~]$ perl /home/jyu/script/mit.pl
[jyu@jenkins-test ~]$ which perl
/usr/bin/perl
[jyu@jenkins-test ~]$ cd script/
[jyu@jenkins-test script]$ ls -alth
total 12K
drwxr-xr-x 2 jyu developers 4.0K Jul 31 20:25 .
drwxr-xr-x 9 jyu developers 4.0K Jul 31 20:25 ..
-rw-r--r-- 1 jyu developers    0 Jul 31 20:21 new
-rwxr-xr-x 1 jyu developers 2.2K Jul 31 19:50 mit.pl
[jyu@jenkins-test script]$ vi mit.pl
[jyu@jenkins-test script]$ sudo su
root@jenkins-test:/home/jyu/script$ perl -MCPAN -e shell
mit.pl.txt
0
Comment
Question by:Jason Yu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 21

Assisted Solution

by:Mazdajai
Mazdajai earned 1000 total points
ID: 41736778
You get the error first time because the system don't which interpreter to use.

#!/usr/bin/env perl 

Open in new window


It works the second time because you pass it to run perl directly. Add the following to the first line of the script -

[jyu@jenkins-test ~]$ perl /home/jyu/script/mit.pl

Open in new window

0
 

Author Comment

by:Jason Yu
ID: 41736806
Hi, Mazdajai:

I added your line to my script and it doesn't give me errors anymore, but I still didn't receive any emails about the new posts. How could I test if the email was blocked by the firewall?

The source code is in the attachment of the last post.

thanks.
0
 
LVL 79

Accepted Solution

by:
arnold earned 1000 total points
ID: 41736976
The first line should be a complete path to perl
which perl
#!/usr/bin/perl

Make sure the commands you use inside I.e. Sendmail is a full path /usr/sbin/sendmail
Cron defaults to a limited path /bin:/usr/bin such that sendmail will not be found if referenced.

Cron based script should always use explicit and completes paths to command and directories/files that the script needs/uses.
0
 

Author Comment

by:Jason Yu
ID: 41738315
got it, thank you very much, it's working now.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question