bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bash 2.05a isn't calling gawk as expected


From: Andrew J. Schorr
Subject: Re: Bash 2.05a isn't calling gawk as expected
Date: Wed, 7 Nov 2007 08:47:05 -0500
User-agent: Mutt/1.4.2.2i

On Tue, Nov 06, 2007 at 04:30:20PM -0500, nparks@torah.org wrote:
> #!/bin/sh
> 
> blockflag=/ihome/tables/modemhog.txt
> pageflag=/ihome/tables/modemhog.page
> 
> [ -s $blockflag ] && exit
> 
> for i in /home/*
> do
>   [ -d $i ] || continue
>   cd $i
> 
>   [ -f session_log ] || continue
> 
>   tail session_log |
>     gawk -v Username=`basename $i` -v TodayDate=`date '+%b %e'` \
>       -v CurrentYear=`date '+%Y'` -v BlockFlag=$blockflag \
>       '$0 ~ /[Uu]ser/ && $0 !~ Username && $0 ~ TodayDate \
>       && $0 ~ CurrentYear \
>       {print Username, $0 >> BlockFlag}'  

Two comments:

1. I think you need to say "cd .." here to return to the top-level
directory so that your next call to "cd" has a chance to succeed.

2. You should enclose the -v arguments to gawk in quotes.  Like this:

    gawk -v "Username=`basename $i`" -v "TodayDate=`date '+%b %e'`" ...

Otherwise, any spaces in those values will confuse gawk.
For example:

bash-3.1$ gawk -v "TodayDate=`date '+%b %e'`" 'BEGIN {print TodayDate}'
Nov  7
bash-3.1$ gawk -v TodayDate=`date '+%b %e'` 'BEGIN {print TodayDate}'
gawk: cmd. line:1: fatal: cannot open file `BEGIN {print TodayDate}' for 
reading (No such file or directory)

Regards,
Andy




reply via email to

[Prev in Thread] Current Thread [Next in Thread]