LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Obtain ip address and check for running process via Bash Script? (http://www.linuxquestions.org/questions/programming-9/obtain-ip-address-and-check-for-running-process-via-bash-script-330109/)

xconspirisist 06-03-2005 08:38 PM

Obtain ip address and check for running process via Bash Script?
 
Is it possible to check if a process is running, dump a 'true', or a 'false' to a file, then get the current, external ip address of the router, and dump that to a file too?

Many thanks.

anandt4u 06-03-2005 09:14 PM

http://howtos.linux.com/guides/abs-guide/procref1.shtml

hope its useful

thehkv 09-11-2008 02:23 AM

Quote:

Originally Posted by anandt4u (Post 1676602)
<cant post URL (first post) >
hope its useful

Link doesnt work anymore, can you please repost ??

Here's what i actually need : suppose i want my current ip address to be stored as a variable, then after some time, i store my now-current ip in some other variable, and then i want to compare these two through IF clause (i wonder if IF only compares strings and not numbers) . Is it possible ?
As you may have noticed, I'm new to linux bash, though I know windows batch programming pretty much - so if possible, please be elaborative. :)

Mr. C. 09-11-2008 02:27 AM

EDIT: ignore below. Response posted to wrong thread.

Code:

if [ $ip1 = $ip2 ] ; then
  echo SAME IP
else
  echo DIFFERENT IP
fi


thehkv 09-12-2008 07:14 AM

Thanks Mr. C.
Although that wasn't what i was asking for. What I'm asking is - how do you store your IP address in those $ip1 & $ip2 variables.

colucix 09-12-2008 07:30 AM

The link above was from the Advanced Bash Scripting Guide. You can find the latest version on The Linux Documentation Project, here. Regarding your specific issue, look at Command Substitution (chapter 11 in the above cited guide).

keefaz 09-12-2008 08:58 AM

For external IP, you could use:
Code:

#!/bin/bash

#file where to store IP
ipfile=/path/to/file

#get external IP
IP=$(curl http://www.whatismyip.com/automation/n09230945.asp)

#display IP
echo $IP

#get old IP
OLDIP=""
if [ -f "$ipfile" ]; then
  OLDIP=$(<$ipfile)
fi

#compare IPs
if [ "$IP" = "$OLDIP" ]; then
    echo "IPs match"
else
    echo "IPs don't match"
fi

#save new IP to the file
echo $IP > $ipfile


lipun4u 09-12-2008 10:10 AM

ifconfig eth0 | grep "inet addr" | cut -d":" -f2 | cut -d" " -f1

you can change the interface eth0 to eth1 or pppoe, etc

Mr. C. 09-12-2008 11:30 AM

Quote:

Originally Posted by thehkv (Post 3278175)
Thanks Mr. C.
Although that wasn't what i was asking for. What I'm asking is - how do you store your IP address in those $ip1 & $ip2 variables.

This is very peculiar. I have no idea how my post ended up in your thread. The response was meant for another question. Sorry.

keefaz 09-12-2008 12:45 PM

For the internal IP address, one could also use dig:
Code:

dig $HOSTNAME +short

thehkv 09-12-2008 02:18 PM

Quote:

Originally Posted by Mr. C. (Post 3278387)
This is very peculiar. I have no idea how my post ended up in your thread. The response was meant for another question. Sorry.

What's even funny is that the script you gave is exactly what I'm using - although it didn't answer just the part of my question which i wanted to know (which I now understand it never meant to).

Thanks keefaz for the whole code, with all the comments, very helpful.
I didn't have curl so I'm using lynx instead (yes, i wanted router's IP, not internal), which works equally good.

Once again, Thanks all. :)


All times are GMT -5. The time now is 04:42 AM.