Typical application of shell scripts in System Management (1)

Source: Internet
Author: User
Article Title: typical application of shell scripts in System Management (1 ). Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

Server System Status Monitoring

-------------------

Case Description:

To continuously observe the running status of the server on a daily basis, you need to periodically track and record the server's cpu load, memory, swap space, disk usage, and other information in conjunction with shell scripts and scheduled tasks.

Implementation Method: use shell scripts

Specific design ideas:

1. Write the script monitor. sh.

#! /Bin/bash

# This is the second script!

Day_time = 'date + "% F % R "'

Cpu_test = 'uptime'

Mem_test = 'free-m | grep "mem" | awk '{print $2 }''

Swap_test = 'free-m | grep "mem" | awk '{print $4 }''

Disk_test = 'df-hT'

User_test = 'last-n 10'

Echo "now is $ day_time"

Echo "% cpu is $ cpu_test"

Echo "Numbet of Mem size (MB) is $ mem_test"

Echo "Number of swap size (MB) is $ swap_test"

Echo "the disk shiyong qingkuang is $ disk_test"

Echo "the users login qingkuang is $ user_test"

2. Set a cron task

*/15 * bash/monitor. sh

55 23 *** tar cxf/var/log/runrec/var/log/running. today & -- remove-files

Note: The cron scheduled task is set to execute this script from time to monitor the system status and log in to facilitate better system management!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.