Jump to content

Bash Script Improvement


Netshroud

Recommended Posts

Hey all,

I'm trying to convert a Squid3 log to mimic my Netgear WGR614v8 on stock firmware. So far what I have is as follows. (It may have a typo, I retyped it here instead of copying from a different machine)

FILE=/var/log/squid3/access/log

exec 0<$FILE
while read line; do
    TIME=`echo $line | gawk '{ print strftime("%c", $1) }'`
    IP=`echo $line | awk '{ print $3 }'`
    DOMAIN=`echo $line | awk '{ print $7 }' | cut -d '/' -f 3 | sed 's/^www\.//'`
    echo [Site allowed: ${DOMAIN}] from source ${IP}, $TIME
done

Is there a more efficient way to do this?

Link to comment
Share on other sites

I am not much of a programmer but you could implement some arrays and a for loop to make the code more efficient.

Link to comment
Share on other sites

I'd rather keep it in bash to keep it portable.

The code will still be portable. you are only change the structure of the code a bit to make it more efficient.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...