Run the system command and write the shell script that writes the output to the specified log file (2 ),

Source: Internet
Author: User

Run the system command and write the shell script that writes the output to the specified log file (2 ),

The previous article was a simple script that can be executed and written into logs. However, if it is placed in the production environment, it seems too rough, so further optimization is required:

#! /Bin/basffe [-d "/opt/bmc"]; then if [-f "/opt/bmc/usysfault. log "]; then {date +" % Y-% m-% d % H: % M: % S "/usr/lpp/diagnostics/bin/usysfault # absolute path of the command to be executed}>/opt/bmc/usysfault. log # the absolute path of the log file to be stored, else touch/opt/bmc/usysfault. log chmod 755/opt/bmc/usysfault. log {date + "% Y-% m-% d % H: % M: % S "/usr/lpp/diagnostics/bin/usysfault}>/opt/bmc/usysfault. log fielse if [-f "/tmp/usysfault. log "]; then {date +" % Y-% m-% d % H: % M: % S "/usr/lpp/diagnostics/bin/usysfault}>/tmp/usysfault. log else touch/tmp/usysfault. log chmod 755/tmp/usysfault. log {date + "% Y-% m-% d % H: % M: % S"/usr/lpp/diagnostics/bin/usysfault}>/tmp/usysfault. log fifi
Note:

Note:

Finally, this is the script for executing words. If you want to execute it cyclically, add the while true written in the previous article. However, I use the unix-like scheduled task manager crontab to add scheduled tasks, allowing the system to execute scripts based on the specified scheduled time.

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.