w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Email whois details on user login using mailx - whois output format not working using sed

You need to double-quote the echo statement in its entirety:

echo -e "ALERT - Shell Access on:' `date` `who` '

' `whois $(who | cut -d'(' -f2 | cut -d')' -f1)`"

That will prevent wrapping of the whois output before it is passed to sed -- preserving all the linebreaks. The remainder of your mailx line should be fine. One other thought. Why not just write all of the output to a tmp file following | sed -r G > tmpfile. Then just add the tmpfile as an attachment to mailx?

mail -s "Alert: SSH Access from `who | cut -d'(' -f2 | cut -d')'
-f1`" -a tmpfile user@example.com




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.