LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-19-2004, 04:59 AM   #1
colabus
Member
 
Registered: Mar 2004
Distribution: Debian Sarge, FC4
Posts: 100

Rep: Reputation: 15
Script to determine last disconnection


Howdy guys

I'm not 100% sure if this is the right place to post this or even the right forum but i'll ask all the same. I was trying to make a script so that when root logs in, it will run this script and let me know when me last disconnection.

I use Debian and worked out that file i'm working with is:
Code:
/var/log/messages.*
So I was using:
Code:
cat /var/log/messages | grep Hangup
Sep 16 11:48:45 xionous pppd[2145]: Hangup (SIGHUP)
Sep 16 14:24:26 xionous pppd[14249]: Hangup (SIGHUP)
Sep 18 05:27:33 xionous pppd[14249]: Hangup (SIGHUP)
but of course that's not always going to work cause the log rotates.

So I ask, how would I first get it to loop through the files increasing til it gets a value, and if there is a value it will get the last one. So "Sep 18 05:27:33 xionous pppd[14249]: Hangup (SIGHUP)", and then I only want to grab the date/time.

Any help would be great, or even if you could point me in the right direction.

Thanks

Last edited by colabus; 09-20-2004 at 05:44 AM.
 
Old 09-22-2004, 08:01 AM   #2
subhasis_ray
Member
 
Registered: Jul 2001
Location: india
Distribution: RedHat 7.1,7.2,7.3, 8.0,9.0,Fedora,EL2.1,EL3.0
Posts: 103

Rep: Reputation: 16
you can try this:

#! /bin/bash

for LOGFILE in `ls -t /var/log/messages*`
do
LASTHNGUP=`grep "Hangup" $LOGFILE | tail -1`
if [ $? == 0 ]; then
DATE=`echo $LASTHNGUP | tr -s " " | cut -d" " -f1-3`
echo "Last hangup at: $DATE"
exit
fi
done


The script is self explanatory

Regards

Subhasis Ray
 
Old 09-22-2004, 08:21 AM   #3
colabus
Member
 
Registered: Mar 2004
Distribution: Debian Sarge, FC4
Posts: 100

Original Poster
Rep: Reputation: 15
thanks man, it works ok and it's a good learning base.. but atm I get a result of:
Code:
Last hangup at:
Last hangup at: Sep 18 05:27:33
Last hangup at:
Last hangup at:
Last hangup at:
how do I make it check if $DATE has a value then echo then halt/exit/kill program?
 
Old 09-22-2004, 08:37 AM   #4
subhasis_ray
Member
 
Registered: Jul 2001
Location: india
Distribution: RedHat 7.1,7.2,7.3, 8.0,9.0,Fedora,EL2.1,EL3.0
Posts: 103

Rep: Reputation: 16
Yes there seems to be aminor problem with the script. What I would suggest that you try and rectify yourself. This way u can learn shell scripting. Contact me if you run into problems.

Cheers

Subhasis
 
Old 09-24-2004, 12:42 AM   #5
colabus
Member
 
Registered: Mar 2004
Distribution: Debian Sarge, FC4
Posts: 100

Original Poster
Rep: Reputation: 15
gee man.. I've tried alot of different things for this

if [ $DATE ]; then
echo "Last hangup at: $DATE"

if [ $DATE ] echo "Last hangup at: $DATE"

if [ $DATE != "" ] echo "Last hangup at: $DATE"

if [ $DATE != "" ]; then
echo "Last hangup at: $DATE"

if [ $DATE !== "" ] echo "Last hangup at: $DATE"


And some others and had no luck. I see what you're saying it's good to learn for yourself but I learn better from example. I'm not entirely programming illiterate either I know PHP, some VB and a few others.

Maybe you know of some good tutorial sites?

Thanks
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script to read ps -e output and determine process double processes. dr_zayus69 Programming 1 09-21-2005 05:37 PM
how to determine script path cxc Programming 3 09-10-2005 08:36 AM
Does anyone know of a bash script that will determine if RPM exists on a system? jimwelc Linux - Software 3 12-28-2004 03:01 PM
disconnection message cynthia Linux - Networking 1 09-30-2004 05:48 PM
Network disconnection pixels Linux - Networking 0 10-26-2003 06:04 PM


All times are GMT -5. The time now is 09:25 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration