AWK and making Operating Sysystem Calls
AWK and making Operating Sysystem Calls
am 30.11.2007 01:33:07 von thomas.jreige
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
Re: AWK and making Operating Sysystem Calls
am 30.11.2007 04:34:25 von Glenn Jackman
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
Re: AWK and making Operating Sysystem Calls
am 30.11.2007 04:49:35 von Bill Marcum
On 2007-11-30, 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.
>
Are you using the old broken awk instead of /usr/xpg4/bin/awk or nawk?
Re: AWK and making Operating Sysystem Calls
am 30.11.2007 05:51:59 von Ed Morton
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.
Re: AWK and making Operating Sysystem Calls
am 30.11.2007 06:23:00 von thomas.jreige
On Nov 30, 3:51 pm, Ed Morton 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.
Re: AWK and making Operating Sysystem Calls
am 30.11.2007 06:37:01 von Edward Morton
On 11/29/2007 11:23 PM, Tommy wrote:
> On Nov 30, 3:51 pm, Ed Morton 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.
Re: AWK and making Operating Sysystem Calls
am 30.11.2007 13:30:19 von Maxwell Lol
Tommy 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.
Re: AWK and making Operating Sysystem Calls
am 30.11.2007 15:16:22 von Ed Morton
On 11/30/2007 6:30 AM, Maxwell Lol wrote:
> Tommy 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.
Re: AWK and making Operating Sysystem Calls
am 30.11.2007 19:21:28 von gazelle
In article <47501B36.9080607@lsupcaemnt.com>,
Ed Morton 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".
Re: AWK and making Operating Sysystem Calls
am 30.11.2007 19:36:08 von Ed Morton
On 11/30/2007 12:21 PM, Kenny McCormack wrote:
> In article <47501B36.9080607@lsupcaemnt.com>,
> Ed Morton 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.
Re: AWK and making Operating Sysystem Calls
am 30.11.2007 20:50:10 von Maxwell Lol
Ed Morton 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.