mkk Posted September 9, 2013 Posted September 9, 2013 Hi there, starting a perl script with cron seems to be a problem for not only me... at least according to google.In another post, it was recommend to start perl scripts either as CGI or with cron.I would prefer cron but cannot get it to work. Supposing my script is "script.pl" and is stored in "/home/mkk/www":How would I set up a cron job for it? I would also be interested in hearing about a way to debug cron: Where are the errors/warning stored when a cron job died? By the way:The script I am talking about does something, sleeps 10sec., does something, sleeps... and this is being done in an endless while-loop.Is that a problem for your server? Thanks for your help.
Byron Posted September 9, 2013 Posted September 9, 2013 Your path would look something like this: /home/byron/public_html/cgi-bin/cron.cgi As far as errors go, I think it will send them to your email? Your script might be a problem if it draws too many system resources.
mkk Posted September 11, 2013 Author Posted September 11, 2013 What's the timezone the cron jobs are living in?
Ice IT Support Posted September 11, 2013 Posted September 11, 2013 Our servers operate in Pacific time (-8). Currently we are in Daylight Savings time, thus the timezone is technically -7.
mkk Posted September 11, 2013 Author Posted September 11, 2013 OK, using a .com email address, I finally get some response from cron:/bin/sh: /home/mkk/public_html/cgi-bin/perlScript.cgi: Permission denied Permission denied on my own scripts?
Byron Posted September 11, 2013 Posted September 11, 2013 Are you able to execute the script from your browser and by any chance is this a part of your path: /bin/sh: or was that just added in the email?
Krydos Posted September 11, 2013 Posted September 11, 2013 Maybe you deleted it after you posted but that file doesn't exist: root@stevie [/home/mkk/public_html/cgi-bin]# ls -la total 20 drwxr-xr-x 2 mkk mkk 4096 Sep 11 09:16 ./ drwxr-x--- 3 mkk nobody 4096 Sep 10 22:56 ../ -rw-r--r-- 1 mkk mkk 6339 Sep 10 22:57 einsatzsms.cgi -rw-r--r-- 1 mkk mkk 1168 Sep 10 23:49 test.cgi Also, looking at those two .cgi files you do have there, you need to make sure your scripts have the proper shebang line at the beginning of the file. If the code is perl then the shebang should look something like: #!/usr/bin/perl
mkk Posted September 11, 2013 Author Posted September 11, 2013 As stated in my initial question, I am looking for a way to execute a perl script with cron.Your suggestion was to execute it as CGI, which I did despite the fact that I do not understand why I should do so. I have a perl script named myScript.pl (filename made up) and I want to execute this script.You do not provide SSH so cron seems like a possible workaround. My question was simply: What's the command to put in the cron job to have a script being executed which is stored in "/home/mkk/www"? To answer your questions:- No, I cannot execute the script using my browser. I get ERROR 500. Could be because it's not a CGI script- The /bin/sh has only been added in the email. By the way: My script starts with:BEGIN { my $b__dir = (-d '/home/mkk/perl'?'/home/mkk/perl':(/&--#62;/&--#62; getpwuid($&--#62;) )[7].'/perl'); unshift @INC,$b__dir.'5/lib/perl5',$b__dir.'5/lib/perl5/x86_64-linux',map { $b__dir . $_ } @INC;}Right after that, my code starts...
Byron Posted September 11, 2013 Posted September 11, 2013 If you can't execute the script from your browser, neither can cron. Make sure your script will execute first and then add it to cron. As stated in my initial question, I am looking for a way to execute a perl script with cron.Your suggestion was to execute it as CGI, which I did despite the fact that I do not understand why I should do so. It doesn't matter if the script ends in .cgi or .pl as long as it's a cgi/perl script. I only ended my example in .cgi because that was from one of my cron jobs. Go ahead and end yours with .pl
mkk Posted September 18, 2013 Author Posted September 18, 2013 I hate it!I cannot even get the easiest script to run.Here's the code: #!/usr/bin/perl BEGIN { my $b__dir = (-d '/home/mkk/perl'?'/home/mkk/perl' getpwuid($>) )[7].'/perl'); unshift @INC,$b__dir.'5/lib/perl5',$b__dir.'5/lib/perl5/x86_64-linux',map { $b__dir . $_ } @INC; } print "Hello World!"; The "BEGIN {}" was given from cPanel > Perl Modules. The script is located at:http://einsatzsms.heliohost.org/cgi-bin/test2.pl Whatever I try, I get error 500.
Byron Posted September 18, 2013 Posted September 18, 2013 Perl is already installed without using the module. Just code a simple hello world script like this and give it file permissions 755: #!/usr/bin/perl -w use CGI::Carp qw(fatalsToBrowser); use CGI qw(:standard); print header; print "Hello World"; http://byrondallas.heliohost.org/cgi-bin/hello-world.cgi You actually don't have to keep all cgi/perl scripts in the cgi-bin if you don't want. They'll work in any part of the public_html folder.
mkk Posted September 18, 2013 Author Posted September 18, 2013 Thanks Byron. 755 did the trick! By the way:I really like the possibility to install cpan modules automatically. 5 stars for that!Is there anything else I need to do after installing a new module before I can use it in my scripts?
Byron Posted September 18, 2013 Posted September 18, 2013 I really like the possibility to install cpan modules automatically. 5 stars for that! Is there anything else I need to do after installing a new module before I can use it in my scripts? As far as I know cpanel should tell you ever thing you need to know but you didn't need that perl module to run cgi/perl scripts on your site. The server is already set up to run those languages.
mkk Posted September 19, 2013 Author Posted September 19, 2013 OK,include path for my modules was missing. Got it working now... Is it correct that SMTP connections from within perl scripts are not allowed? (at least not with a free plan)I get a connection timeout when I try to establish one...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now