Hello guys.
I have two problems
Firstly, I make a script which send a report of current log files in every 10 min. When I manually execute the script, if there are no log file, it sends a mail with
"no log file to report". However, when the script execute automatically with Crontab, it sends
"Filename: *.log"
Secondly, when there is email address in report.txt, if the address is "something@gmail.com", when I check the mail after I run it, the mail address become "something%40gmail.com" like this. How can I fix two issues?
Thank you.
Here is my code:
<<Crontab>>
Code:
*/10 * * * * /home/team_24/Log_Report.bash
<<Log_Report.bash>>
Code:
#! /bin/bash
cd /home/team_24/logs
export DIR=/home/team_24/logs
if ls ${DIR}/*.log &>/dev/null
then
for file in *.log
do
touch report.txt
echo "Filename: $file" >> report.txt
echo "" >> report.txt
cat "$file" >> report.txt
echo "" >> report.txt
#remove log original log file
rm -f $file
done
#report the log file and remove from log directory
mail -s "Approved_Client_Report" something@gmail.com < /home/team_24/logs/report.txt
rm /home/team_24/logs/report.txt
exit 0
else
touch report.txt
echo "No logfile to report" >> report.txt
mail -s "Approved_Client_Report" something@gmail.com < /home/team_24/logs/report.txt
rm /home/team_24/logs/report.txt
exit 0
fi