Re: Bash 2.05a isn't calling gawk as expected
On Tue, Nov 06, 2007 at 04:30:20PM -0500, [EMAIL PROTECTED] 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
Re: Bash 2.05a isn't calling gawk as expected
[EMAIL PROTECTED] wrote: > A shell script which worked perfectly using "1.14.7(1)" fails to execute > properly using "2.05a.0(1)-release". The purpose of the script is to parse > a session log file found in each user's home directory, and determine > whether a record belonging to some other user appears with today's date in > the file. > The parsing is done by gawk, using variables passed to it by repeated use > of the "-v" parameter. Thanks for the report. Unfortunately your test case is too complicated to recreate easily and also unfortunately incomplete since the contents of the input file are never specified. Without knowing that information it can't be duplicated. > I have tried this with both gawk 3.0.6 and gawk 3.1.1, and I get the same > results with either gawk. When I use bash 1.14, bash calls gawk correctly > and gives it the proper parameters. When I use bash 2.05a, each invocation > of gawk produces an error msg saying that gawk cannot open a file named > "-v". Then the command line for awk or the environment is probably different in those two cases. Please look specifically at the command line given to awk and then to the environment (specifically any locale setttings) for differences. > Create files named "session_log" in the home directories of some users, > and run the script. What the test case really needs is something that other people can recreate on their systems to reproduce the problem. That means that hard coded paths (other than /tmp) are bad. > blockflag=/ihome/tables/modemhog.txt > pageflag=/ihome/tables/modemhog.page > for i in /home/* Also all of the input needs to be included. > tail session_log | What is in session_log? > gawk -v Username=`basename $i` -v TodayDate=`date '+%b %e'` \ Using date like that looks to be trouble. $ date '+%b %e' Nov 7 Is that your problem? > -v CurrentYear=`date '+%Y'` -v BlockFlag=$blockflag \ > '$0 ~ /[Uu]ser/ && $0 !~ Username && $0 ~ TodayDate \ > && $0 ~ CurrentYear \ > {print Username, $0 >> BlockFlag}' Please try to create a smaller test case. Something like this: echo "User foo 2007-11-07" | awk -v Username=bob -v TodayDate=2007-11-07 \ '$0 ~ /[Uu]ser/ && $0 !~ Username && $0 ~ TodayDate {print Username, $0}' bob User foo 2007-11-07 Then the test case will be self-contained and other people can reproduce it. Thanks Bob
Re: Bash 2.05a isn't calling gawk as expected
[EMAIL PROTECTED] wrote: > Configuration Information [Automatically generated, do not change]: > Machine: i686 > OS: linux-gnu > Compiler: gcc > Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='i686' > -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-pc-linux-gnu' > -DCONF_VENDOR='pc' -DSHELL -DHAVE_CONFIG_H -D_GNU_SOURCE -I. -I. > -I./include -I./lib -O2 -march=i386 -mcpu=i686 > uname output: Linux acsvan0 2.4.18-4custom #3 Fri May 31 14:54:10 EDT 2002 > i686 unknown > Machine Type: i686-pc-linux-gnu > > Bash Version: 2.05a > Patch Level: 0 > Release Status: release > > Description: > A shell script which worked perfectly using "1.14.7(1)" fails to execute > properly using "2.05a.0(1)-release". The purpose of the script is to parse > a session log file found in each user's home directory, and determine > whether a record belonging to some other user appears with today's date in > the file. Why not run bash with the -x option to get an execution trace? Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer Live Strong. No day but today. Chet Ramey, ITS, CWRU[EMAIL PROTECTED]http://cnswww.cns.cwru.edu/~chet/
memory leak in read builtin
Configuration Information [Automatically generated, do not change]: Machine: i486 OS: linux-gnu Compiler: gcc Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='i486' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i486-pc-linux-gnu' -DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H -I. -I../bash -I../bash/include -I../bash/lib -g -O2 uname output: Linux johann 2.6.18-5-686 #1 SMP Wed Sep 26 17:54:59 UTC 2007 i686 GNU/Linux Machine Type: i486-pc-linux-gnu Bash Version: 3.1 Patch Level: 17 Release Status: release (debian etch, bash 3.1dfsg-8) Description: aparently I hit a memory leak in the read builtin. Repeat-By: yes | bash -c 'ulimit -v 1000; while read a ; do :; done' bash: xmalloc: ../bash/make_cmd.c:99: cannot allocate 2 bytes (0 bytes allocated) note that yes | while read; do :; done yes | while read a b ; do :; done both run "forever". this apears to be only triggered when the number of input fields is larger than the number of variables. Fix: I did not check too closely yet, nor did I build a debug version or run it through gdb. But from looking at the code, I suspect that in builtins/read.def:647 ... the allocated temporary space for t is never FREE'd. | /* Check whether or not the number of fields is exactly the same as the | number of variables. */ | if (*input_string) |{ | t1 = input_string; | t = get_word_from_string (&input_string, ifs_chars, &e); | if (*input_string == 0) | input_string = t; | else | input_string = strip_trailing_ifs_whitespace (t1, ifs_chars, saw_escape); |} thanks for listening, awaiting your feedback. Lars Ellenberg -- : Lars EllenbergTel +43-1-8178292-55 : : LINBIT Information Technologies GmbH Fax +43-1-8178292-82 : : Vivenotgasse 48, A-1120 Vienna/Europehttp://www.linbit.com :
Bash 2.05a isn't calling gawk as expected
Configuration Information [Automatically generated, do not change]: Machine: i686 OS: linux-gnu Compiler: gcc Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='i686' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-pc-linux-gnu' -DCONF_VENDOR='pc' -DSHELL -DHAVE_CONFIG_H -D_GNU_SOURCE -I. -I. -I./include -I./lib -O2 -march=i386 -mcpu=i686 uname output: Linux acsvan0 2.4.18-4custom #3 Fri May 31 14:54:10 EDT 2002 i686 unknown Machine Type: i686-pc-linux-gnu Bash Version: 2.05a Patch Level: 0 Release Status: release Description: A shell script which worked perfectly using "1.14.7(1)" fails to execute properly using "2.05a.0(1)-release". The purpose of the script is to parse a session log file found in each user's home directory, and determine whether a record belonging to some other user appears with today's date in the file. The parsing is done by gawk, using variables passed to it by repeated use of the "-v" parameter. I have tried this with both gawk 3.0.6 and gawk 3.1.1, and I get the same results with either gawk. When I use bash 1.14, bash calls gawk correctly and gives it the proper parameters. When I use bash 2.05a, each invocation of gawk produces an error msg saying that gawk cannot open a file named "-v". Repeat-By: Create files named "session_log" in the home directories of some users, and run the script. The shell script follows: .cut here. #!/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}' done [ -s $blockflag ] || exit 0 cat $blockflag cp -f $blockflag $pageflag .cut here. NEIL PARKS Beachwood, Ohio
Re: error with ' in command substitution
> At least when a non-compliance is spotted, it's fixed in the > next release. And this one will be, too. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer Live Strong. Chet Ramey, ITS, CWRU[EMAIL PROTECTED]http://tiswww.tis.case.edu/~chet/