Arguments in Cron Jobs - Unix

This is a discussion on Arguments in Cron Jobs - Unix ; Hello and happy new year to everyone. I was trying to run a simple cron job on my a certain php script I have, it runs smoothly. * * * * * .......... /import.php But I want to add a ...

+ Reply to Thread
Results 1 to 8 of 8

Thread: Arguments in Cron Jobs

  1. Arguments in Cron Jobs

    Hello and happy new year to everyone.

    I was trying to run a simple cron job on my a certain php script I
    have, it runs smoothly.

    * * * * * .......... /import.php

    But I want to add a "?", "&", "=" and I don't know what other
    arguments, the script is done to accept some overrides like so:

    * * * * * .......... /import.php?module=import_do_import&override=12

    But the cron job like this is not ran at all, and no report whatsoever
    is even sent to my mailbox.

    Can someone point me towards a solution. Thanks is advance.


  2. Re: Arguments in Cron Jobs

    GoodMan writes:

    > * * * * * .......... /import.php?module=import_do_import&override=12


    It is a quoting problem. I strongly suggest you put these kind of things
    in a shell script, to make it easier to debug, and put quotes around the
    arguments. Either use ' or ". This is described in any shell script
    programming resource.

    --
    Thorbjørn Ravn Andersen

  3. Re: Arguments in Cron Jobs

    In article
    <4505b764-56f0-489f-a2b3-c6e388e78577@v32g2000hsa.googlegroups.com>,
    GoodMan wrote:

    > Hello and happy new year to everyone.
    >
    > I was trying to run a simple cron job on my a certain php script I
    > have, it runs smoothly.
    >
    > * * * * * .......... /import.php
    >
    > But I want to add a "?", "&", "=" and I don't know what other
    > arguments, the script is done to accept some overrides like so:
    >
    > * * * * * .......... /import.php?module=import_do_import&override=12
    >
    > But the cron job like this is not ran at all, and no report whatsoever
    > is even sent to my mailbox.
    >
    > Can someone point me towards a solution. Thanks is advance.


    It looks like you're trying to use URL syntax. Cron jobs are processed
    by the shell, not an HTTP server. Arguments are separated from the
    command by whitespace, not "?". Also, "+" characters in the URL
    argument string are converted to spaces when executing the command.

    I suggest you look up the specification of CGI, the Common Gateway
    Interface. It describes all the transformations that take place when a
    URL invokes a program.

    --
    Barry Margolin, barmar@alum.mit.edu
    Arlington, MA
    *** PLEASE post questions in newsgroups, not directly to me ***
    *** PLEASE don't copy me on replies, I'll read them in the group ***

  4. Re: Arguments in Cron Jobs

    GoodMan wrote:
    > Hello and happy new year to everyone.
    >
    > I was trying to run a simple cron job on my a certain php script I
    > have, it runs smoothly.
    >
    > * * * * * .......... /import.php
    >
    > But I want to add a "?", "&", "=" and I don't know what other
    > arguments, the script is done to accept some overrides like so:
    >
    > * * * * * .......... /import.php?module=import_do_import&override=12
    >
    > But the cron job like this is not ran at all, and no report whatsoever
    > is even sent to my mailbox.
    >
    > Can someone point me towards a solution. Thanks is advance.


    You need to invoke it as a URL, something like:
    * * * * * .......... wget 'http://localhost/import.php?parameters_go_here'

    Good luck,

    Charles


  5. Re: Arguments in Cron Jobs

    On Thu, 03 Jan 2008 00:30:42 -0000, Charles Polisher wrote:

    > You need to invoke it as a URL, something like:
    > * * * * * .......... wget 'http://localhost/import.php?parameters_go_here'


    Ugh. I'd rather call a script that handles all the logic than try to
    wedge it into a crontab entry. Right tool for the job and all that.


  6. Re: Arguments in Cron Jobs

    GoodMan wrote:
    >
    > I was trying to run a simple cron job on my a certain php script I
    > have, it runs smoothly.
    >
    > * * * * * .......... /import.php
    >
    > But I want to add a "?", "&", "=" and I don't know what other
    > arguments, the script is done to accept some overrides like so:
    >
    > * * * * * .......... /import.php?module=import_do_import&override=12
    >
    > But the cron job like this is not ran at all, and no report whatsoever
    > is even sent to my mailbox.


    Just to include those characters you need to escape them with
    backslash but it is very unlikely it will work. Chances are it will
    result in file-not-found error.

    > Can someone point me towards a solution.


    man getopt

    for how to pass arguments to scripts. You want to write a script
    that takes switches on its command line then generates the web
    type of arguments.

  7. Re: Arguments in Cron Jobs

    Thanks for all the help! I ended writing a small script and executing
    it. In my opinion it's a lot better than invoking a URL, so mainly I
    did as Thorbjoern Ravn Andersen and Doug Freyburger wrote. So if
    anyone encounters the same problem, I suggest using the same method.

  8. Re: Arguments in Cron Jobs

    GoodMan wrote:
    >
    > Thanks for all the help! I ended writing a small script and executing
    > it. In my opinion it's a lot better than invoking a URL, so mainly I
    > did as Thorbjoern Ravn Andersen and Doug Freyburger wrote. So if
    > anyone encounters the same problem, I suggest using the same method.


    I read in another newsgroup that for cron jobs, things like .profile may
    not get executed in some UN*Xes with the result that the process
    environment is different under cron than it would be in an "at" job or
    when a script is run interactively.

    A poster in that group (comp.unix.aix) suggested having a "template
    script" that you submit to cron, and have that template script invoke
    such things as .profile or otherwise provide any environment setup that
    might otherwise be missing under cron before invoking the script you
    want to execute, whose name is passed to the template script as a
    command line argument in the crontab entry.

    For what little it may be worth...

    David J Dachtera
    DJE Systems

+ Reply to Thread