Quantcast
Channel: Active questions tagged 22.04 - Ask Ubuntu
Viewing all articles
Browse latest Browse all 4462

Make shell script output correctly [duplicate]

$
0
0

I am trying to run a shell script to get the PID details and sort them based on memory, while executing in the server. I am getting correct output like this:

[inda@jump-server ~]$ ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head    PID    PPID CMD                         %MEM %CPU   1181       1 /usr/libexec/mysqld --based  3.0  6.7 740025  740020 /usr/sbin/rsync              1.7  1.5   7051       1 /usr/libexec/packagekitd     1.6  0.0   7234    2398 /usr/sbin/jump_server: hi  1.4  0.0   7232    2398 /usr/sbin/jump_server: hi  1.4  0.0   7235    2398 /usr/sbin/local_server: hi  1.4  0.0   3357    2818 /usr/bin/gnome-shell         1.4  0.0   7237    2398 /usr/sbin/local_server: hi  1.4  0.0   7238    2398 /usr/sbin/local_server: es  1.0  0.0

but while running the script I am getting the output like below:

[india@jump-server ~]$ for i in `cat cpu.txt` ; do host=`ssh -q ${i} "ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem |  head | xargs"`; echo $host; donePID PPID CMD %MEM %CPU 4317 1 /usr/libexec/packagekitd 33.9 0.0 6641 6572 /usr/bin/gnome-shell 4.1 0.0 6982 6572 /usr/bin/gnome-software --g 2.4 0.0 6712 1 /usr/libexec/ibus-x11 --kil 0.7 0.0 6682 6641 /usr/bin/Xwayland :0 -rootl 0.7 0.0 6800 1 /usr/libexec/sssd/sssd_kcm 0.6 0.0 1029 1 /usr/libexec/platform-pytho 0.5 0.0 6777 6523 /usr/libexec/goa-daemon 0.5 0.0 706 1 /usr/lib/systemd/systemd-jo 0.5 0.0

I need to get the shell script output like first one, please suggest.


Viewing all articles
Browse latest Browse all 4462

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>