I want to execute the top command from my bash script
the problem is that usually when I type the top command on the console , I exit by Ctrl+C.
but how to exit from top
when I run the top
command from my bash script ?
for example how to print the free memory from top in bash ?
I do the following but command not return value as I am explained
top | grep Mem: | awk '{print $6" "$7}'
when I run the top from the console:
top
top - 17:55:24 up 20 days, 8:05, 3 users, load average: 0.08, 0.08, 0.04
Tasks: 93 total, 1 running, 92 sleeping, 0 stopped, 0 zombie
Cpu(s): 1.0%us, 3.2%sy, 0.0%ni, 95.2%id, 0.5%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 2075516k total, 1731156k used, 344360k free, 373308k buffers
Swap: 4192924k total, 76k used, 4192848k free, 1130448k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1 root 15 0 2072 656 568 S 0.0 0.0 0:01.36 init
.
.
.
top -n1
will run just one iteration.vmstat
command or looking directly into/proc/meminfo
. What exactly do you want to achieve?top -bn1
will be helpful.