Choose a gateway according to IP with awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Choose a gateway according to IP with awk
# 1  
Old 05-18-2010
Choose a gateway according to IP with awk

Hello, I have to make a script shell with awk function to choose the gateway to apply according to a "IP".

Ex:
Code:
10.121.66.125 10.121.63.122 10.122.68.122

If the adress is in network 10.121.66.x , i set Gateway=10.121.66.3
Or
If the adress is in network 10.121.62.x , i set Gateway=10.121.62.3

Thank you

Moderator's Comments:
Mod Comment Please format your posts next time a bit more eye friendly Smilie

Last edited by zaxxon; 05-18-2010 at 12:30 PM..
# 2  
Old 05-18-2010
Why awk? Like this?

Code:
$> LIST="10.121.66.125 10.121.63.122 10.122.68.122"
$> for A in $LIST; do echo Gateway=${A%.*}.3; done
Gateway=10.121.66.3
Gateway=10.121.63.3
Gateway=10.122.68.3

# 3  
Old 05-19-2010
Thanks a lot
# 4  
Old 05-19-2010
Code:
echo "10.121.66.125 10.121.63.122 10.122.68.122" |sed 's/\([0-9]*\.[0-9]*\.[0-9]*\.\)[0-9]*/\13/g'

Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Inconsistency between RedHat 6.5 global gateway and single gateway leads to loss of default gateway

Dear friends I use RedHat 6.5, which sets the gateway in the configuration file / etc / sysconfig / network as GATEWAY = 192.168.1.26, and the gateway in the configuration file / etc / sysconfig / network-scripts / ifcfg-eth11 as GATEWAY = 192.168.1.256. The two gateways are different.... (6 Replies)
Discussion started by: tanpeng
6 Replies

2. UNIX for Beginners Questions & Answers

Which Product to Choose?

Okay, I have an Asus A8NSLI board with an Athlon 64 and I dunno, maybe 8gig Ram and Windows has crashed for the last time so I've finally had enough and I'll make it a Unix machine. I have a new 1Tera drive and I'm all set to go. Which brand of Unix/Linux can you advise me to go for? The... (3 Replies)
Discussion started by: abrogard
3 Replies

3. UNIX for Dummies Questions & Answers

How to choose the RIGHT PID?

I can find a single PID and copy it to a variable (thanks to the forum), but I have a slightly tougher situation: When a user logs into our system, it creates 5 processes example: root 21160 3096 0 07:16 ? 00:00:00 sshd: cs113 cs113 21164 21160 0 07:16 ? 00:00:00... (3 Replies)
Discussion started by: Igrok
3 Replies

4. What is on Your Mind?

Which Tablet to Choose?

Currently in the process of looking for a tablet. Which one is best? Thanks Benjamin Mauerberger (9 Replies)
Discussion started by: hlinks12
9 Replies

5. Shell Programming and Scripting

choose y or n

Hi, I have written a choice based shell script some thing like this: if (y) execute code .... fi else if(n) terminating the problem with the above scripting is it will work as far as the options are y or n. but i want to reiterate the same code when the user inputs something else... (1 Reply)
Discussion started by: sunrexstar
1 Replies

6. Linux

GNUGK-How to setup static gateway to gateway routing

Dear Sir I am a newbie in the world of IP telephony. I have been working with Asterisk PBX (SIP) and Cisco Call Manager (MGCP) but now I am learning on how to work GNUGK for H.323 Gatekeeper. I am having a problem, configuring static call routing on GNUGK in the section ... (0 Replies)
Discussion started by: mfondoum
0 Replies

7. Shell Programming and Scripting

choose random text between constant string.. using awk?

Hallo I have maybe a little bit advanced request.... I need to choose one random part betwen %.... so i have this.. % text1 text1 text1 text1 text1 text1 text1 text1 text1 % text2 text2 text2 text2 text2 % text3 text3 text3 tetx3 % this choose text between % awk ' /%/... (8 Replies)
Discussion started by: sandwich
8 Replies

8. Programming

GCC: Choose my own linker

Hi, I do not use the default linker, and instead us another one and pass this argument -Wl,--dynamic-linker=<path to linker> to gcc when compiling. However, what happens if the linker is not under /lib and /lib64 and I am not able to create a symlink to the linker in /lib or /lib64 due to no... (2 Replies)
Discussion started by: Shompis
2 Replies
Login or Register to Ask a Question