Solved

what are these modules in perl script

Posted on 2016-07-31
4
98 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
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.…
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.:
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

773 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