nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

Shell Script To Log Uptime, Connect Time, Bytes Sent Received Of a PPP Connection

This is a discussion on Shell Script To Log Uptime, Connect Time, Bytes Sent Received Of a PPP Connection within the Shell scripting forums, part of the Development/Scripting category; Useing redhat 7.3. i need a script to log the uptime of a ppp connection. it need to display the ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Linux answers from nixCraft.


Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 21-05-2009, 08:12 PM
Junior Member
User
 
Join Date: May 2009
OS: redhat 7.3
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
dane is on a distinguished road
Default Shell Script To Log Uptime, Connect Time, Bytes Sent Received Of a PPP Connection

Useing redhat 7.3.

i need a script to log the uptime of a ppp connection.
it need to display the time it started and terminated and the amount of ime it ran for.
help!!!!!
it need to run a cron job and then display the stats.
as i said help plz plz!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Reply With Quote
  #2 (permalink)  
Old 22-05-2009, 07:27 AM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,710
Thanks: 11
Thanked 245 Times in 184 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Usually, you need to create a shell script as follows in /etc/ppp/ip-down.local

Code:
#!/bin/sh
OUT=/var/log/pppd.acct.log
echo "Connect time: $CONNECT_TIME" > $OUT
echo "Bytes sent: $BYTES_SENT" >> $OUT
echo "Bytes Received: $BYTES_RCVD" >> $OUT
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #3 (permalink)  
Old 22-05-2009, 01:56 PM
Junior Member
User
 
Join Date: May 2009
OS: redhat 7.3
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
dane is on a distinguished road
Default

Thanks for the prompt response.

How would i be able to measure total connection time aswell
i would need this to run in the crontab as a daily uptime report that get emailed to me if the connection goes down with the stats:
connect time
total connect time
date
bytes sent/recieved

Sorry im new to scripting, still learning.
Reply With Quote
  #4 (permalink)  
Old 23-05-2009, 04:06 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,710
Thanks: 11
Thanked 245 Times in 184 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Create a script called ppp.sh:
Code:
#!/bin/sh
OUT=/var/log/pppd.acct.log.$(date +"%d-%m-%Y")
log(){
  echo "Connect time: $CONNECT_TIME" >> $OUT
  echo "Bytes sent: $BYTES_SENT" >> $OUT
  echo "Bytes Received: $BYTES_RCVD" >> $OUT
}

email(){
 /bin/mail -S 'ppp log' you@example.com < /var/log/pppd.acct.log.$(date +"%d-%m-%Y")
}
case "$1" in
        ppplog)
                log
                ;;
        pppemail)
                email
                ;;
        *)
                echo "Usage: $0 {ppplog|pppemail}"
esac
Create cron job as follows to email log file to yourself:
Code:
@daily /path/to/ppp.sh pppemail
To log messages add the following line to /etc/ppp/ip-down.local:
Code:
/path/to/ppp.sh ppplog
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #5 (permalink)  
Old 25-05-2009, 03:09 PM
Junior Member
User
 
Join Date: May 2009
OS: redhat 7.3
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
dane is on a distinguished road
Default Thank you very much, your a great help

Thanks!!!!!!!!!

Everything is in place if i run the script i recieve an email but with blank stats

eg:
Connect time:
Bytes sent:
Bytes Received:

Do i need to wait for the crontab to run as there is not info.
and how do i add to have a field in there

total time= ??hrs min sec
Reply With Quote
  #6 (permalink)  
Old 25-05-2009, 03:28 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,710
Thanks: 11
Thanked 245 Times in 184 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

You are using old Redhat software. I'm not sure if pppd support those settings. Just go through pppd man page and search for those 3 variables. If they are present in man page you will be able to use them.
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
Reply

Tags
/etc/ppp/ip-down.local , bytes_rcvd , ppp bytes_sent , ppp connect_time , pppd , pppd down script , redhat


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
Script To Kill process if time and memories of more than 30% lliriK Shell scripting 9 28-04-2009 12:43 AM
Backup Shell Script That Searches for all the files greater then 200 bytes nextcmchiranjeevi Shell scripting 2 11-02-2009 11:44 PM
Script for checking uptime on multiple hosts madhusudany2k Shell scripting 0 12-08-2008 08:24 PM
SNMP Error:no response received manish_2479 Networking, Firewalls and Security 2 14-06-2007 04:17 AM
how to delete 0 bytes file puppen Linux software 2 15-05-2007 09:45 PM


All times are GMT +5.5. The time now is 08:07 AM.


Powered by vBulletin® Version 3.8.5 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38