Google Answers Logo
View Question
 
Q: Bash Script for Debian Linux ( No Answer,   3 Comments )
Question  
Subject: Bash Script for Debian Linux
Category: Computers > Programming
Asked by: agkerr-ga
List Price: $20.00
Posted: 20 Apr 2006 20:51 PDT
Expires: 20 May 2006 20:51 PDT
Question ID: 721180
I would like a bash script for Debian Linux that executes a simple
if/then relationship based on the machine's IP address, such as:

If the machine's ip address is 192.168.1.200, then run "program
command line, option a"

There are 7-10 machines/ip addresses
Answer  
There is no answer at this time.

Comments  
Subject: Re: Bash Script for Debian Linux
From: mootothemax-ga on 21 Apr 2006 09:17 PDT
 
Would something like this do the job?

ifconfig lists interfaces set up on the machine, along with their ip
addresses. Here I'm just looping through all interfaces and checking
what ip addresses are assigned.

#!/bin/sh
for foo in $(/sbin/ifconfig | grep "inet addr:" | sed -e 's/addr://g'
| awk '{print $2}'); do
        if [[ $foo = "127.0.0.1" ]];
        then
                //enter command to run
        elif [[ $foo = "127.0.0.2" ]];
        then
                //enter another command
        fi
done
Subject: Re: Bash Script for Debian Linux
From: mootothemax-ga on 21 Apr 2006 09:18 PDT
 
Argh, formatting - the for foo in [...] | awk... bit should all be on
one line, next line should begin if [[$foo ...
Subject: Re: Bash Script for Debian Linux
From: agkerr-ga on 21 Apr 2006 20:08 PDT
 
This looks promising - I'll give  it a spin on Monday and let you know

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy