Reputation: 1543
I am trying to write a shell script which will run a command to ssh into multiple machines and store the output in a variable and send it as a report via email.Here is what I have in the script as of now:
#!/bin/bash
DcEmitterConn='yinst ssh -H test.out "netstat -a | grep ES | grep 25019 | wc"'
SUBJECT="DC-Connections"
EMAIL="[email protected]"
EMAILMESSAGE="report.out"
echo $DcEmitterConn> $EMAILMESSAGE
#send email using /bin/mail
/bin/mail -s "$SUBJECT" "$EMAIL"< $EMAILMESSAGE
After executing the above command in the script it would ask me for a password and then would print the requested output. The problem i am facing in the above script is that I am not able to store the command output in the variable and print it in the email body. Can someone please let me know if I am missing something.
the output would look something like this:
[email protected]'s password: (yinst-pw)
40 240 3560
[email protected]'s password: (supplied by yinst-pw)
50 300 4450
Thanks in advance!
Upvotes: 0
Views: 9707
Reputation: 59290
You should put double quotes around $DcEmitterConn on line 8. And you can avoid the temporary file:
SUBJECT="DC-Connections"
EMAIL="[email protected]"
yinst ssh -H test.out "netstat -a | grep ES | grep 25019 | wc" | /bin/mail -s "$SUBJECT" "$EMAIL"
Upvotes: 0