In CentOS 8, we created a shell script that records the results of the top command in a log file every 10 seconds.
#!/bin/sh
while true
do
top-b-n 1 | head-30>>/var/log/process-logger.log
sleep10
done
This script has been set to start the service on systemctl.The service configuration file is as follows:
[Unit]
Description= Process Logger
After=network.target
Service
Type = simple
ExecStart=/home/username/process-logger/main
WorkingDirectory=/home/username/process-logger
KillMode=process
Restart=always
Install
WantedBy=multi-user.target
As a result, the output process name of the top command is shortened and recorded in the log file.
For example, the original content was:
6 root 0-2000 I 0.00:00.00 kworker/0:0H-kblockd
8 root 0-2000 I 0.0000.00 mm_percpu_wq
If you start with systemctl, the process name is only halfway and the rest is the "+" symbol as follows:
6 root 0-2000 I 0.00:00.00 kworker/0+
8 root 0-2000 I 0.0000.00 mm_percpu+
There is no problem if you run the script manually on the terminal.
Running from systemctl seems to shorten it.
Why is this?
Would it be possible to make everything come out without shortening it?
Thank you for your cooperation.
linux centos shellscript systemd
I'm a questioner, but I solved it after receiving your comment.
-w512
to the top command. (Process names are no longer shortened.)Note: Without the use of this command-line option, output width is always based on the terminal at which top was invoked either or not in Batch mode.
Thank you @metropolis and @cubick.
581 PHP ssh2_scp_send fails to send files as intended
911 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
572 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
610 GDB gets version error when attempting to debug with the Presense SDK (IDE)
© 2024 OneMinuteCode. All rights reserved.