Obtain ip address and check for running process via Bash Script?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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.
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).
#!/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
Last edited by keefaz; 09-12-2008 at 08:07 AM.
Reason: forgot a "then" in if condition
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.