Solved

Output awk to route delete

Posted on 1998-12-29
7
544 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Running shell command from Access 3 69
not able to insert into temp table 68 157
ffmpeg - "rtsp://...... Operation not permitted" 4 74
zeroFront challenge 7 80
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: 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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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.

863 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now