This simple script uses cURL
to check if a web application is running on a server. If the service is not running, it utilizes the telegram bot API for sending a message to inform the operator of the server.
- have docker installed (works on wsl2 / docker for desktop on windows as well)
- checkout this repo
- read the readme and edit the serverUp.sh accordingly
Go to the BotFather bot-account and create a bot by writing /newbot
. Then, copy the token.
Send a message to you newly created bot (you can find the link to your bot in the success message sent by BotFather).
Visit https://api.telegram.org/bot{token}/getUpdates
to get your chat id: result => 0 => message => chat => id
Please note that the token must be directly behind bot
in the URL. If your token starts with AAAA
the URL looks like /botAAAA
and so on.
Fill in the four variables server
, port
(SSL is on 443 by default), botToken
and chatId
. . Wheras the serverList is comma seperated list.
Execute chmod +x serverUp.sh
to make the script executable.
To test the script, enter an unused port and execute it via ./serverUp.sh
. Don't forget to change the port number after testing.
A simple docker container that runs a cron invoking a shell script.
Copy the repository and build from the Dockerimage:
On Linux run:
$ sudo docker build --rm -t docker-cron .
Run the docker container in the background (docker returns the id of the container):
$ sudo docker run --restart=always -t -i -d docker-cron
b149b5e7306dba492558c7024809f13cfbb616cccd0f4020db61bf715f4db836
To check if it is running properly, connect to the container using the id and view the logfile. (You may have to wait a few minutes)
$ sudo docker exec -i -t b149b5e7306dba492558c7024809f13cfbb616cccd0f4020db61bf715f4db836 /bin/bash
root@b149b5e7306d:/# cat /var/log/serverUp.log
INFO: google.com:443 up! Mon, 15. November 2021, 10:20:01
INFO: yahoo.com:443 up! Mon, 15. November 2021, 10:20:01
INFO: Mon, 15. November 2021, 10:20:01: executed script
The cron job is running. Now let's modify the interval and the actual job executed!
##Crontab for termux on Android:
pkg install cronie termux-services
restart termux
sv-enable crond
crontab -e
it will open default text editor , write your job in it and save it,
For example :
`*/5 * * * * /path/to/your/script/script.sh`
Every time you start/restart Termux, you need to start the cron service by running the command:
sv up crond
Check for running crond
pidof crond
To change the interval the cron job is runned, just simply edit the crontab file. In default, the job is runned every 5 minutes.
You don't need a user because it runs with your local Termux user. (To find your user type whoami
)
To find your working directoy where the script should be stored somwhere type pwd
*/5 * * * * /path/to/the/script/serverUp.sh
To change the actual job performed just change the content of the serverUp.sh file. In default, the script writes the date into a file located in ${pwd}/serverUp.log
To check the working directory type pwd
echo "$(date): executed script" >> ${pwd}/serverUp.log 2>&1
RundesBalli - Server online-status check and reporting to telegram
Chris Heyer - docker-cron