Execute the system command and write the shell script that writes the output to the log file,

Source: Internet
Author: User

Execute the system command and write the shell script that writes the output to the log file,

This is probably the requirement. Run the usysfault command on the aix system to retrieve the fault light information. However, it seems that only the root user can execute this command. If other users execute this command, an error is reported. I tried every means to grant permissions and ended up failing. So I thought of writing shell scripts to write the results to the log file using the root user, and then we could read the file to get the data, we don't need to execute any commands that we don't want to execute.

The shell script is as follows:

! /Usr/bashwhile true # execute do {date + "% Y-% m-% d % H: % M: % S "# Get the current date and time uname # command to be executed}> patrol. log # output to log sleep 5 # execution cycle is 5 seconds done

This script stores the host system type and time in the log file. logs are stored in overwrite mode, not append mode. There is always only one record.
Run the following command:
Sh patrol. sh &
To run the script in the background to retrieve the number of times.

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.