{"id":15959927,"url":"https://github.com/aleen42/checkserver","last_synced_at":"2026-05-03T02:37:11.008Z","repository":{"id":86875897,"uuid":"191341255","full_name":"aleen42/checkServer","owner":"aleen42","description":"🙏 a shell script to check whether the server is normal with its CPU or its MEMORY","archived":false,"fork":false,"pushed_at":"2019-06-11T10:20:00.000Z","size":4,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-09T21:12:59.400Z","etag":null,"topics":["linux","mutt","server","shell"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aleen42.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-06-11T09:42:51.000Z","updated_at":"2020-03-30T10:06:21.000Z","dependencies_parsed_at":"2023-05-29T16:00:11.898Z","dependency_job_id":null,"html_url":"https://github.com/aleen42/checkServer","commit_stats":{"total_commits":2,"total_committers":1,"mean_commits":2.0,"dds":0.0,"last_synced_commit":"850c63c42fa93ee2a36784ed0d73a8be05dc44bd"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aleen42%2FcheckServer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aleen42%2FcheckServer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aleen42%2FcheckServer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aleen42%2FcheckServer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aleen42","download_url":"https://codeload.github.com/aleen42/checkServer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247166156,"owners_count":20894652,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["linux","mutt","server","shell"],"created_at":"2024-10-07T15:01:21.351Z","updated_at":"2026-05-03T02:37:05.959Z","avatar_url":"https://github.com/aleen42.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"## checkServer\n\n[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/aleen42/checkServer/master/LICENSE) ![](https://img.shields.io/badge/Shell-4,685-89e051.svg)\n\n**checkServer** is a repository of a shell script snippet, which is mainly used for checking whether **CPU** or **MEMORY** of a server is normal. To enhance notification, the checked status will also be sent by emails.\n\n### 1. Mutt\n\nFor mailing people, **Mutt** is the client what I chose for sending emails under Linux with **POP3** protocol. the following tutorial has shown us how to install it under Ubuntu. For more detailed around installation on other Linux, like CentOS, please check [the official site](http://www.mutt.org/), or [a third-party document](http://www.wilf.cn/post/centos-mutt-msmtp-setup.html) searched before.\n\n#### 1.1 Installation via `apt-get`\n\nThe system name can be set with whatever name you like.\n\n```bash\napt-get install mutt\n```\n\n#### 1.2 Setup Configuration\n\nTouch a file named `.muttrc` in the `~` directory of root user and edit it with following snippet:\n\n```\n# .mutttrc file\n# sudo vi ~/.muttrc or /root/.muttrc\nset envelope_from=yes\n# the name of who sent the mail\nset from=xxx@xx.cn\n# the real name of who send the mail\nset realname=\"VoiceIn Website\"\nset use_from=yes\nset rfc2047_parameters=yes\nset charset=\"utf-8\"\n```\n\n#### 1.3 Send Emails via Terminals\n\n```bash\necho \"Email Contents\" | `which mutt` -s \"Title\" aleen42@vip.qq.com\n```\n\n### 2. Crontab\n\n**Crontab** helps us to set up a series of tasks, which can be run at a fixed time in Linux.\n\nThe following case set here means that `checkServer.sh` will be executed on 9 pm every day.\n\n```\n0 21 * * * sh ./checkServer.sh false\n```\n\n### 3. Scripts Information\n\nThere is also some helpful information for you to understand shell scripts.\n\n#### 3.1 Parameters\n\n- **MAX_mem**(%): the upper edge of physical memory warning.\n- **MAX_cpu**(%): the upper edge of physical cpu warning.\n- **DELAY**(s): update every ***$delay*** seconds.\n- **COUNT**: update ***$count*** times.\n- **NORMAL_CHECK**: to identify whether it is just a normal check each day.\n- **sh_command**: point out where `sh` command is.\n- **top_command**: point out where `top` command is.\n- **sar_command**: point out [where `sar` command is.\n- **iostat_command**: point out where `iostat` command is.\n- **free_command**: point out where `free` command is.\n\n#### 3.2 Methods\n\n- **checkServer**: generate system information and send emails to the specified email address.\n\n#### 3.3 Extracting Number\n\nTo extracting number from terminals, I have used `sed` (The following case has got the row 3 and column 3 of results run by `top` command):\n\n```bash\nfree | sed -n \"3, 1p\" | awk '{print int($3)}'\n```\n\n#### 3.4 Attention\n\n`sar` command need us to set `ENABLED` with `true` in the configuration file `/etc/default/sysstat`.\n\n```\n#\n# Default settings for /etc/init.d/sysstat, /etc/cron.d/sysstat\n# and /etc/cron.daily/sysstat files\n#\n\n# Should sadc collect system activity informations? Valid values\n# are \"true\" and \"false\". Please do not put other values, they\n# will be overwritten by debconf!\nENABLED=\"true\"\n\n# Additional options passed to sa1 by /etc/init.d/sysstat\n# and /etc/cron.d/sysstat\n# By default contains the `-S DISK' option responsible for\n# generating disk statisitcs.\nSA1_OPTIONS=\"-S DISK\"\n\n# Additional options passed to sa2 by /etc/cron.daily/sysstat.\nSA2_OPTIONS=\"\"\n```\n\nOtherwise, we may get the following error when running `sar` command:\n\n```\nroot@xxx:/home/checkServer# sar\nCannot open /var/log/sysstat/sa16: No such file or directory\nPlease check if data collecting is enabled in /etc/default/sysstat\n```\n\n### 4. How to install it on your server?\n\n1. clone it:\n\n    ```bash\n    git clone https://github.com/aleen42/checkServer.git\n    ```\n\n2. install mutt service as mentioned [above](#1-mutt) and check whether the following commands works:\n\n    ```bash\n    mutt\n    ```\n\n    ```bash\n    sar\n    ```\n\n3. run it manually:\n\n    ```bash\n    # options:\n    #\t- true: normal check\n    #\t- false: warning check\n    # email_addr: the email you want to receive infos of the server\n    sh ./checkServer.sh true aleen42@vip.qq.com\n    ```\n\n### :fuelpump: How to contribute\n\nHave an idea? Found a bug? See [how to contribute](https://aleen42.github.io/PersonalWiki/contribution.html).\n\n### :scroll: License\n\n[MIT](https://aleen42.github.io/PersonalWiki/MIT.html) © aleen42\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faleen42%2Fcheckserver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faleen42%2Fcheckserver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faleen42%2Fcheckserver/lists"}