81

I'm running two cron jobs:

This one executes without a problem:

curl -sS http://example.com/cronjob.php?days=1 

But this doesn't run at all:

curl -sS http://example.com/cronjob.php?days=1&month=1 

Is this because of the ampersand (&)? If yes, how to pass multiple parameters?

Using argv is not an option.

4 Answers 4

148

You'll notice that this doesn't exactly work in your shell, either.

What you need to do is put single quotes around the URL, like so:

curl -sS 'http://example.com/cronjob.php?days=1&month=1' 
Sign up to request clarification or add additional context in comments.

3 Comments

Windows user running curl binaries should use double-quotes instead of single quotes to get multiple query parameters command working.
This works for me - many minutes wasted not understanding why my second parameter wasn't working.
Welp, I feel stupid now. I was also forgetting my quotes. Thanks man.
23

As an alternative way, you can use \ before & which is a special character for shell. Generally, & is one of special characters that are meaningful for shell.

So, using a backslash [beside Quoting solution] can be a good solution to this problem. more

In your example you can simply apply this command:

curl -sS http://example.com/cronjob.php?days=1\&month=1 

2 Comments

➕1 for actually explaining the issue being & behaving as a special character [which as i looked it up on your link indicates 'background job' 🤷]
this was the exact reason that my curl didn't work. thanks!
7

Try a POST Request

curl -d "days=1&month=1" www.example.com/cronjob.php 

5 Comments

Any particular reason you suggest a POST?
No harm in mentioning it, it's good to know (Although I'll go with GET)
well it just up you you also could do it with a GET request. This is just how i would do it. However this would work, and that is the point :-)
You can not know if it will work - it depends on the script if it looks POST variables or only GET variables.
on the receiving end it wont matter ($_REQUEST) but using an implicit string as URL not sure how post would work. Using GET or REQUEST will retrieve the variables
0

Here's another way to do a POST request with multiple parameters:

curl www.example.com/cronjob.php -d name=John -d age=30 

source: https://spring.io/guides/gs/accessing-data-mysql

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.