Fine tune this perl script to add router


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Fine tune this perl script to add router
# 1  
Old 02-15-2011
Fine tune this perl script to add router

Hi,

I have this routine that reads a microsoft dhcp.netsh dump. Where it finds optionvalue 3 STRING "0.0.0.0"

Replace it with the router IP based on the network

Code:
!/usr/bin/perl
while ( <> )
{
    if ( /\# NET / ) { $net = $'; $net =~ s/[\r\n]//g; }
    else
    {
        s/set optionvalue 3 STRING \"0.0.0.0\"/set optionvalue 3 STRING \"$net\"/;
    }
    print $_;
}

What I need it to do is read an input file where
Code:
# NET ---
# NET 128.163.112.0/24
# WARN - option missing a value (router-discovery)
# WARN - option missing a value (mask-supplier)
Dhcp Server 1.1.1.1 add scope 128.163.112.0 255.255.255.0 "128.163.112.0-24-pot-ob11-rp" ""
Dhcp Server 1.1.1.1 Scope 128.163.112.0 set optionvalue 6 STRING "128.163.3.10" "128.163.1.6"
Dhcp Server 1.1.1.1 Scope 128.163.112.0 set optionvalue 3 STRING "0.0.0.0"
Dhcp Server 1.1.1.1 Scope 128.163.112.0 set optionvalue 51 STRING "345600"
Dhcp Server 1.1.1.1 Scope 128.163.112.0 set optionvalue 44 STRING "128.163.2.77" "128.163.1.77"

to be fixed as such for this case

Code:
# NET ---
# NET 128.163.112.0/24
# WARN - option missing a value (router-discovery)
# WARN - option missing a value (mask-supplier)
Dhcp Server 1.1.1.1 add scope 128.163.112.0 255.255.255.0 "128.163.112.0-24-pot-ob11-rp" ""
Dhcp Server 1.1.1.1 Scope 128.163.112.0 set optionvalue 6 STRING "128.163.3.10" "128.163.1.6"
Dhcp Server 1.1.1.1 Scope 128.163.112.0 set optionvalue 3 STRING "128.163.112.1"
Dhcp Server 1.1.1.1 Scope 128.163.112.0 set optionvalue 51 STRING "345600"
Dhcp Server 1.1.1.1 Scope 128.163.112.0 set optionvalue 44 STRING "128.163.2.77" "128.163.1.77"


What the script is doing:

Code:
# WARN - option missing a value (router-discovery)
# WARN - option missing a value (mask-supplier)
Dhcp Server 1.1.1.1 add scope 128.163.1.0 255.255.255.128 "128.163.1.0-25-mcv-059-rp" ""
Dhcp Server 1.1.1.1 Scope 128.163.1.0 set optionvalue 6 STRING "128.163.3.10" "128.163.1.6"
Dhcp Server 1.1.1.1 Scope 128.163.1.0 set optionvalue 3 STRING "128.163.1.0"
Dhcp Server 1.1.1.1 Scope 128.163.1.0 set optionvalue 51 STRING "345600"
Dhcp Server 1.1.1.1 Scope 128.163.1.0 set optionvalue 44 STRING "128.163.2.77" "128.163.1.77"

Regards,

Last edited by pludi; 02-15-2011 at 04:43 AM..
# 2  
Old 02-15-2011
Code:
#!/usr/bin/perl
while ( <> )
{
    if ( /\# NET / ) { $net = $'; $net =~ s/[\r\n]//g; $net =~ s/\.0\/.*/.1/; }
    else
    {
        s/set optionvalue 3 STRING \"0.0.0.0\"/set optionvalue 3 STRING \"$net\"/;
    }
    print $_;
}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script works fine as a standalone script but not as part of a bigger script

Hello all, I am facing a weird issue while executing a code below - #!/bin/bash cd /wload/baot/home/baotasa0/sandboxes_finance/ext_ukba_bde/pset sh UKBA_publish.sh UKBA 28082015 3 if then echo "Param file conversion for all the areas are completed, please check in your home directory"... (2 Replies)
Discussion started by: ektubbe
2 Replies

2. Shell Programming and Scripting

Perl telnet to router run commands from file

I have a perl script that is called with a router name command list file and output file. The command file can be very large, up to 3k of commands. At first I dumped the command list file to an array and ran the entire file on the router and captured the output. It worked ok for a command list in... (1 Reply)
Discussion started by: numele
1 Replies

3. Shell Programming and Scripting

Tune my script

Hi ! My script read out data out of 144 files per day - every ten minutes a file with data. data-file WR030B 306.71 0 WR050B 315.13 0 WR120B 308.34 0 WV030B 3.52 0 WV050B 5.06 0 WV120B 6.65 0 TLUFT02B 8.60... (3 Replies)
Discussion started by: IMPe
3 Replies

4. Shell Programming and Scripting

Fine Tune - Huge files/directory - Purging

Hi Expert's, I need your assitance in tunning one script. I have a mount point where almost 4848008 files and 864739 directories are present. The script search for specific pattern files and specfic period then delete them to free up space. The script is designed to run daily and its taking around... (19 Replies)
Discussion started by: senthil.ak
19 Replies

5. Programming

SQL : Fine tune Insert by query

i would like to know how can i fine tune the following query since the cost of the query is too high .. insert into temp temp_1 select a,b,c,d from xxxx .. database used is IDS.. (1 Reply)
Discussion started by: expert
1 Replies

6. Solaris

Please tune my script for Solaris

I have very big log file around 2-3 GB in that it contians 24 hours log data. My work is extract only 5-5 data and count the patterns from them. I worte a script in linux and we're using that. sed -n "/2009 05:/,/2009 17:/p" trace.log | grep -f patterns.txt > temp.log while read string ;do... (5 Replies)
Discussion started by: senthil.ak
5 Replies

7. Cybersecurity

How to fine Tune and Harden the Linux kernel

Hi, As a a security audit, how can I proceed further with Fine tuning and Hardening the linux kernel... I am not sure with the steps how to proceed further... If i do some thing wrong, then its comes with the Kernel panic error. So, I am afraid, how to do the tuning with the kernel.. (1 Reply)
Discussion started by: gsiva
1 Replies

8. UNIX for Dummies Questions & Answers

Tune my logic of script

I have big log file, which contains the netstat output from my application server to a particular DB server. I aim is to plot a daily graph for this. Please find the sample log file below. @ - ........................................................... @ - Total number of connection to the ... (3 Replies)
Discussion started by: senthilkumar_ak
3 Replies

9. Shell Programming and Scripting

Perl telnet to cisco router and compare the ping ms

All Please help, i will telnet to router to obain the ping status and compare, if higher than normal latency, i will have further action.. if i do the telent and in perl script then .... e.g the result i obtain from the router will be =' Success rate is 100 percent (5/5), round-trip... (4 Replies)
Discussion started by: optimus
4 Replies

10. Shell Programming and Scripting

Script works fine until I | more

Hello all, This beats me. I have a script that executes some commands and redirects their output to some text files that I will parse. The commands are along the lines of: dsmadmc -id=admin -pa=admin -outfile=/home/tools/qlog.txt q log f=d If I just run the script it works. If I execute... (2 Replies)
Discussion started by: Skovian
2 Replies
Login or Register to Ask a Question