| | |
inserting and summing several values into variable
![]() |
•
•
Join Date: Dec 2007
Posts: 17
Reputation:
Solved Threads: 0
hi everyone,
im searching for a way to insert several values i get from a command [top |grep root |awk '{print $10}'] to a variable, so that the variable will contain the sum of all values returned.
(trying to calculate MEM usage by all root processes )
can anyone help?
p.s - why when i run that command i need to press q to get the result? and when i type:
ps -ef |grep root |awk '{print $10}'
it returns automatically?
thanx a lot !!
yair
)
im searching for a way to insert several values i get from a command [top |grep root |awk '{print $10}'] to a variable, so that the variable will contain the sum of all values returned.
(trying to calculate MEM usage by all root processes )
can anyone help?
p.s - why when i run that command i need to press q to get the result? and when i type:
ps -ef |grep root |awk '{print $10}'
it returns automatically?
thanx a lot !!
yair
) You're already running AWK, make it do the additions
Yes, you need that newline in the command
> p.s - why when i run that command i need to press q to get the result?
Because 'top' is an interactive program?
You'd have to read the manual to see if there's a "do it once and quit" option.
But I'd use 'ps' if it works.
Shell Scripting Syntax (Toggle Plain Text)
top | grep root | awk '{ sum += $10 } END {print sum}'
> p.s - why when i run that command i need to press q to get the result?
Because 'top' is an interactive program?
You'd have to read the manual to see if there's a "do it once and quit" option.
But I'd use 'ps' if it works.
•
•
Join Date: Apr 2006
Posts: 148
Reputation:
Solved Threads: 40
better still, no need grep
Shell Scripting Syntax (Toggle Plain Text)
top | awk '/root/{ sum += $10 }END {print sum}'
![]() |
Other Threads in the Shell Scripting Forum
- Previous Thread: How to format this date UNDER FreeBSD?
- Next Thread: New to Bash Scripting - Service Restart
| Thread Tools | Search this Thread |






