Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > Programming/Scripts

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 18th November 2011, 20:17
nerdhacker nerdhacker is offline
Junior Member
 
Join Date: Nov 2011
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default need to log the execution of script

inside /etc/ppp/ip-up.d i have this script that executes automatically when the interface ppp0 comes up.

Code:
#!/bin/sh

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"
i need to see the output for debug of this script, how can i log this to /var/log/script.log everytime it runs automatically?
Reply With Quote
Sponsored Links
  #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
Reply

Bookmarks

Tags
bash, log, script, shell

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot login to phpmyadmin penkku HOWTO-Related Questions 1 24th February 2011 09:26
freebsd 7, samba 3, domain controller alexdimarco Suggest HOWTO 6 5th November 2010 16:54
FTP Problems wabz Installation/Configuration 6 11th January 2010 18:51
[SHELL] script in script mopsos Programming/Scripts 3 8th August 2007 13:42
Upgrade from 2.2.0 to 2.2.1 successful but SSL and IMAP stopped working teleriddler Installation/Configuration 8 29th April 2006 14:25


All times are GMT +2. The time now is 01:25.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.