Я хочу написать скрипт, который будет показывать загрузку процессора для одного сервиса. ниже скрипт и вывод для того же. Любезно помочь.
Сценарий:
yourpid=$(service tomcat_SP status | cut -d':' -f2) #this will store PID
newpid="${yourpid// /}" # this will remove extra space from PID
final=$(ps -p $newpid -o %cpu=) # this is final command to get cpu utilization
$final # calling command to give output
Выход скрипта:
[root@PHYAPP01 tmp]# sh -x temp.sh
++ service tomcat_SP status
++ cut -d: -f2
+ yourpid=' 1823'
+ newpid='1823'
+ ps -p 1823 -o %cpu=
ERROR: Process ID list syntax error.
********* simple selection ********* ********* selection by list *********
-A all processes -C by command name
-N negate selection -G by real group ID (supports names)
-a all w/ tty except session leaders -U by real user ID (supports names)
-d all except session leaders -g by session OR by effective group
name
-e all processes -p by process ID