View Single Post
  #2  
Old 19th April 2013, 18:40
aFoP aFoP is offline
Junior Member
 
Join Date: Jun 2012
Location: Budapest
Posts: 7
Thanks: 1
Thanked 1 Time in 1 Post
Default need to log the execution of script

Hi,
I would do it like this:

Quote:
#!/bin/bash

#### logging this script into 2 log files
SHELL_LOG="`basename $0`.log"
# Logs stderr and stdout to separate files.
exec 2> >(tee "$SHELL_LOG.err")
exec > >(tee "$SHELL_LOG")

echo "Checking if exist internet connection"
ping -c 3 www.google.com
if [ $? -eq 0 ]; then
echo "Starting to send & download email"
echo "Flushing mail queue"
/usr/sbin/postqueue -c /etc/postfix -f
echo "Starting fetchmail"
/usr/bin/fetchmail -v -f /etc/fetchmailrc -L /var/log/fetchmail.log
echo "Checking mail queue and fetchmail process"
while ! postqueue -p | grep -q empty && ps -C fetchmail > /dev/null; do
echo "There is still mail in queue or fetchmail is still working"
sleep 1
done
echo "Terminating the connection"
killall wvdial
fi
echo "Internet connection not found"
Reply With Quote