├── LICENSE ├── README.md └── check.sh /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # server-status 2 | A little Bash script that checks if a server is UP or DOWN, and sends a mail with status update. 3 | 4 | ## Installation 5 | 6 | ### Dependencies 7 | 8 | `fping` to check if the server answser to the ping. Available on Debian, Arch and Gentoo repositories, or on [fping.org](http://fping.org/) 9 | 10 | `sendmail` or any mail sender. But you *must* make sure you can send mail with the `mail` command, or the script will be useless. 11 | 12 | `cron` to run the script automatically. 13 | 14 | ### Download the script 15 | 16 | ``` 17 | wget https://raw.githubusercontent.com/Angristan/server-status/master/check.sh 18 | chmod +x check.sh 19 | ``` 20 | 21 | 22 | ## Usage 23 | 24 | To run the script : `./check.sh` or `bash check.sh` 25 | 26 | To run the script automatically : 27 | 28 | `crontab -e` 29 | 30 | Add: 31 | 32 | `*/1 * * * * bash /path/to/check.sh` 33 | 34 | This will run the script every minute. 35 | 36 | 37 | ## License 38 | 39 | [The unlicense](https://github.com/Angristan/server-status/blob/master/LICENSE) : do whatever you want with the code. 40 | -------------------------------------------------------------------------------- /check.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | host="IP or domain" 3 | mail="the email adress that will receive mails" 4 | status=$(fping $host) 5 | status=$(echo $status | awk '{print $3}') 6 | if [ -e /tmp/status-$host.txt ] 7 | then 8 | laststatus=$(cat /tmp/status-$host.txt) 9 | if [[ $laststatus != $status ]] 10 | then 11 | echo $status > /tmp/status-$host.txt 12 | if [[ $status = "alive" ]] 13 | then 14 | echo "Hi, the server $host is back up." | mail -s "The server $host is UP !" $mail 15 | else 16 | echo "Hi, the server $host is down." | mail -s "he server $host is DOWN !" $mail 17 | fi 18 | fi 19 | else 20 | echo $status > /tmp/status-$host.txt 21 | fi 22 | --------------------------------------------------------------------------------