Need help to copy the lease info block


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help to copy the lease info block
# 1  
Old 03-05-2010
Data 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
Code:
 
sed s/${ip_addr[i]}/$ch_ip/g $temp_file | grep -B5 "${mac[$i]}" >> $persistent_file
sed s/${ip_addr[i]}/$ch_ip/g $temp_file | grep -A4 "${mac[$i]}" | grep -v "${mac[$i]}" >> $persistent_file

above lines are in for loop

here i grep using before and after option, but now the lines in lease info may vary....
Code:
lease 172.19.134.239 {
  starts 3 2010/02/10 04:59:07;
  ends 3 2010/02/10 13:59:07;
  ----------------------
 ---------------------- (No of lines which may vary in between   
 ---------------------    automatically thro dhcpd)
 -----------------------
  binding state active;
  next binding state free;
  hardware ethernet 00:1d:45:56:b0:e2;
  uid "\000cisco-001d.4556.b0e2-Fa0.14";
  option agent.circuit-id "eth0";
  client-hostname "WAP";
}

I need a solution to copy the lease info.

Any help is appreciated!!!
Thanks in advance

Last edited by Scott; 03-05-2010 at 02:10 AM.. Reason: Code tags
# 2  
Old 03-05-2010
Better you clearly define what your input file contains and what output you're expecting.
# 3  
Old 03-05-2010
Code:
Input: ./xxx.sh 4 00:23:5e:04:4a:20/1/230 00:1d:45:56:b0:e2/2/239 00:19:06:eb:0a:98/3/238 00:ff:ff:ff:ff:ff/4/237

i need to copy the contents of lease info which contains the MAC am passing as input(carried out thro for loop).and have to change the IP according to the i/p given.

For ExampleSmilieconsider above input)

Iteration 1:
check for 00:23:5e:04:4a:20 which is stored in mac[0]
and consider original lease file contains IP as .237 for this MAC,

Now i have to find this mac[0] in the lease info and and update the IP as .240 according to the value passing after MAC(ie.,1 in first case)


i have sort out how to find the particular IP in case of variable number of lines between IP and MAC..


Solution Needed:

update the IP using MAC id and copy the contents of that changed lease info to some file.

i used grep option "before" and "after" to copy the lines, sed to change the IP.....case is now that lines are variable....


Code:
sed s/${ip_addr[i]}/$ch_ip/g $temp_file | grep -B5 "${mac[$i]}" >> $persistent_file
sed s/${ip_addr[i]}/$ch_ip/g $temp_file | grep -A4 "${mac[$i]}" | grep -v "${mac[$i]}" >> $persistent_file


Last edited by Scott; 03-05-2010 at 02:14 AM.. Reason: Code tags please...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to copy certain info from several directories

Hi, I am writing a script to copy certain file name in txt file . It is working fine if I provide a single directory name (for example "/eos/uscms/store/user/pooja04//analysis2012/525/data/doubleele/2012/datav1/" ) where those specific files are present ending with *root . But I want to modify... (14 Replies)
Discussion started by: nrjrasaxena
14 Replies

2. 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

3. 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

4. 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

5. Shell Programming and Scripting

How to extract the day of the year and use that info to copy a file remotely

Hello, Thank you in advance for helping a newbie who is having great trouble with this simple task. I'm allowed to copy one file remotely each night due to bandwidth restrictions. A new file gets generated once a day, and I need to copy the previous day's file. Here is what I'd like to do:... (1 Reply)
Discussion started by: tmozdzen
1 Replies

6. 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

7. 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

8. Shell Programming and Scripting

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... (3 Replies)
Discussion started by: SMNK
3 Replies

9. 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

10. UNIX for Dummies Questions & Answers

Copy and keep owner info

I need to copy all fiels and directories to another locathon and keep the owner info and rights. I tried cp -r - p * /newdir No good. (5 Replies)
Discussion started by: aarono
5 Replies
Login or Register to Ask a Question