Gossamer Forum
Home : General : Perl Programming :

Question about cgi scripts and crontab

Quote Reply
Question about cgi scripts and crontab
Hi! I have a cgi script which goes through the directories in my site and search for files which have been modified for the past 7 days. It would then write the results into a .shtml file. I have tried to get crontab to do this everyday at midnight. But whenever the crontab runs, the results of the script is never output to the .shtml. In addition, when I receive a mail from crontab it keeps showing the result which is only printed when there are no new files for the past 7 days. However, when I run the script through my browser, it outputs the correct results and shows that there were new files for the past 7 days and this is written to the .shtml file.

Does anyone know why I'm encountering this problem and also does anyone know where I can learn more about crontab and how to configure cgi scripts to run under crontab? I search around and basically they all tell me how to make the crontab file but tell me nothing about troubleshooting it. Would apprecite any help. Thank you.
Julian
Quote Reply
Re: [vampy] Question about cgi scripts and crontab In reply to
Try the attached script to setup the crontab :) Just a little script I wrote when developing my Links SQL Cron Plugin Wink

Hope that helps.

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Question about cgi scripts and crontab In reply to
The way you setup the crontab isn't going to change the output Cool ....I don't think he had a problem installing the cronjob.
Quote Reply
Re: [Paul] Question about cgi scripts and crontab In reply to
Mmm...ok Julian, have you tried using full Paths? When you run it via SSH/Telnet, I'm assuming you are in the directory of the script, and then running it with;

perl file.cgi

correct? If so, then sometimes Perl scripts get confused with their destination paths/relative paths....but when you are doing it via SSH, the path is set to the folder you are already in. Could be completly wrong here...but this is from previous experience Tongue

Also, may wanna see if you can get the output of the cronjob emailed to you (by your system admin), or emailed to the 'root' user for your domain normally....

Just throwing a few ideas at you :)

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Question about cgi scripts and crontab In reply to
Quote:
when you are doing it via SSH, the path is set to the folder you are already in

No that's not true, the path is defined in your bash profile and is exported by the PATH variable.
Quote Reply
Re: [vampy] Question about cgi scripts and crontab In reply to
Hello Vampy,

If it works from a browser and not from crontab , it sounds like a permissions problem.

1. From the browser means the default user for CGI is allowed to read and write in the output directory.

2. The crontab user may not have permissions to read and write in the output directory.

thanks

cornball
Quote Reply
Re: [vampy] Question about cgi scripts and crontab In reply to
You should try running the script from your ssh account and see what happens.
Quote Reply
Re: [Paul] Question about cgi scripts and crontab In reply to
I do have the output sent to me vis mail and it's like what I mentioned before, it keeps giving me the output that would be generated if there were no new files for the past 7 days. My crontab file has the following lines:

#!/bin/sh
/var/www/html/WhatsNew.cgi -E >> /var/www/html/testWhatsNew.inc

I notice something different about the crontab and the normal cgi scripts and that is the shebang line. For the crontab file, it has #!bin/sh while my cgi script has #/usr/bin/perl

I have also tried to debug the script on command line with perl -d and it keeps saying uninitialized string at some lines and then the script ends with premature ending of script headers. But if I were to run the script using my browser, it produce the output with no errors.

Thanks,
Julian
Quote Reply
Re: [Paul] Question about cgi scripts and crontab In reply to
I hate to be saying this but I have been trying to figure out how to do that. I tried finding info from the web but did not find tutorials. I have a telnet program I can login but how then do I go and run crontab?
Julian
Quote Reply
Re: [vampy] Question about cgi scripts and crontab In reply to
You just need to execute the script.

Change to the directory where the script is eg...

cd cgi-bin/myscripts

Then execute the script:

perl -cw mycronscript.cgi
Quote Reply
Re: [Paul] Question about cgi scripts and crontab In reply to
This is what I got:
Name "main::default_index_file_name" used only once: possible typo at WhatsNew.c
gi line 70.
Name "MacPerl::Version" used only once: possible typo at WhatsNew.cgi line 49.
WhatsNew.cgi syntax OK
Julian
Quote Reply
Re: [vampy] Question about cgi scripts and crontab In reply to
Would you mind posting the code as an attachment?
Quote Reply
Re: [Paul] Question about cgi scripts and crontab In reply to
I uploaded the two files as attachments. Thanks.
Julian