Solved

Output awk to route delete

Posted on 1998-12-29
7
550 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
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

679 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