0

This is my curl script

#!/bin/bash

PING_STATUS="$(netcat -vz mc.bella.wtf 25565 2>&1)"
curl -H "Content-Type: application/json" -X POST -d '{"embeds": [{"title": "Server Status:","color": 16027903,"description": "'"$PING_STATUS"'"}]}' "$WEBHOOK"

This is what I get when I run my crontab:

mc@ubuntu:~$ crontab -l
* * * * * /home/mc/server/ping >/tmp/mycommand.log 2>&1
mc@ubuntu:~$ cat /tmp/mycommand.log 
curl: (3) <url> malformed

Why is my url malformed when it works fine when running the script by itself?

5HT2
  • 3
  • 1

1 Answers1

2

The reason is that your env variable WEBHOOK is not recognized.

Solution 1

In your /etc/environment add:

WEBHOOK="http://example.org"

and in your crontab:

*/1 * * * * source /etc/environment; /home/mc/server/ping >/tmp/mycommand.log 2>&1

Solution 2

Specify WEBHOOK in your curl script:

#!/bin/bash
WEBHOOK="http://example.org"
PING_STATUS="$(netcat -vz mc.bella.wtf 25565 2>&1)"
...

Solution 3

curl script:

#!/bin/bash
source $HOME/.profile
PING_STATUS="$(netcat -vz mc.bella.wtf 25565 2>&1)"
...

$HOME/.profile

WEBHOOK="http://example.org"
lukascode
  • 46
  • 2