Discussion:
Arguments in Cron Jobs
(too old to reply)
GoodMan
2008-01-01 08:07:39 UTC
Permalink
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.
Thorbjoern Ravn Andersen
2008-01-01 10:19:25 UTC
Permalink
Post by GoodMan
* * * * * .......... /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
Barry Margolin
2008-01-01 17:12:38 UTC
Permalink
In article
Post by GoodMan
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
* * * * * .......... /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, ***@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 ***
Charles Polisher
2008-01-03 00:30:42 UTC
Permalink
Post by GoodMan
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
* * * * * .......... /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
Dave Hinz
2008-01-03 02:02:04 UTC
Permalink
Post by Charles Polisher
* * * * * .......... 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.
Doug Freyburger
2008-01-07 19:54:36 UTC
Permalink
Post by GoodMan
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
* * * * * .......... /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.
Post by GoodMan
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.
GoodMan
2008-01-12 08:15:44 UTC
Permalink
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.
David J Dachtera
2008-01-13 02:46:05 UTC
Permalink
Post by GoodMan
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

Loading...