1

how to trigger mail with below format by getting df -h /log fS usage

server1 | server 2

75% | 50%

Below are step how i check FS usage manually

login to putty

ssh server1

give the password

issue command df -h /log to get FS usage .

How do it get details from two servers server 1 ans server 2 and send the FS

usage details in mail in below format

server1 | server 2

75% | 50%

  • do you want to do this in a batch script that you run from the windows command line? or do you want it to run automatically? if the former, then your question is off-topic because it's about windows batch files. if the latter, then set up cron jobs on the remote systems to run df -h /log | mail -s "$(hostname -s): df -h /log" you@your.mail.host – cas Jun 12 '16 at 10:35
0

First of all, you need to remove the requirement to use a password to log into your servers. Use public key based logins instead. Once you've don that, you'll need something like:

$ for host in "server1" "server2" ; do echo $host; ssh $host df --output="ipcent" /tmp | tail -n1 | tr -d " "; done | pr --columns=2  --length=2 | mail bloggs@example.com

should work.

The line loops through both server1 and server2 and runs the command:

echo $host; ssh $host df --output="ipcent" /tmp

on each server in turn. The output of this is simply the server name ($host) followed by the percentage use of the drive containing /tmp, but it has a header, so that is removed by piping it to:

tail -n1

which returns the last line (the percentage). Unfortunately, that is surrounded by whitespace, so that is removed by piping it to:

tr -d " "

At this point, both servers would have been ssh'd, but the output would be something like:

server1
75%
server2
50%

so it is piped into:

pr --columns=2 --length=2

in order to rotate it to the format you requested:

server1     server2
75%         50%

Finally, this is piped into:

mail bloggs@example.com

to email it to bloggs.

| improve this answer | |

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.