3

I created a cron job to trigger a url at set times, which in turn starts a product import script. But for some reason part of the trigger url with parameters is stripped away.

I set the cron job like this:

/usr/bin/wget -O /dev/null http://domain.nl/wp-cron.php?import_key=XXXXXXXXXX&import_id=3&action=processing

But it only runs http://domain.nl/wp-cron.php?import_key=XXXXXXXXXX. Where is the last part that actually tells the script what to do?

Who knows why it behaves like this and how to get it to work?

1
  • put the url in single quotes.
    – fuero
    Feb 13, 2015 at 21:58

2 Answers 2

4

The ampersand character (&) actually means something in Linux (well, in a Bourne-compatible shell). It means: run the command as a background task.

Because of that, you are actually telling cron to run /usr/bin/wget -O /dev/null http://domain.nl/wp-cron.php?import_key=XXXXXXXXXX in the background, and then to do action=processing. And that's what cron is doing for you - what you told it to do.

To get around this, you need to escape the & character, so that it gets processed as part of the url, rather than being interpreted as a control character.

The easiest solution is to encapsulate the url in quotes.

1
  • What about a space in a query parameter? For example, date=2021-10-07 03:00:00, does it work if I wrap entire url in quotes?
    – Arvind K.
    Oct 7, 2021 at 10:58
3

In addition to the ampersand that was already mentioned, you also have to be careful with a % character in a cron entry. % in a cron entry will be interpreted as a line break and has to be escaped with a backslash(\%). Make sure the import_key that you censored doesn't have such a character. Also, URLs often have % in them to escape certain characters like space (), =, etc.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .