Skip to main content
  1. Posts/

Sending Exit Code Over Curl

·272 words·2 mins·
linux administration notification monitoring
May Meow
Author
May Meow
MayMeow is a developer and cybersecurity enthusiast with a passion for cryptography, DevSecOps, and open-source contributions. They enjoy creating tools that strengthen digital security, blending creativity and technology to innovate in fields like PHP and .NET. Always exploring new frontiers in tech, MayMeow is dedicated to safeguarding the digital landscape through their work.

Hi everyone! I created few scripts to backum my server’s data to my S3 storage and wanted to be notified when backup fails. Until now I used Zabbix with zabix-sender but I found maybe better server monitoring for me: Netdata. So when I dont use zabbix anymore I needed another solution and found one. You can post status code with curl to any api (or you can create easy script for example in the GO to send data to the api, this is just easier and faster solution for me now.)

How to get exit code?

#!/bin/bash

# ... your code

#read exit code and add it to variable
STATUS_CODE=$?

# and send it
curl -i --data state=${STATUS_CODE} https://your-url-to-server

That’s it, easy no? This is how you can post status/exit code to your api, you can add more data or header for authentication. You can send an email for example if status change from default or if it is changed from last one or anything you want.

I wanted to be notified over SMS message so i created Cake-Notify. It is using Twilio service to send message to provided phone number. This app is in early stage of development but it is usable. I plannig to add more services to use for sending notifications, but for now it knows only sending SMS over Twilio.

This is how you can send exit code to my api

curl -i --data state=1 -H "__token__:<change-to-your-token>" https://<change-to-server-address>/api/v1/applications/create-log/<application-id>.json

… and this is all. You are free to check it yourself, or contribute if you want, i will be glad.

Thank you for reading, Have a nice day. 👋

Reply by Email

Related

Docker Volume on NFS?
·367 words·2 mins
docker linux WIP
How to Install and Configure Samba
·432 words·3 mins
Administration notes guide wiki file sharing linux windows
Xfce Terminal Color Emoji
·133 words·1 min
tutorial linux xfce 100DaysToOffload