LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   bash script help (https://www.linuxquestions.org/questions/linux-newbie-8/bash-script-help-292503/)

colabus 02-20-2005 12:32 AM

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.

Artanicus 02-20-2005 02:45 AM

Well, one thing I notice is the broken if there:
Code:

if [ "!$DATE" ]; then
Works pretty differently than
Code:

if [ ! "$DATE" ]; then

colabus 02-20-2005 03:51 PM

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.


All times are GMT -5. The time now is 05:42 PM.