Need help to locate the particular line in lease block


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help to locate the particular line in lease block
# 1  
Old 03-04-2010
Data Need help to locate the particular line in lease block

Hi,
I need a help that i want to get the IP which is located at the first line of lease block, using mac id i have to get that ip....In between IP and MAC, the number of lines may vary.....i tried using Grep before 5 line and using awk i took the IP...But the scenario am facing is that number of lines in between IP and mac may change.

Any help is appreciated....


lease 172.19.134.240 {
starts 4 2010/03/04 11:00:26;
ends 4 2010/03/04 20:00:26;
tstp 4 2010/03/04 20:00:26;
binding state active;
next binding state free;
hardware ethernet 00:23:5e:05:1f:02;
uid "\000cisco-0023.5e05.1f02-Fa0.14";
option agent.circuit-id "eth0";
client-hostname "WAP";
}


Thanks in Advance
# 2  
Old 03-04-2010
Code:
# mac="00:23:5e:05:1f:02"
# awk -v mac=$mac '/lease/{ip=$2}$0 ~ mac{print ip}' logfile

# 3  
Old 03-04-2010
Code:
nawk -f  sm.awk -v mac='00:23:5e:05:1f:02' sm.txt

sm.awk:
Code:
BEGIN {
  FS=" |;"
}
/^lease/ {ip=$2;next}
/^hardware ethernet/ && $3==mac {print ip}

# 4  
Old 03-05-2010
MySQL

Thank you for your ideas!!!!Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Solaris 10- DHCP lease time increase

HI Admins, can anyone tell me how can I increase the lease time in Solaris 10. I want to use that dhcp address for 4 weeks. (2 Replies)
Discussion started by: snchaudhari2
2 Replies

2. Red Hat

DHCP lease problem

Hi frnds I am testing DHCP server on vmware.I have two REDHAT 9 vmware machine.DHCP is installed on one machine and second machine is using as a client .I have configured DHCP with Ip Address ,Mask and Gateway.But client machine is not getting ip address.When i type ifconfig command on client it... (6 Replies)
Discussion started by: Vaibhav.T
6 Replies

3. UNIX for Dummies Questions & Answers

remove duplicate entries from dhcp.lease

Hi, I have to parse the dhcp.lease file and have to keep the most recent entry and remove the rest and also the number of lines between any two leases might not always be the same. eg: lease 5.5.5.252 { starts Wed Jul 27 09:48:39 2011 ends Wed Jul 27 21:48:39 2011 tstp Wed Jul... (1 Reply)
Discussion started by: bitspradp
1 Replies

4. IP Networking

DHCP lease under SuSE is not working., limited at 10 minutes

Hi, I got a strange issue here: We are using ISC DHCP v4 which is default in Open SuSE 11.4. These two options 'default-lease-time' and 'max-lease-time' are set in all subnets, with values between 43200 (12 hours) to 518400 (144 hours). See partial dhcpd.conf below please. Now the lease... (5 Replies)
Discussion started by: aixlover
5 Replies

5. UNIX for Advanced & Expert Users

DHCP lease under SuSE is not working. Why?

Hi, I got a strange issue here: We are using ISC DHCP v4 which is default in Open SuSE 11.4. These two options 'default-lease-time' and 'max-lease-time' are set in all subnets, with values between 43200 (12 hours) to 518400 (144 hours). See partial dhcpd.conf below please. Now the lease time... (0 Replies)
Discussion started by: aixlover
0 Replies

6. AIX

Locate command

Hello to all, Can I use the "locate" command on AIX 5.3 like on Linux. If yes what packages should I install and where can I find them. Thanks, Enid (9 Replies)
Discussion started by: enux
9 Replies

7. Shell Programming and Scripting

Need help to copy the lease info block

Hi, am having a lease file which contains lots os lease info. In that i have to copy the whole block(shown below) by identifying the mac and change the IP according to the i/p. I have used like sed s/${ip_addr}/$ch_ip/g $temp_file | grep -B5 "${mac}" >> $persistent_file sed... (2 Replies)
Discussion started by: SMNK
2 Replies

8. Shell Programming and Scripting

Need to delete duplicate lease entry

Hi *, I need to delete duplicate lease entries in file according to MAC/IP. I'm having tempfile which contains many lease info and need to have one entry for each IP(not more than that), if it contains more than one entry for same set, need to be deleted that entry... EX: lease... (4 Replies)
Discussion started by: SMNK
4 Replies

9. Shell Programming and Scripting

Need to find a multiple line block and replace with a multiple line block

I would perfer to use cut and paste to do this but I can't find a GUI to do this with. What I want to do is to find a multiple line block of code like Exit Sub Log_Handler: then replace it with GoTo RSLogRtn Exit Sub Log_Handler: Basically it is just an insert, but I may want to... (8 Replies)
Discussion started by: Randem
8 Replies

10. UNIX for Dummies Questions & Answers

command locate.

Hi, I am aware of the command locate/slocate. But when I try to search the file which is located in /tmp. Its not able to get it. I tried by updating the database also with the command updatedb. Is there any consern that the command 'locate' dont check /tmp??? And I knew that locate is the... (5 Replies)
Discussion started by: praveen_b744
5 Replies
Login or Register to Ask a Question