Skip to content
Advertisement

Os.system doesn’t push message in cron alert to cronitor?

I am running a python script using a cron job. When the script runs, it either alerts that it completed or failed. It is supposed to send a message to cronitor along with the completion ping. An example of the link is below:

JavaScript

When I just put the link into the search bar and hit Enter, the message shows up in cronitor. However, when I try to get the message to print when running the link through the script it doesn’t work. Cronitor gets the ping that it completed successfully but no message shows up:

JavaScript

I tried removing ‘–silent’ but that didn’t make a difference. Any ideas on how to fix this? Thanks

Advertisement

Answer

Your command contains an unescaped &, which the shell used by os.system parses as a command terminator that runs curl the the background. You need to escape it, e.g.

JavaScript

but even better would be to stop using os.system and use subprocess.run instead.

JavaScript

which bypasses the shell altogether.

Best, use a library like requests to send the request from Python, rather than forking a new process.

JavaScript

(In all cases, does the API really require single quotes around Success?)

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement