Getting information out of a log file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Getting information out of a log file
# 1  
Old 10-23-2014
Getting information out of a log file

Hello guys,

I am trying to filter some information out of a log file (example shortcut)


Code:
===== fspCIV0
/vol/vol0 -sec=sys,rw=fspsanp42.net,root=fspsanp42.net,nosuid
===== fcvCIS01
/vol/ARDW -sec=sys,rw
/vol/ARDW -sec=sys,rw
/vol/ARDW -sec=sys,rw,nosuid
/vol/ARDW -sec=sys,rw
/vol/ARDW -sec=sys,rw=none
/vol/lonulixda -sec=sys,rw=fcvsan10.net:fcvsan11.net,root=fcvsan10.net:fcvsan11.net

My desired output is:
Code:
vFiler, Type, host
fspCIV0, /vol/vol0, fspsanp42.net
fcvCIS01, /vol/lonulixda, fcvsan10.net
fcvCIS01, /vol/lonulixda, fcvsan11.net

So now a few information behind the output i am trying to achieve.

vFiler: the line where the vFiler is in always starts with a =====
I just want to get the name of it behind the '=' symbol

Type/host: as you can see there are more than just the 2 different types in
my example output. This is because I only want the types which are followed by hosts, indicator here is "rw=" or "ro=" followed by host
names. If there are multiple hosts named they are seperated by a ":"
and there should be a new line for each host in the output.

EDIT: everything behind the 'root=' should be ignored becaue it says just the same anyway

This is only a example shortcut of the log file, because it would be way too long, it continues that way for a few pages!

Since I am not really familiar with Scripting I have no idea what commands/loops etc. I need to get my wished output ... hope you guys can help

Thanks in advance,
linux_scrub

Last edited by Corona688; 10-23-2014 at 01:44 PM..
# 2  
Old 10-23-2014
Please use code tags for code and data, [code]stuff[/code]. You can also select text and click the Image button.
# 3  
Old 10-23-2014
One approach:

Code:
#!/bin/bash

OLDIFS="$IFS"

# Read lines one by one, splitting into A="/vol/vol0", B="-sec=sys,rw=fspsanp42.net,root=fspsanp42.net,nosuid"
# ...or A="=====", B="fspCIV0"
while read -r A B
do
        # Check the contents of A
        if [ "$A" = "=====" ]
        then
                VFILER="$B"
                continue
        fi

        # Split "-sec=sys,rw=fspsanp42.net,root=fspsanp42.net,nosuid"
        # into $1="sec", $2="sys", $3="rw=fspsanp42.net,root=fspsanp42.net", $4="nosuid"
        # ${B:1} is to get rid of the - by skipping the first char, otherwise it would be ${B}
        IFS="," ; set -- ${B:1}
        # Loop over $1 though $4
        while [ "$#" -gt 0 ]
        do
                case "$1" in
                r[ow]=none)     ;;
                r[ow]=*)
                        BACKUP="$*" # Save $1..$4 since we need to overwrite them now
                        IFS=":=" ; set -- $1 ; shift ; IFS=","
                        printf "$VFILER, $A, %s\n" $*
                        set -- $BACKUP # Return $1...$4 to what they were
                        ;;
                esac

                shift # Set $1=$2, $2=$3, $3=$4, discard $4.
        done
        IFS="$OLDIFS" # Split on spaces again, to read the next lne.
done

Code:
$ ./ardw.sh < data

fspCIV0, /vol/vol0, fspsanp42.net
fcvCIS01, /vol/lonulixda, fcvsan10.net
fcvCIS01, /vol/lonulixda, fcvsan11.net

$


Last edited by Corona688; 10-23-2014 at 02:15 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read Log Realtime and Parse out Information for a Report

I'm not too fluent at this and having problems comprehending / coming up with a way to do it. Our telephone system is spitting out call information on it's maintenance (serial) port which i have connected to a linux box. I want to be able to monitor the output of this text and when a 911 call is... (1 Reply)
Discussion started by: Pythong
1 Replies

2. Shell Programming and Scripting

Feeding information in columns of LOG file

Dear all, I want to write a shell script to easy my job. Here is the description of task: I have several files (d1.log, d2.log, d3.log etc) with the common text as =======using photon counter ====== tot pho is = 29596 nomatch pho is = 1350 phoeta pho is = 1220... (11 Replies)
Discussion started by: nrjrasaxena
11 Replies

3. Shell Programming and Scripting

Grep'ing information from a log file on SUN OS 5

Hi Guys, I'm trying to write an script that will be launched by a user. The script will look at a log file and check for alerts with the date (supplied by user) and a machine's hostname (also supplied by the user). I'm trying to get the output formatted just like the log file. The logfile looks... (5 Replies)
Discussion started by: illgetit
5 Replies

4. Shell Programming and Scripting

Extract various information from a log file

Hye ShamRock If you can help me with this difficult task for me then it will save my day Logs : ================================================================================================================== ... (4 Replies)
Discussion started by: SilvesterJ
4 Replies

5. Shell Programming and Scripting

extract information from a log file (last days)

I'm still new to bash script , I have a log file and I want to extract the items within the last 5 days . and also within the last 10 hours the log file is like this : it has 14000 items started from march 2002 to january 2003 awk '{print $4}' < *.log |uniq -c|sort -g|tail -10 but... (14 Replies)
Discussion started by: matarsak
14 Replies

6. Shell Programming and Scripting

Extract information from Log file formatted

Good evening! Trying to make a shell script to parse log file and show only required information. log file has 44 fields and alot of lines, each columns separated by ":". log file is like: first_1:3:4:5:6:1:3:4:5:something:notinterested second_2:3:4:3:4:2 first_1:3:4:6:6:7:8 I am interested... (3 Replies)
Discussion started by: dummie55
3 Replies

7. UNIX for Dummies Questions & Answers

Log information

hello all, so i'm working on a script, and part of it is to display the log info of the current logged on users, 1- full name 2- last log-in time 3- source ip address i used who command to find the user ID then grep the full name and the last log in time. but i can't find a command... (6 Replies)
Discussion started by: ibzee33
6 Replies

8. UNIX for Dummies Questions & Answers

Routing a verbose information to a log file

Hi All, In the script mentioned below uses a sftp command to login to the remote host and pull the files from the remote server. we want to log this inf to a log file . But it is not happening, the verbose information is just displayed on the screen but not to the log file when I run this... (1 Reply)
Discussion started by: raghuveer2008
1 Replies

9. Solaris

Log Information about login/logout of any users

Hi to all, i want configure my solaris 10 machine to log all login,logout and "su" in a particularly file. How can i do it? Now i enable auth.* in syslog.conf but the informations are written in a confused mode... Thanks (4 Replies)
Discussion started by: suuuper
4 Replies

10. Shell Programming and Scripting

caputring information from log

Hello all, I am pretty new and UNIX scripting. I am trying to write a script that will caputure some information from a log, without opening a log. Can you please point me in the right direction. Thanks, Keyur (5 Replies)
Discussion started by: fossil0681
5 Replies
Login or Register to Ask a Question