Solved

what are these modules in perl script

Posted on 2016-07-31
4
83 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
Comment Utility
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
Comment Utility
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 76

Accepted Solution

by:
arnold earned 250 total points
Comment Utility
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
Comment Utility
got it, thank you very much, it's working now.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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.

762 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now