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.