Friday, December 14, 2012

How to set a crontab job for a perl script

In this tutorial I’m going describe how to set a crontab job for perl script on a linux system. The following example I'm going to demonstrate, how to  execute perl script every five minutes. below is the steps

[1] list the existing crontab using following command. If you have not set any crontab jobs it will display noting.
[shehan@localhost ~]$ crontab -l

crontab job

[2] issue following command to create a new crontab or edit previously created crontab 
[shehan@localhost ~]$ crontab -e

[3] add following line of code to crontab and don't forget to edit your perl script path.
*/5 means script will be executed every 5 minutes time , for ex :- 10.00 , 10.05 , 10.10 etc

*/5 * * * * perl /path/to/your/perlscript/

some tricky example
3-58/5 * * * * perl /path/to/your/perlscript/

This would still execute perl script every five minutes, but it would run on the 3's and 8's - e.g. 12:03, 12:08, 12:13, 12:18, etc.

[4]that's it !


How To Install Perl Modules Manually on linux

I  recently try out  perl script which is used to test download speed. when I run that script it gives me the following error saying that can’t locate Perl module called Time::Format .

Can't locate Time/ in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 ... )....

Can't locate Time/ in @INC

Solution for this error is install the perl module, in this case by installing the Time::Format perl module. below is most required steps to install any perl module.

[1] switch to root and launch the CPAN using following command
 [root@localhost ~]# perl -MCPAN -e shell

[2] type the module name according to below format, in this example I’m going to install Time::Format perl module.
cpan[1]> install Time::Format

[3] that’s all !! . now run your perl script again :)

Related Posts