LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 02-14-2008, 03:59 PM   #1
skids48
LQ Newbie
 
Registered: Feb 2008
Posts: 3

Rep: Reputation: 0
Bash and ip variable


I've been searchin all week and haven't been able to find an answer anyplace. What I want to do ic create a script that reads the IP form a computer and if the IP matches a certain range, move to that section of my script.

1. Read the PC IP address

2. If the IP is 10.3.3.x then move to that section of my script to
execute the drive mappings for that subnet (building)

3. If the IP is 10.10.10.x then move to that section of my script to
execute the drive mappings for that subnet (building)

I can get the IP address with ifconfig but I can't figure out how to
check it agianst the first three octects of an IP and move on
 
Old 02-14-2008, 07:27 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Lotsa choices:

Code:
addr="10.10.10.10"
case "$addr" in
 10.3.3.*) doSomething;;
 10.10.10.*) doSomethingElse;;
esac
Code:
addr="10.10.10.10"; addr=(${addr//./ })
if [ ${addr[0]} -eq 10 -a ${addr[1]} -eq 3 ]; then 
 doSomething
elif [ ${addr[0]} -eq 10 -a ${addr[1]} -eq 10 ]; then 
 doSomethingElse
fi
Code:
addr="10.10.10.10"
echo "$addr"|grep -q '10.3.[0-9]\{1,3\}.[0-9]\{1,3\}' && doSomething || doSomethingElse

Last edited by unSpawn; 02-14-2008 at 07:28 PM.
 
Old 02-15-2008, 07:02 AM   #3
skids48
LQ Newbie
 
Registered: Feb 2008
Posts: 3

Original Poster
Rep: Reputation: 0
Smile

Quote:
Originally Posted by unSpawn View Post
Lotsa choices:

Code:
addr="10.10.10.10"
case "$addr" in
 10.3.3.*) doSomething;;
 10.10.10.*) doSomethingElse;;
esac
Code:
addr="10.10.10.10"; addr=(${addr//./ })
if [ ${addr[0]} -eq 10 -a ${addr[1]} -eq 3 ]; then 
 doSomething
elif [ ${addr[0]} -eq 10 -a ${addr[1]} -eq 10 ]; then 
 doSomethingElse
fi
Code:
addr="10.10.10.10"
echo "$addr"|grep -q '10.3.[0-9]\{1,3\}.[0-9]\{1,3\}' && doSomething || doSomethingElse


Thank You!!! UnSpawn. Those look like exactly what I'm trying to do. I'm off to try them now.

Thank You Once again!!!!!!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
passing variable from bash to perl in a bash script quadmore Programming 6 02-21-2011 04:11 AM
bash, how to get variable name from variable Duudson Programming 6 01-06-2005 04:38 PM
bash month variable johniccp Linux - Newbie 1 12-06-2004 01:41 PM
Variable with bash pinkysioux Programming 6 04-15-2004 08:46 PM
how to escape variable in bash??? rabbate Linux - General 4 03-17-2004 08:04 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 02:33 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration