LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 02-20-2005, 12:32 AM   #1
colabus
Member
 
Registered: Mar 2004
Distribution: Debian Sarge, FC4
Posts: 100

Rep: Reputation: 15
bash script help


Code:
#!/bin/bash

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

if [ "!$DATE" ]; then
        for LOGFILE in `ls -t /var/log/messages*.gz`; do
                LASTHNGUP=`zgrep "PAP authentication succeeded" $LOGFILE | tail -1`
                if [ $? == 0 ]; then
                        DATE=`echo $LASTHNGUP | tr -s " " | cut -d" " -f1-3`
                        if [ "$DATE" ]; then
                                echo "Last redial: $DATE"
                                exit;
                        fi
                fi
        done
fi

DL=`ifconfig ppp0|grep bytes|cut -d"(" -f2|cut -d" " -f1`
let DOWNLOADED="$DL/1024/1024"
if [ "$DOWNLOADED" ]; then
        echo "Downloaded for this stanza: $DOWNLOADED MB"
fi
my problem is that I run the lastdial checks and when it gets a result, it exits. how can I make it continue with the remaining code?

and if anyone knows a better way I can run the first 2 scripts as one, please let me know.
 
Old 02-20-2005, 02:45 AM   #2
Artanicus
Member
 
Registered: Jan 2005
Location: Finland
Distribution: Ubuntu, Debian, Gentoo, Slackware
Posts: 827

Rep: Reputation: 31
Well, one thing I notice is the broken if there:
Code:
if [ "!$DATE" ]; then
Works pretty differently than
Code:
if [ ! "$DATE" ]; then
 
Old 02-20-2005, 03:51 PM   #3
colabus
Member
 
Registered: Mar 2004
Distribution: Debian Sarge, FC4
Posts: 100

Original Poster
Rep: Reputation: 15
narr that part was fine, i'll optimise that later. I really need to write an if statement that checks if $LOGFILE finishes with ".gz" and if so set $CMD2USE="/bin/zgrep" if not $CMD2USE="/bin/grep".

But before that I'm still stuck on the exit part. I need it to exit it's existing standza of code, but still continues on


thx for the reply.
 
  


Reply



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
Bash Script zaicheke Programming 3 11-07-2004 06:32 PM
bash script how to? Lleb_KCir Programming 11 05-21-2004 07:03 PM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM
bash script - incrementing a filename in a script tslinux Programming 10 08-05-2003 11:58 PM
bash script prob: how can i tell the script that a 'dd' has finished? Frustin Linux - General 2 04-02-2003 05:34 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:49 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
Open Source Consulting | Domain Registration