78

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.

SamB
  • 9,039
  • 5
  • 49
  • 56
Yeti
  • 5,628
  • 9
  • 45
  • 71

3 Answers3

144

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'
SamB
  • 9,039
  • 5
  • 49
  • 56
  • 26
    Windows user running curl binaries should use double-quotes instead of single quotes to get multiple query parameters command working. – vivek.m Jan 06 '12 at 15:49
  • 4
    This works for me - many minutes wasted not understanding why my second parameter wasn't working. – James Wilson Feb 25 '19 at 14:19
  • Welp, I feel stupid now. I was also forgetting my quotes. Thanks man. – Rezkin Oct 07 '19 at 22:17
20

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
MMKarami
  • 1,144
  • 11
  • 14
5

Try a POST Request

curl -d "days=1&month=1" www.example.com/cronjob.php
streetparade
  • 32,000
  • 37
  • 101
  • 123
  • 1
    Any particular reason you suggest a POST? – SamB Jun 05 '10 at 20:28
  • 2
    No harm in mentioning it, it's good to know (Although I'll go with GET) – Yeti Jun 05 '10 at 20:30
  • 1
    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 :-) – streetparade Jun 05 '10 at 20:34
  • You can not know if it will work - it depends on the script if it looks POST variables or only GET variables. – Kristijan Jul 02 '13 at 11:15
  • 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 – roberthuttinger Apr 23 '18 at 13:41