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
Solved

what are these modules in perl script

Posted on 2016-07-31
4
102 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
  • 2
4 Comments
 
LVL 21

Assisted Solution

by:Mazdajai
Mazdajai earned 250 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 77

Accepted Solution

by:
arnold earned 250 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Utilizing an array to gracefully append to a list of EmailAddresses
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…

789 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