Home » Infrastructure » Linux » A small AWK problem
A small AWK problem [message #98851] Fri, 25 April 2003 04:09 Go to next message
Carl Pender
Messages: 1
Registered: April 2003
Junior Member
Hi, I have a Suse7.3 Linux PC acting as a gateway with an APache server running. I have a web site set up and what I want to do is allow only certain MAC addresses onto the network as I choose. I have a script that adds certain MAC addresses onto the network which works perfectly if I type the MAC address in manually but I need to automate it. I'll nearly there I think but I need a little help.

Here's the question I asked someone on
www.allexperts.com but unfortunately the person could
help me. Would you mind having a quick look at it and
if anything jumps to your mind you might let me know.

Here goes.... I have a acript that matches an IP
address with it's respective MAC address via the
'arp' command. The script is as follows:

#!/bin/bash

sudo arp > /usr/local/apache/logs/users.txt

sudo awk '{if ($1 =="157.190.66.1" print $3}'
/usr/local/apache/logs/users.txt
/usr/local/apache/cgi-bin/add

Here is a typical output from the arp command:

Address HWtype HWaddress Flags Mask Iface
157.190.66.13 ether 00:10:5A:B0:30:ED C eth0
157.190.66.218 ether 00:10:5A:5B:6A:11 C eth0
157.190.66.1 ether 00:60:5C:2F:5E:00 C eth0

As you can see I send this to a text file from which I
capture the MAC address for the respective IP address
("157.190.66.1") and then send this MAC address to
another script, called "add", which allows this MAC
address onto the network. This works perfectly when I
do it from a shell with the ip address typed in
maually.

My problem is that instead of actually typing in the
IP address (e.g "157.190.66.1"), I want to be able to
pipe the remote IP address of the user that is
accessing my web page at the time to this script as an
input.

In order to do this, I tried:

#!/bin/bash

read ip_address

sudo arp > /usr/local/apache/logs/users.txt
sudo awk '{if ($1 ==$ip_address) print $3}'
/usr/local/apache/logs/users.txt
/usr/local/apache/cgi-bin/add

But I'm afraid this doesn't work. I'm wondering where
I'm going wrong. I also tried putting quotations
around the variable $ip_address but that doesn't work
either. On my CGI script I have the line 'echo
"$RENOTE_ADDR" | /usr/local/apache/cgi/bin/change' to
pipe the ip address of the user. I know this is
working because if I include the line 'echo
"$ip_address"' in my script then the ip address is
echoed to the screen

I hope that I have made myself clear.

Basically what I want to know is how do you pipe somehting to a script and then use this within the script with awk, because I cant see why what I have done doesn't work.

Thanks

Carl
Re: A small AWK problem [message #98898 is a reply to message #98851] Thu, 10 July 2003 09:20 Go to previous message
Dan
Messages: 61
Registered: February 2000
Member
Try this, no promises ;)

does your script read arguements on the command line? e.g the $1 variable etc..

if so try:

xargs sudo awk '{if ($1 ==$ip_address) print $3}'
/usr/local/apache/logs/users.txt | /usr/local/apache/cgi-bin/add -

xargs should pass the output of your awk process to the add script as arguements..

HTH,

dan....
Previous Topic: Error in RMAN - Linux8.0 - Database-9i
Next Topic: oracle9i on Linux - Please help
Goto Forum:
  


Current Time: Fri Mar 29 04:01:23 CDT 2024