Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Output awk to route delete

Posted on 1998-12-29
7
Medium Priority
?
555 Views
Last Modified: 2013-12-26
I need to write a shell script similar to the following:
netstat -rn | awk '{if ($3 = "UGHD") print | route delete $1, $2}'

I can't seem to get the command route delete to accept the output from awk correctly.  What's wrong with my syntax?
0
Comment
Question by:sharonp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 

Expert Comment

by:leandro
ID: 1295049
Try the folowing simple script:
#!/bin/ksh

netstat -m | awk '{if ($3 == "UGHD") print $1,":",$2 > "output.txt"}'
FIRST=`cut -d: -f1 output.txt`
SECOND=`cut -d: -f2 output.txt`

route delete $FIRST $SECOND

Good luck!
Leandro
0
 

Author Comment

by:sharonp
ID: 1295050
Leandro - I forgot to add the stipulation that we do not want to create an intermediate file in the process.  Why won't this command work?

netstat -rn | awk '"UGHD" {system (route delete $1 $2)}'
0
 
LVL 2

Expert Comment

by:seedy
ID: 1295051
`netstat -rn | awk '{ if ($3 == "UGHD") print "route delete",$1,$2 }'`
0
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 

Author Comment

by:sharonp
ID: 1295052
Thanks, Seedy - I tried your command, and it didn't work, but it did put us on the right track.  The use of commas following the route delete command causes an error that there are too many parameters.  Instead, we can use ..."route delete "$1" "$2}' - Unix liked that much better.  The actual command we added to our cron job ended up being: netstat -rn | awk '$3 = /UGHD/ { system("route delete "$1" "$2)}'.

Thanks for leading us in the right direction!
0
 

Author Comment

by:sharonp
ID: 1295053
Seedy - I need for you to post the answer so I can award the points!
0
 

Expert Comment

by:leandro
ID: 1295054
I think that solution proposed by seedy is not what sharonp wants.
The "route delete $1 $2" should be executed and not printed
My new solution is:

  for i in `netstat -m | awk ´{if ($3 == "UGHD") print $1":"$2}´`
  do
  FIRST=`echo $i | cut -d: -f1`
  SECOND=`echo $i | cut -d: -f2`
  route delete $FIRST $SECOND
  done

  This can be done on command line or script
  It´s simple but i think that works.

  Regards.
  Leandro.
0
 
LVL 2

Accepted Solution

by:
seedy earned 400 total points
ID: 1295055
sharonp,
>I tried your command, and it didn't work,
Umm... I don't think so.

Yes, if you have used the commas in the system function, it would not have worked - in my comment I have used the commas in the print statement.  But I also prefer your choice of using the system command over my command substitution/execution using back quote.

leandro,
> I think that solution proposed by seedy is not what sharonp wants.
> The "route delete $1 $2" should be executed and not printed
My suggesstion will execute and NOT print!  Please see the single back quotes - just as you have used in your "for" statement.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question