Solved

Output awk to route delete

Posted on 1998-12-29
7
551 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
Independent Software Vendors: 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

Title # Comments Views Activity
Generic progress indicator 6 121
format the code in java 6 117
scoreUp challenge 14 74
Example code 13 43
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.

738 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