Sponsored Content
Top Forums Shell Programming and Scripting Grabbing variables and comparing Post 302225810 by kerpm on Sunday 17th of August 2008 04:27:00 AM
Old 08-17-2008
Grabbing variables and comparing

I have two computers with dynamic IP addresses and am using dyndns so that they are identifiable as the same computer even if their IPs change (we'll call them host1.dyndns.com and host2.dyndns.com). I also have a remote server which I would like to store my computers' IP addresses on. There is a file on my remote server which has the IPs that the two hostnames point to. So the file would look like this

111.111.111.111 #host1.dyndns.com
222.222.222.222 #host2.dyndns.com

I need a script that will run this command which gets the IPs of my computers:

/usr/bin/dig +short host1.dyndns.com | /usr/bin/tail -n 1
/usr/bin/dig +short host2.dyndns.com | /usr/bin/tail -n 1

Then compare the result (which is an IP address) to the file that I have described above. If the IP is different from the old one then remove that line and replace it with the new IP. I thought I could do this myself but grabbing the old IP and storing it in a variable and then comparing it to the new IP was beyond me. I don't even know if that is how you should do it. sed/awk is preferable but any language will do Smilie

Thanks in advance.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

comparing variables

I have searched and found a few threads that have dealt with this, but the examples I've tried haven't seemed to help. I am monitoring our database log for high checkpoints. I can parse out the checkpoint value which can be anywhere from zero into a 3 digit number. I set a variable to be the... (3 Replies)
Discussion started by: MizzGail
3 Replies

2. Shell Programming and Scripting

Comparing two variables

Script #!/bin/sh hardware=PC os=WindowsNET for i in `cat newservers` do x=`sudo /opt/openv/netbackup/bin/admincmd/bpplclients |grep $i |head -40 |grep $i|awk '{print $3;exit}'` if then echo "$i is already added" else echo "Need to add" fi done O/p in debug mode bash-2.05$... (3 Replies)
Discussion started by: rajip23
3 Replies

3. Shell Programming and Scripting

Comparing Variables in Perl

Hi. I have three arrays. @a=('AB','CD','EF'); @b=('AB,'DG',HK'); @c=('DD','TT','MM'); I want to compare the elements of the first two array and if they match then so some substition. I tried using the if statement using the scalar value of the array but its not giving me any output. ... (7 Replies)
Discussion started by: kamitsin
7 Replies

4. UNIX for Dummies Questions & Answers

comparing variables

im trying to compare ipaddresses. i loop through an array to see if the ip is already is in the array and if it is it should set a flag and then i wont add it to the array. but its just adding all the ipaddresses to the array if ] then ... (3 Replies)
Discussion started by: magnia
3 Replies

5. Shell Programming and Scripting

Comparing multiple variables

Hi! I've come up with a ksh-script that produces one or more lists of hosts. At the and of the script, I would like to print only those hosts that exists in all the lists. Ex. HOSTS="host1 host2 host3 host11" HOSTS="host1 host2 host4" HOSTS="host2 host11" HOSTS="host2 host5 host6 host7... (1 Reply)
Discussion started by: Bugenhagen
1 Replies

6. Shell Programming and Scripting

comparing variables in an if statement

#!/bin/bash #timetest TIMENOW="$(date)" T1=12:00:00 echo $TIMENOW >timenow cat timenow |cut -f4 -d' ' >time1 T2=$(sed -n "${1}p" time1) echo "T1 = " $T1 echo "T2 = " $T2 if then echo $T1 else echo $T2 fi I thought scripting was simple! So why does this script result in: T1 =... (4 Replies)
Discussion started by: habuchas
4 Replies

7. Shell Programming and Scripting

awk comparing variables

Is there a way to compare variables in a 'awk'? I've been trying for a while and can't figure it out. I'm guessing its not possible :/ VAR=Bob awk '$3 == $VAR { print $1 }' file.txt Regards Jikuu (4 Replies)
Discussion started by: Jikuu
4 Replies

8. Shell Programming and Scripting

Comparing two variables

I have a script like this. Just couldn't get the comparison part work. Any thought? thanks, #!/usr/bin/ksh -x STEP=`echo $(basename $0 .ksh) | tr "" ""` log=/skip.log while read LINE do if then echo `date`: STEP $STEP skipped by user >> $log exit 0 fi done < $1 echo... (0 Replies)
Discussion started by: ghostmic
0 Replies

9. Shell Programming and Scripting

Grabbing text between two lines with shell variables.

I would like to grab complex html text between lines using variables. I am running Debian and using mksh shell. Here is the part of the html that I want to extract from. I would like to extract the words 'to love,' and I would like to use the above and below lines as reference points. ... (3 Replies)
Discussion started by: bedtime
3 Replies

10. UNIX for Beginners Questions & Answers

Comparing 2 variables in UNIX

Hi, I have 2 variables as given below. How can i compare them and say its matching ? Appreciate your help VAR1=describe/read/write VAR2=read/write/describeThanks, Please use CODE tags as required by forum rules! (4 Replies)
Discussion started by: prince1987
4 Replies
INADYN(8)						    System management commands							 INADYN(8)

NAME
inadyn - a client for open DNS servers. SYNOPSIS
inadyn [-h | --help] [-u | --username username ] [-p | -- password password ] [-a | --alias[,hash] alias,hash [-a | --alias[,hash] another_alias,the_other_hash ... ]] [--input_file path/name ] [--ip_server_name server[:port] url ] [--dyndns_server_name[:port] server[:port] ] [--dyndns_system service ] [--proxy_server[:port] proxy[:port] ] [--update_period ms ] [--update_period_sec sec ] [--forced_update_period sec ] [--log_file path/name ] [--background] [--verbose level ] [--iterations iterations ] [--syslog] ] [--change_persona uid[:gid] ] DESCRIPTION
inadyn is a client for `open' name servers. That is, it let the user have an Internet recognized name for his machine by transferring to him some control over a name server that he does not manage. Some of the services that are offered by those open name servers are free of charge, and work even when the client machine does not have a static IP. The name servers that are supported by inayn are: http://www.dyndns.org <> and http://freedns.afraid.org <> Its basic operation is to periodically check whether the actual IP of the client machine is the same one that is recorded in the name server, and update the name server records when there is a mismatch. OPTIONS -h, --help Print a summary of the options to inadyn and exit. -u, --username The username, if applicable. This might be referred to as hash. -p, --password The password, if applicable. -a, --alias[,hash] A host name alias. This option can appear multiple times, for each domain that has the same IP. --input_file The file name that contains inadyn command options exactly as specified in the command line syntax (adds to those already present in the cmd line). The default configuration file name is '/etc/inadyn.conf'. It is looked at automatically if inadyn is called without any command line options. The format is as expected for a **NIX config the hash character is used to comment entire lines. Spaces are ingored. The long options may be specified without -- if placed at the beginning of the line. --ip_server_name[:port] url The client IP is detected by calling 'url' from this 'ip_server_name:port'. Defaults to checkip.dyndns.org:80 /. --dyndns_server_name[:port] The server that receives the update DNS requests. When no proxy is specified it is sufficient to set the dyndns_system so that the default servers will be taken. The option is useful for generic DynDNS services that support HTTP update. --dyndns_server_url name The update path inside the DynDNS server. --dyndns_system An optional DNS service. For http://www.dyndns.org <> the acceptable services are one of dyndns@dyndns.org, statdns@dyndns.org or custom@dyndns.org. There is only one acceptable service for http://freedns.afraid.org <> , which is default@freedns.afraid.org. Other services are: default@zoneedit.com, custom@http_svr_basic_auth. The default service is dyndns@dyndns.org, which is believed to be used by most users, at least initially. --proxy_server[:port] An http proxy server name and port. The default is none. --update_period How often the IP is checked. This value denotes millisecond (There are 1000 milliseconds in one second). The default is about 1 minute. The maximum is 10 days. --update_period_sec How often the IP is checked. Here the value denotes seconds. The default is about 1 minute. The maximum value is 10 days. --forced_update_period How often the IP should be updated even if it is not changed. The time should be given in seconds. --log_file The name, including the full path, of a log file. --background run in background. Output is sent to the UNIX syslog facilities or to a log file, if one was specified. --verbose Set the debug level, which is an integer between 0 to 5. --iterations Set the number of DNS updates. The default is 0, which means infinity. --syslog Explicitly sending the output to a syslog like file, such as /var/log/messages. --change_persona uid[:gid] After init changes user ID and group ID to the provided ones. This allows dropping unneeded [root] privileges after startup. TYPICAL USAGE
http://www.dyndns.org <> inadyn -u username -p password -a my.registered.name inadyn --username test --password test --update_period 60000 --alias test.homeip.net --alias my.second.domain inadyn --background -u test -p test --update_period 60000 --alias inarcis.homeip.net --alias my.second.domain --log_file inadyn_srv.log http://freedns.afraid.org <> inadyn --dyndns_service default@freedns.afraid.org -a my.registrated.name,hash_from_freedns inadyn --update_period 60000 --alias test.homeip.net,hash_for_host1 -a my.second.domain,hash2 --dyndns_system default@freedns.afraid.org The 'hash' should be extracted from the grab url batch file that can be downloaded from the site. A single hashed (base64 encoded) string is preferred upon a username and password pair, apparently to reduce the computational resources that is required on their side. Unfortu- nately the hash can not be computed by inadyn because it requires the index to the username record in the freedns database, which is not known. The simplest solution seems to be a copy&paste action from the grab url batch file offered on their website. When the batch file looks is like graburl http://freedns.afraid.org/dynamic/update.php?YUGIUGSEIUFGOUIHEOIFEOIHJFEIO= the hash string, which is what the user should copy and paste, is the string that begins right after the '?' character and ends with the end of line. This string shell be used as the username in inadyn command. When the user has several names then each name should be fol- lowed with that name hash string. OUTPUT
inadyn prints a message when the IP is updated. If no update is needed then by default it prints a single '.' character, unless --verbose is set to 0. Therefore, unless --verbose is set to 0, the log file will contains lot of dots. When the connection goes down it could be that inadyn will print some error messages. Those are harmless and should be followed by 'OK' messages after the connection is back up. Signals Any of the SIG_HUP, SIG_INT, SIG_QUIT will cause inadyn to terminate gracefully. SEE ALSO
Other manual pages The syntax of the optional configuration file is given by inadyn.conf(5). Internet resources Inadyn 's home page is http://inadyn.ina-tech.net. <> AUTHOR
inadyn was written by Narcis Ilisei, <inarcis2002@hotpop.com>. This manual page was written by Shaul Karl, <shaul@debian.org>, for the Debian GNU/Linux system, based on the readme.html file that is found in the source. Linux applications October, 2004 INADYN(8)
All times are GMT -4. The time now is 09:33 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy