AWK and making Operating Sysystem Calls

Hi Everyone, here is a script i have written to collect information
from the /etc/passwd file
If I run this script on Linux, it works. If I run on Solaris 10, the
system call below does not work.

Any Ideas? Is there something wrong with making system calls from Awk
in Solaris 10.

Thanks

Tom

date > users.output
echo "" >> users.output
echo "" >> users.output
echo "++++++++++++++++++++++" >> users.output
echo "OUTPUT FOR USERS FILES" >> users.output
echo "++++++++++++++++++++++" >> users.output
awk -F: '($3 >= 0) {
printf("\n");
printf("\n");
print "===============================";
print "Username: " $1;
print "Home Drive: " $6;
print "===============================";
printf("\n");
system("ls -la " $6"/.*");
printf("\n");
print "END ======================== END";
}' /etc/passwd
thomas.jreige [ Fr, 30 November 2007 01:33 ] [ ID #1882409 ]

Re: AWK and making Operating Sysystem Calls

At 2007-11-29 07:33PM, "Tommy" wrote:
> Hi Everyone, here is a script i have written to collect information
> from the /etc/passwd file
> If I run this script on Linux, it works. If I run on Solaris 10, the
> system call below does not work.

C'mon, I don't want to turn this group into comp.lang.perl.misc, but
"doesn't work" is the most useless problem report. Describe in detail
what you get, and how it differs from what you expect.

Also, which awk are you using on solaris?

--
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry
Glenn Jackman [ Fr, 30 November 2007 04:34 ] [ ID #1882412 ]

Re: AWK and making Operating Sysystem Calls

On 2007-11-30, Tommy <thomas.jreige [at] gmail.com> wrote:
>
>
> Hi Everyone, here is a script i have written to collect information
> from the /etc/passwd file
> If I run this script on Linux, it works. If I run on Solaris 10, the
> system call below does not work.
>
> Any Ideas? Is there something wrong with making system calls from Awk
> in Solaris 10.
>
Are you using the old broken awk instead of /usr/xpg4/bin/awk or nawk?
Bill Marcum [ Fr, 30 November 2007 04:49 ] [ ID #1882413 ]

Re: AWK and making Operating Sysystem Calls

On 11/29/2007 6:33 PM, Tommy wrote:
> Hi Everyone, here is a script i have written to collect information
> from the /etc/passwd file
> If I run this script on Linux, it works. If I run on Solaris 10, the
> system call below does not work.
>
> Any Ideas? Is there something wrong with making system calls from Awk
> in Solaris 10.
>
> Thanks
>
> Tom
>
> date > users.output
> echo "" >> users.output
> echo "" >> users.output
> echo "++++++++++++++++++++++" >> users.output
> echo "OUTPUT FOR USERS FILES" >> users.output
> echo "++++++++++++++++++++++" >> users.output
> awk -F: '($3 >= 0) {
> printf("\n");
> printf("\n");
> print "===============================";
> print "Username: " $1;
> print "Home Drive: " $6;
> print "===============================";
> printf("\n");
> system("ls -la " $6"/.*");
> printf("\n");
> print "END ======================== END";
> }' /etc/passwd

You're probably invoking old, broken awk as Bill suggests. Having said that,
there doesn't seem to be any point in using awk instead of a simple shell script
for this job, something like this:

printf "..."
while IFS=: read f1 f2 f3 f4 f5 f6 rest
do
if (( $f3 >=0 )); then
printf "..."
printf "Username: %s\n",f1
printf "Home Drive: %s\n",$6
printf "..."
ls -la "$6/.*"
printf "..."
endif
done < /etc/passwd

Use echo or printf for printing as you see fit.

Ed.
Ed Morton [ Fr, 30 November 2007 05:51 ] [ ID #1882415 ]

Re: AWK and making Operating Sysystem Calls

On Nov 30, 3:51 pm, Ed Morton <mor... [at] lsupcaemnt.com> wrote:
> On 11/29/2007 6:33 PM, Tommy wrote:
>
>
>
>
>
> > Hi Everyone, here is a script i have written to collect information
> > from the /etc/passwd file
> > If I run this script on Linux, it works. If I run on Solaris 10, the
> > system call below does not work.
>
> > Any Ideas? Is there something wrong with making system calls from Awk
> > in Solaris 10.
>
> > Thanks
>
> > Tom
>
> > date > users.output
> > echo "" >> users.output
> > echo "" >> users.output
> > echo "++++++++++++++++++++++" >> users.output
> > echo "OUTPUT FOR USERS FILES" >> users.output
> > echo "++++++++++++++++++++++" >> users.output
> > awk -F: '($3 >= 0) {
> > printf("\n");
> > printf("\n");
> > print "===============================";
> > print "Username: " $1;
> > print "Home Drive: " $6;
> > print "===============================";
> > printf("\n");
> > system("ls -la " $6"/.*");
> > printf("\n");
> > print "END ======================== END";
> > }' /etc/passwd
>
> You're probably invoking old, broken awk as Bill suggests. Having said that,
> there doesn't seem to be any point in using awk instead of a simple shell script
> for this job, something like this:
>
> printf "..."
> while IFS=: read f1 f2 f3 f4 f5 f6 rest
> do
> if (( $f3 >=0 )); then
> printf "..."
> printf "Username: %s\n",f1
> printf "Home Drive: %s\n",$6
> printf "..."
> ls -la "$6/.*"
> printf "..."
> endif
> done < /etc/passwd
>
> Use echo or printf for printing as you see fit.
>
> Ed.- Hide quoted text -
>
> - Show quoted text -

Thanks for this code and yes it was the buggy version of awk in
Solaris.

Thanks everyone for your help.
thomas.jreige [ Fr, 30 November 2007 06:23 ] [ ID #1882417 ]

Re: AWK and making Operating Sysystem Calls

On 11/29/2007 11:23 PM, Tommy wrote:
> On Nov 30, 3:51 pm, Ed Morton <mor... [at] lsupcaemnt.com> wrote:
>
>>On 11/29/2007 6:33 PM, Tommy wrote:
>>
>>
>>
>>
>>
>>
>>>Hi Everyone, here is a script i have written to collect information
>>>from the /etc/passwd file
>>>If I run this script on Linux, it works. If I run on Solaris 10, the
>>>system call below does not work.
>>
>>>Any Ideas? Is there something wrong with making system calls from Awk
>>>in Solaris 10.
>>
>>>Thanks
>>
>>>Tom
>>
>>>date > users.output
>>>echo "" >> users.output
>>>echo "" >> users.output
>>>echo "++++++++++++++++++++++" >> users.output
>>>echo "OUTPUT FOR USERS FILES" >> users.output
>>>echo "++++++++++++++++++++++" >> users.output
>>>awk -F: '($3 >= 0) {
>>>printf("\n");
>>>printf("\n");
>>>print "===============================";
>>>print "Username: " $1;
>>>print "Home Drive: " $6;
>>>print "===============================";
>>>printf("\n");
>>>system("ls -la " $6"/.*");
>>>printf("\n");
>>>print "END ======================== END";
>>>}' /etc/passwd
>>
>>You're probably invoking old, broken awk as Bill suggests. Having said that,
>>there doesn't seem to be any point in using awk instead of a simple shell script
>>for this job, something like this:
>>
>>printf "..."
>>while IFS=: read f1 f2 f3 f4 f5 f6 rest
>>do
>> if (( $f3 >=0 )); then
>> printf "..."
>> printf "Username: %s\n",f1
>> printf "Home Drive: %s\n",$6
>> printf "..."
>> ls -la "$6/.*"
>> printf "..."
>> endif
>>done < /etc/passwd
>>
>>Use echo or printf for printing as you see fit.
>>
>> Ed.- Hide quoted text -
>>
>>- Show quoted text -
>
>
> Thanks for this code and yes it was the buggy version of awk in
> Solaris.
>
> Thanks everyone for your help.

You're welcome. If you do decide to keep your shell+awk script, you could
improve it to:

awk -F: -v date=$(date) '
BEGIN {
print date
print "\n\n++++++++++++++++++++++"
print "OUTPUT FOR USERS FILES"
print "++++++++++++++++++++++"
}
$3 >= 0 {
print "\n\n==============================="
print "Username: " $1
print "Home Drive: " $6
print "===============================\n"
system("ls -la " $6"/.*")
print "\nEND ======================== END"
}' /etc/passwd > users.output

If you use GNU awk, you can use it's time commands instead of the external "date".

Regards,

Ed.
Edward Morton [ Fr, 30 November 2007 06:37 ] [ ID #1882418 ]

Re: AWK and making Operating Sysystem Calls

Tommy <thomas.jreige [at] gmail.com> writes:

> Thanks for this code and yes it was the buggy version of awk in
> Solaris.

Ahem. I'm not sure the old version should be classified as "buggy."
It does what it is documented to do. It's just ..... old.
Maxwell Lol [ Fr, 30 November 2007 13:30 ] [ ID #1882439 ]

Re: AWK and making Operating Sysystem Calls

On 11/30/2007 6:30 AM, Maxwell Lol wrote:
> Tommy <thomas.jreige [at] gmail.com> writes:
>
>
>>Thanks for this code and yes it was the buggy version of awk in
>>Solaris.
>
>
> Ahem. I'm not sure the old version should be classified as "buggy."
> It does what it is documented to do. It's just ..... old.

I like to call it "broken" rather than "buggy", but I suppose either works. One
small example:

$ gawk 'BEGIN{print sprintf("The magic number is"), 3; exit}'
The magic number is 3
$ nawk 'BEGIN{print sprintf("The magic number is"), 3; exit}'
The magic number is 3
$ /usr/xpg4/bin/awk 'BEGIN{print sprintf("The magic number is"), 3; exit}'
The magic number is 3
$ awk 'BEGIN{print sprintf("The magic number is"), 3; exit}'
The magic number is

You could, I suppose, make a case for something not being technically "broken"
if that was the designers intent but "broken"s a more convenient way of
expressing the condition as it relates to it's intended user compared to
"functioning as designed but not as expected, not as any of it's peers, and not
in a useful fashion" so I'll stick with "broken".

Ed.
Ed Morton [ Fr, 30 November 2007 15:16 ] [ ID #1882443 ]

Re: AWK and making Operating Sysystem Calls

In article <47501B36.9080607 [at] lsupcaemnt.com>,
Ed Morton <morton [at] lsupcaemnt.com> wrote:
....
>I like to call it "broken" rather than "buggy", but I suppose either works. One
>small example:
>
>$ gawk 'BEGIN{print sprintf("The magic number is"), 3; exit}'
>The magic number is 3
>$ nawk 'BEGIN{print sprintf("The magic number is"), 3; exit}'
>The magic number is 3
>$ /usr/xpg4/bin/awk 'BEGIN{print sprintf("The magic number is"), 3; exit}'
>The magic number is 3
>$ awk 'BEGIN{print sprintf("The magic number is"), 3; exit}'
>The magic number is

This is interesting. Any idea why this happens? I mean, I'm familiar
with most of the whackiness^Wold-fashioned-ness of the old AWK, but this
one has me stumped.

Or is it just a bug?

>You could, I suppose, make a case for something not being technically "broken"
>if that was the designers intent but "broken"s a more convenient way of
>expressing the condition as it relates to it's intended user compared to
>"functioning as designed but not as expected, not as any of it's peers, and not
>in a useful fashion" so I'll stick with "broken".

Well, the current ethic among Usenet-posters in groups like this one
(shell) and, e.g., CLC, is to be what I call a "standards jockey". I.e.,
to maintain that the published standards are the sacred texts and
anything that doesn't meet those standards is "broken" (or whatever more
or less insulting term you prefer).

By that, er, standard, Solaris's "old awk" is "broken".
gazelle [ Fr, 30 November 2007 19:21 ] [ ID #1882447 ]

Re: AWK and making Operating Sysystem Calls

On 11/30/2007 12:21 PM, Kenny McCormack wrote:
> In article <47501B36.9080607 [at] lsupcaemnt.com>,
> Ed Morton <morton [at] lsupcaemnt.com> wrote:
> ...
>
>>I like to call it "broken" rather than "buggy", but I suppose either works. One
>>small example:
>>
>>$ gawk 'BEGIN{print sprintf("The magic number is"), 3; exit}'
>>The magic number is 3
>>$ nawk 'BEGIN{print sprintf("The magic number is"), 3; exit}'
>>The magic number is 3
>>$ /usr/xpg4/bin/awk 'BEGIN{print sprintf("The magic number is"), 3; exit}'
>>The magic number is 3
>>$ awk 'BEGIN{print sprintf("The magic number is"), 3; exit}'
>>The magic number is
>
>
> This is interesting. Any idea why this happens? I mean, I'm familiar
> with most of the whackiness^Wold-fashioned-ness of the old AWK, but this
> one has me stumped.
>
> Or is it just a bug?

The "sprintf()" function thinks the ", 3" are it's arguments rather than
arguments for "print":

$ awk 'BEGIN{print sprintf("The magic number is <%d>"), 3; exit}'
The magic number is <3>
$ gawk 'BEGIN{print sprintf("The magic number is <%d>"), 3; exit}'
gawk: fatal: not enough arguments to satisfy format string
`The magic number is <%d>'
^ ran out for this one

$ awk 'BEGIN{print sprintf("The magic number is <%d>", 4), 3; exit}'
The magic number is <4>
$ gawk 'BEGIN{print sprintf("The magic number is <%d>", 4), 3; exit}'
The magic number is <4> 3

Whether that's by design or a bug, I don't know (or care!)...

Ed.
Ed Morton [ Fr, 30 November 2007 19:36 ] [ ID #1882448 ]

Re: AWK and making Operating Sysystem Calls

Ed Morton <morton [at] lsupcaemnt.com> writes:

> $ awk 'BEGIN{print sprintf("The magic number is"), 3; exit}'

Good point. That's not a bug I came across.

As I recall, the oldest awk I used had problems if the arguments to printf
continued onto another line. You needed a \ at the end of a "partial"
line, i.e.
print( a, \
b);
I got used to these quirks.
Maxwell Lol [ Fr, 30 November 2007 20:50 ] [ ID #1882450 ]
Linux » comp.unix.shell » AWK and making Operating Sysystem Calls

Vorheriges Thema: tricky sed problem
Nächstes Thema: stat: "modification time" vs "change time"?