Home > Archive > AWK > April 2005 > newbie question
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Boom Stick 2005-04-14, 3:55 pm |
| Searching Google I cant seem to get the syntax correct.
Looking to run conditions on the output of awk:
#!/bin/ksh
#set -x
echo "Enter the instance name"
read opt
echo "what day"
read x
grep COMMAND=/etc/init.d/$opt /var/log/secure | awk '{if ( $x = $2)
print $1,$2,$3,$6,$14,$15,$16,$17; else
print "please check the day you entered"}'
I want to see who is running sudo on init.d commands but it only
prints the value of $x.
Thanks,
Boom
| |
| Loki Harfagr 2005-04-14, 3:55 pm |
| Le Thu, 14 Apr 2005 10:51:49 -0400, Boom Stick a écrit_:
> Searching Google I cant seem to get the syntax correct.
>
> Looking to run conditions on the output of awk:
>
> #!/bin/ksh
> #set -x
>
> echo "Enter the instance name"
> read opt
> echo "what day"
> read x
> grep COMMAND=/etc/init.d/$opt /var/log/secure | awk '{if ( $x = $2)
> print $1,$2,$3,$6,$14,$15,$16,$17; else
> print "please check the day you entered"}'
>
> I want to see who is running sudo on init.d commands but it only
> prints the value of $x.
Mind you pass the variable first :
awk -vMylocalAwkX=$x '{awk code...}'
is the usual form, you may find some fun in ARGV too but ...
| |
| Ed Morton 2005-04-14, 3:55 pm |
|
Boom Stick wrote:
> Searching Google I cant seem to get the syntax correct.
>
> Looking to run conditions on the output of awk:
>
> #!/bin/ksh
> #set -x
>
> echo "Enter the instance name"
> read opt
> echo "what day"
> read x
> grep COMMAND=/etc/init.d/$opt /var/log/secure | awk '{if ( $x = $2)
> print $1,$2,$3,$6,$14,$15,$16,$17; else
> print "please check the day you entered"}'
>
> I want to see who is running sudo on init.d commands but it only
> prints the value of $x.
No need for grep AND awk:
awk -vx="$x" -vpat="COMMAND=/etc/init.d/$opt" '$0 ~ pat {
if (x == $2) print $1,$2,$3,$6,$14,$15,$16,$17
else print "please check the day you entered"}' /var/log/secure
Regards,
Ed.
| |
| Kenny McCormack 2005-04-14, 3:55 pm |
| In article <qk0t511l6chl26q7o0r9qm1q5rtbtv6ffp@4ax.com>,
Boom Stick <bumstickitynospam@cox.net> wrote:
>Searching Google I cant seem to get the syntax correct.
>
>Looking to run conditions on the output of awk:
>
>#!/bin/ksh
>#set -x
>
>echo "Enter the instance name"
>read opt
>echo "what day"
>read x
>grep COMMAND=/etc/init.d/$opt /var/log/secure | awk '{if ( $x = $2)
> print $1,$2,$3,$6,$14,$15,$16,$17; else
> print "please check the day you entered"}'
>
>I want to see who is running sudo on init.d commands but it only
>prints the value of $x.
Try posting in comp.unix.shell. Totally OT here.
|
|
|
|
|