Shell script that executes system commands and writes output to a log file

Source: Internet
Author: User
Tags log log

Presumably the requirement is that the AIX system Usysfault command takes the fault light information, but this command appears to be performed only by the root user, and the other user executes the error. All sorts of ways to empower all fail, so think of writing a shell script with the root user to execute the results are written to the log file, and then we read the file to fetch the data, we do not have to execute the AIX or not let us execute the command.

The shell script is as follows:

! /usr/bashwhile true   #循环执行do    {        date + "%y-%m-%d%h:%m:%s"     #取当前日期和时间        uname        #要执行的命令    } > Patrol.log       #输出到日志sleep 5      #执行周期是5秒done

This script is to take the host system type and time into the log log file, the log is overwritten storage is not appended, always only one record.
With the command:
SH patrol.sh &
Run the script in the background to always loop through the number.

Shell script that executes system commands and writes output to a log file

Related Article

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.