#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    73
    Rep Power
    15
    Hello guys,

    Anybody knows how to run cron job to call a cgi script, but what I need is passing in parameters
    Example: /home/path/myscript.pl?x=123&y=abc
    So how would I set up the cron so that it will execute that script WITH those params

    One more question: to call the above script (with params) under unix (or linux), how would you put the params?

    Thanks a lot,

    ------------------
    http://new.123finder.com/ - Helps you find cool domains for FREE & Registers it for only $14.95/yr
    http://www.guideclick.com/ - Qualified webmaster resources (affiliate programs, web design, tips)

    ------
    Son
  2. #2
  3. SwollenMember
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    the master control
    Posts
    264
    Rep Power
    15
    crontab -e: edits a new crontab
    crontab -r: removes a crontab
    crontab -l: lists the crontab

    then just fill in the paramaters for when you want it to run:

    min hrs day mos dow script to run

    30 15 * * mon /home/path/myscript.pl?x=123&y=abc

    would run a crontab every monday at 3:30PM.

    use man crontab for more help

    [This message has been edited by tron (edited August 08, 2000).]
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2000
    Location
    Indiana
    Posts
    614
    Rep Power
    16
    30 15 * * mon /home/path/myscript.pl?x=123&y=abc
    isn't going to work. You'll get a perl error (or the person owning the crontab will get an e-mail with the error) saying that it can't find/run "/home/path/myscript.pl?x=123&y=abc".

    You need to pass it on using the @ARGV array:

    30 15 * * mon /home/path/myscript.pl "123" "abc"

    then in the script say:
    $x=$ARGV[0];
    $y=$ARGV[1];

    That will work.

    [This message has been edited by JonLed (edited August 08, 2000).]
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2000
    Location
    Indiana
    Posts
    614
    Rep Power
    16
    Heh, was fixing that as you where saying it.

    [This message has been edited by JonLed (edited August 08, 2000).]
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    73
    Rep Power
    15
    Thank guys!

    So calling the script from the command prompt of unix I would do the same thing?
    Is there a solution that I don't need to modify the code?

    ------------------
    http://new.123finder.com/ - Helps you find cool domains for FREE & Registers it for only $14.95/yr
    http://www.guideclick.com/ - Qualified webmaster resources (affiliate programs, web design, tips)

    ------
    Son
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2000
    Location
    Indiana
    Posts
    614
    Rep Power
    16
    You'll need to modify the code if you plan on running it from the command line.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    81
    Rep Power
    15
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by JonLed:
    You'll need to modify the code if you plan on running it from the command line.[/quote]

    Not entirely true if you use CGI.pm to parse the parameters -- just specify your command line arguments as name=value pairs, e.g.

    /home/path/myscript.pl x=123 y=abc
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2000
    Location
    Indiana
    Posts
    614
    Rep Power
    16
    Well I never use CGI.pm, so it's not possible for me .
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    73
    Rep Power
    15
    Can you tell me more specific how to parse in CGI.pm? Thanks

    ------------------
    http://new.123finder.com/ - Helps you find cool domains for FREE & Registers it for only $14.95/yr
    http://www.guideclick.com/ - Qualified webmaster resources (affiliate programs, web design, tips)

    ------
    Son
  18. #10
  19. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Charleston, SC, USA
    Posts
    10
    Rep Power
    0
    The following code assumes you have a page that has an <input> named "FileName".
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    #!/usr/local/bin/perl -w
    use CGI;
    $q = new CGI;
    print $q->header;
    print $q->start_html;

    # get filename from submitted form
    my $filename = $q->param('FILENAME');

    # if other parameters are available
    # from the form.....
    my $otherParm = $q->para('otherParm');
    # and so on for any others.

    # you might open file or showError and die.
    open (FILE,$filename) or &showError("can not open $filename");
    @FILE=<FILE>;
    close(FILE);

    print '<pre>'."@FILE".'</pre>';
    print '</P>',$q->end_html;


    sub showError
    {
    my $error = @_;
    print "ERROR - $error<BR>n";
    print '</P>',$q->end_html;
    exit;
    }
    [/code]
  20. #11
  21. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Charleston, SC, USA
    Posts
    10
    Rep Power
    0
    oops....that should have been "a parameter named 'FILENAME'", not 'FileName'.

IMN logo majestic logo threadwatch logo seochat tools logo