1
  • From one VM-X i want to log onto different VM-Y, get output dh -H command from VM-Y

  • and find out which disk usage is above say 50% and sendemail

from VM-X

echo "df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 \" \" \$1 }'" | sshpass -p 'password' ssh user@VM-Y-IpAddress 

and I am able to get output

Pseudo-terminal will not be allocated because stdin is not a terminal. Welcome to Ubuntu 16.04 LTS (GNU/Linux 4.4.0-62-generic x86_64)

 * Documentation:  https://help.ubuntu.com/

122 packages can be updated. 0 updates are security updates.


*** System restart required ***  udev  /dev/mapper/servername--vg-root  /dev/sda1

but when I put it in ganeticheckdiskspace.sh not able to get it

#!/bin/sh
# Shell script to monitor or watch the disk space
# It will send an email to $ADMIN, if the (free avilable) percentage
# of space is >= 90%
# set admin email so that you can get email

ADMIN="email@domain.com"


# set alert level 90% is default
ALERT=50
OUTPUT="$(df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 \" \" \$1 }' \" | sshpass -p 'password' ssh user@VM-Y-IpAddress)"

df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 \" \" \$1 }'" | sshpass -p 'password' ssh user@VM-Y-IpAddress | while read output;
do
  #echo $output
  usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1  )
  partition=$(echo $output | awk '{ print $2 }' )
  if [ $usep -ge $ALERT ]; then
    echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)" |
     mail -s "Alert: Almost out of disk space $usep" $ADMIN
  fi
done

any help plz

ManojA
  • 11
  • 2

0 Answers0