0

I am currently trying to use Plink to run a few commands on a linux server to monitor a couple of things on it such as the disk space, memory, cpu usage.
I have the commands that I want to use but I want to format the output that I get to something a little friendlier to read.
This is the commands I am using inside my batch file.

 FOR /F "" %%G IN (C:\Users\username\Desktop\ip_list.txt) DO "C:\Program Files\PuTTY\plink.exe" -ssh -batch username@%%G -pw password "hostname; df | fgrep '/dev/'; free -h; top -bn2 | grep 'Cpu(s)';"

and here is the output that i get
enter image description here
Basically, I would like to just add some lines in between the individual command outputs to make this a tiny bit easier to read. Is this possible without writing the output to a text file?
Thank you

3

This can be achieved by adding echo "" in the middle of the commands where the space is required.

Here are some example.

  1. Adding new line in the middle.

Example:

 df | fgrep '/dev/'; echo ""; free -h

output

 tmpfs                                    16334344       55772  16278572   1% /dev/shm

              total        used        free      shared  buff/cache   available
Mem:            31G        4.0G         21G        346M        6.0G         26G
Swap:           15G        2.3M         15G
  1. Adding detail of the command.

Recommended

Example:

echo "==================" ; echo "This is output of df"; echo "==================" ;df | grep '/dev/shm' ; echo ""; echo "==================" ; echo "This is output of Free"; echo "==================";free -h

Output:

==================
This is output of df
==================
tmpfs                                    16334344       55772  16278572   1% /dev/shm

==================
This is output of Free
==================
              total        used        free      shared  buff/cache   available
Mem:            31G        4.0G         21G        359M        6.0G         26G
Swap:           15G        2.3M         15G
  • this is actually perfect. Thank you so much! – hescobar Mar 19 at 15:19
  • Glad to be helpful. Learning is the key! – Vivek Kanadiya Mar 19 at 15:21
  • The quoted empty string argument is not needed, a simple echo; will do. – TooTea Mar 19 at 15:41
  • 1
    yea i actually ended up having to use && instead of ; in my script because it kept taking the ; as part of the echo instead of ending the command. Still great idea to use echo that i hadn't thought of though – hescobar Mar 19 at 16:16
1
    Instead of displaying whole df command output i Wrote below script to find only if disk space crosses threshold (here i assuming threshold as 90%) and also included current memory usage percentage details

    Here is the code



      df -Ph| awk 'NR>1'| sed "s/%//g"| awk '($(NF-1) >90){print "Disk space utilized is" "  "$(NF-1)"%" " for partition" " "$NF}'|sed '1i Below are partition details of hosts where disk utilized crossed 90%\n'| sed '$s/.*/&\n=============================================================================/g';free  | awk '/Mem/{print $0}'| awk '{print $3/$2*100}'| sed '1i below are current memory usage percentage of host'



Sample output
Below are partition details of hosts where disk utilized crossed 90%

Disk space utilized is  100% for partition /snap/gnome-system-monitor/51
Disk space utilized is  100% for partition /snap/gtk-common-themes/1122
Disk space utilized is  100% for partition /snap/core/6531
Disk space utilized is  100% for partition /snap/gnome-calculator/260
Disk space utilized is  100% for partition /snap/gnome-logs/37
Disk space utilized is  100% for partition /snap/gtk-common-themes/818
=============================================================================
below are current memory usage percentage of host
39.2084

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.