-
Help fix bash script that mails clamscan result
Hello,
i am unable to make this script working, i was playing with quotation marks, but i do not receive e-mail, i tried to replace mailing part by just echo, but nothing is printed. I wanted whole command to be one liner if possible
Code:
#!/bin/bash
#set -exu
clamscanresult="$(/usr/local/bin/clamscan /var/tmp /tmp /home/"$(ls -lt /home|head -n 2|tail -n 1|grep -v root|awk '{print $4}' 2>/dev/null)"/public_html)" && if [[ "$clamscanresult" != *"Infected files: 0"* ]];then echo "Infected files was found: \"$clamscanresult\""|mail -s "ClamScan" me@gmail.com;fi
-
Why make it harder for yourself trying to make it a one liner.
I see you tried using the debug (set -x) so did that provide any insight?
You can add echo statements to aid in debugging.
#!/bin/bash
scandir="/home/$(ls -lt /home|head -n 2|tail -n 1|grep -v root|awk '{print $4}' 2>/dev/null)/public_html"
echo "scandir=$scandir"
clamscanresult=$(clamscan /var/tmp /tmp $scandir)
if [[ "$clamscanresult" != *"Infected files: 0"* ]];then
echo "Results: $clamscanresult"
fi
You might want to look at the clamscan options to only output infected files etc.
-
Thanks, i ended up making it a multi liner as you mentioned and then it started working.
I have suspection the "&&" or ";" somehow breaks the variable "clamscanresult" or some problem with quotation marks.
But OK, at least it works now. thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|