0

I am trying to run mailx after remoting into another linux box, but for some reason the command doesn't work. I also want to add the content of a csv file in the mail I am trying to send, but it is not working.

SERVER=host1
rm conncheck.csv
`netstat -na 63.111.184.111 442|grep "ESTABLISHED"|grep "63.111.184.111:442" >> conncheck.csv`
`netstat -na 63.111.184.201 572|grep "ESTABLISHED"|grep "63.111.184.201:572" >> conncheck.csv`

wordcount=`grep "ESTABLISHED" conncheck.csv|wc -l`
if [ $wordcount == 2 ]; then
`scp conncheck.csv $SERVER:/tmp/`
ssh -o "StrictHostKeyChecking=no" $SERVER `cat /tmp/conncheck.csv | mailx -s "LiquidityFIX connection is up" recepient@email.com < /dev/null'
else
ssh -o "StrictHostKeyChecking=no" $SERVER mailx -s 'LiquidityFIX connection is down <eom>' recepient@email.com < /dev/null'
fi
~

I think I am getting the command incorrect. Kindly advise how to get this working

Rajdeep
  • 1
  • 2
  • `wordcount=$(grep -i -c "ESTABLISHED" conncheck.csv)` may work equally well without the pipe. Also see [How to use Shellcheck](http://github.com/koalaman/shellcheck). – jww Dec 03 '19 at 08:54
  • Thanks . But any idea how I can get the mailx working with ssh – Rajdeep Dec 03 '19 at 08:57
  • You have not stated what the problem is. Also see [How to use SSH to run a shell script on a remote machine?](https://stackoverflow.com/q/305035/608639) and anything about [Expect scripts and SSH](https://stackoverflow.com/questions/tagged/ssh+expect). – jww Dec 03 '19 at 09:00
  • The script is working fine till the point when it tried to shh and look for the file conncheck.csv in the /tmp/ path in the remote server. Seems this command is not working. Its not able to find the file – Rajdeep Dec 03 '19 at 09:21
  • At the end it throws this error : bash: -c: line 0: unexpected EOF while looking for matching `'' bash: -c: line 1: syntax error: unexpected end of file – Rajdeep Dec 03 '19 at 09:23

1 Answers1

0

in this line:

ssh -o "StrictHostKeyChecking=no" $SERVER `cat /tmp/conncheck.csv | mailx -s "LiquidityFIX connection is up" recepient@email.com < /dev/null'

you need to change the ` to ' right before the cat

mlazatin
  • 71
  • 1
  • 3