LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-28-2007, 12:49 PM   #1
ashesh0326
Member
 
Registered: Jan 2007
Distribution: Suse 10.0, FC 6
Posts: 93

Rep: Reputation: 15
Question How do I execute inadyn automatically during boot?


Friends,
I'm using dyndns.org to maintain my domain, and I use inadyn to keep my ip updated at that site (in case my link fails and my ip gets changed.)
I need to execute this at the command line after every reboot: inadyn -u <username> -p <password> -a ashesh.homeip.net
Given that I'm using FC 6, is there some place I can add this line so that it is executed automatically during bootup?
I'll really appreciate your help guys.
Thanks in advance,
Peace.
 
Old 03-28-2007, 01:14 PM   #2
Wynd
Member
 
Registered: Jul 2001
Distribution: Slackware 12
Posts: 511

Rep: Reputation: 32
Make a file called /etc/init.d/inadyn. Put this in it:
Code:
#!/bin/bash

case "$1" in
    start)
        inadyn -u <username> -p <password> -a ashesh.homeip.net
        ;;
    stop)
        (whatever commands you would use to stop the service)
        ;;
    reload|restart)
        $0 stop
        $0 start
        ;;
    *)
        echo "Usage: $0 start|stop|restart|reload"
        exit 1
esac
exit 0
Then run 'chkconfig inadyn' and 'service inadyn start'

Recommended reading: Create a Startup Script

Last edited by Wynd; 03-28-2007 at 01:17 PM.
 
1 members found this post helpful.
Old 03-29-2007, 07:23 AM   #3
ashesh0326
Member
 
Registered: Jan 2007
Distribution: Suse 10.0, FC 6
Posts: 93

Original Poster
Rep: Reputation: 15
Thank you!! It worked!
 
Old 02-06-2010, 03:47 AM   #4
vpablos
LQ Newbie
 
Registered: Oct 2008
Posts: 9

Rep: Reputation: 1
Inadyn does not work always by itself ... :-(

The problem with this solution is that inadyn does not detect if network is up, and sometimes it updates too much times and server disables your dynamic dns account.
This script works most of the times. It uses dhcp to know when ip has been updated.

#!/bin/sh

# FILE: dhcp3/dhclient-exit-hooks.d/zzz_public_ip

username=*fill in*
password=*fill in*
domain=*fill in*

dns_ip=`host "$domain" |sed -e 's/[A-Za-z. \-]* //'`
actual_ip=`wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//'`

function test_network_and_ip_on_dns() {
# Some times ping is not allowed :-(
# case `ping -qnc 1 google.com 2>&1` in
# *'100% packet loss'*)
# logger -t publicIP “The network is DOWN.”
# exit 0
# ;;
# esac

NETSTATUS=`wget -O - www.google.com 2>&1 | grep "Network is unreachable"`
# echo "NETSTATUS: $NETSTATUS."
if [ -z "$NETSTATUS" ] || [ "" == "$NETSTATUS" ]; then
test_ip_on_dns
else
logger -t publicIP “Network is DOWN.”
exit 0
fi
}

function test_ip_on_dns() {
if [ "$dns_ip" == "$actual_ip" ]; then
logger -t publicIP "Public IP is $actual_ip"
else
logger -t publicIP "Updating ip for domain $domain with username $username"
/usr/sbin/inadyn --iterations 1 -u $username -p $password -a $domain
logger -t publicIP "Public IP is $actual_ip"
fi
}

if [ -z "$reason" ]; then
test_network_and_ip_on_dns
exit 0
fi

case "$reason" in
MEDIUM|ARPCHECK|ARPSEND|NBI|BOUND|RENEW|REBIND)
logger -t publicIP "Updating public IP. Reason: $reason"
test_network_and_ip_on_dns
;;

EXPIRE|FAIL|TIMEOUT|PREINIT|REBOOT|STOP|RELEASE|*)
logger -t publicIP "Not updating. Reason: $reason"
;;
esac
 
Old 02-09-2010, 03:07 AM   #5
vpablos
LQ Newbie
 
Registered: Oct 2008
Posts: 9

Rep: Reputation: 1
Improved script.

The previous script some times hangs, specially when no internet connection is available (Network is unreachable or unable to resolve host address). This one takes care of these problems.

#!/bin/sh

# FILE: dhcp3/dhclient-exit-hooks.d/zzz_public_ip

username=*fill in*
password=*fill in*
domain=*fill in*

function test_network_and_ip_on_dns() {
# case `ping -qnc 1 google.com 2>&1` in
# *'100% packet loss'*)
# logger -t publicIP “The network is DOWN.”
# exit 0
# ;;
# esac

TEST=`wget --timeout=10 --tries=1 -O - www.google.com 2>&1`
TEST_1=`echo $TEST | grep "Network is unreachable"`
TEST_2=`echo $TEST | grep "unable to resolve host address"`
# echo "NETSTATUS: $NETSTATUS."

echo "test: $TEST"
echo "test_1: $TEST_1"
echo "test_2: $TEST_2"

# Check that network is up.
if [ ! -z "$TEST_1" ] || [ ! "" == "$TEST_1" ] || [ ! -z "$TEST_2" ] || [ ! "" == "$TEST_2" ]; then
logger -t publicIP “Network is DOWN.”
exit 0
fi

# Only if none of them is set then network is up.
test_ip_on_dns
}

function test_ip_on_dns() {
dns_ip=`host "$domain" |sed -e 's/[A-Za-z. \-]* //'`
actual_ip=`wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//'`


if [ "$dns_ip" == "$actual_ip" ]; then
logger -t publicIP "Public IP is $actual_ip"
else
logger -t publicIP "Updating ip for domain $domain with username $username"
/usr/sbin/inadyn --iterations 1 -u $username -p $password -a $domain
logger -t publicIP "Public IP is $actual_ip"
fi
}

if [ -z "$reason" ]; then
test_network_and_ip_on_dns
exit 0
fi

case "$reason" in
MEDIUM|ARPCHECK|ARPSEND|NBI|BOUND|RENEW|REBIND)
logger -t publicIP "Updating public IP. Reason: $reason"
test_network_and_ip_on_dns
;;

EXPIRE|FAIL|TIMEOUT|PREINIT|REBOOT|STOP|RELEASE|*)
logger -t publicIP "Not updating. Reason: $reason"
;;
esac
 
1 members found this post helpful.
Old 11-07-2011, 05:50 PM   #6
trendyserial
LQ Newbie
 
Registered: Nov 2011
Posts: 1

Rep: Reputation: Disabled
Init script for Inadyn

First of all you have to create (or edit) inadyn configuration file:

/etc/inadyn.conf

this way

Code:
# Basic configuration file for inadyn
#
# /etc/inadyn.conf
update_period_sec 600 # Check for a new IP every 600 seconds
username yourusername
password yourpassword
dyndns_system dyndns@dyndns.org
alias yourdomainname
background

Now put this code in /etc/init.d/inadyn

Code:
#!/bin/bash
case "$1" in
    start)
	if [ -f /tmp/inadyn.pid ]; then
		PID=$(cat /tmp/inadyn.pid)
		kill -0 ${PID} &>/dev/null
		if [ $? = 0 ]; then
			echo "Inadyn is already running."
		else
			/usr/sbin/inadyn
			pidof inadyn > /tmp/inadyn.pid
			PID=$(cat /tmp/inadyn.pid)
			kill -0 ${PID} &>/dev/null
			if [ $? = 0 ]; then
				echo "Inadyn started succesfully."
			else
				echo "Error starting Inadyn"
			fi
		fi
	else
		/usr/sbin/inadyn
		pidof inadyn > /tmp/inadyn.pid
		PID=$(cat /tmp/inadyn.pid)
		kill -0 ${PID} &>/dev/null
		if [ $? = 0 ]; then
			echo "Inadyn started succesfully."
		else
			echo "Error starting Inadyn"
		fi
        fi
        ;;
    stop)
	if [ -f /tmp/inadyn.pid ];then
		PID=$(cat /tmp/inadyn.pid)
		kill -0 ${PID} &>/dev/null
		if [ $? = 0 ]; then
			/bin/kill ${PID}
			kill -0 ${PID} &>/dev/null
			if [ $? = 1 ]; then
				echo "Inadyn stopped succesfully."
			else
				echo "Error stopping Inadyn"
			fi
		else
			echo "Inadyn is already stopped."
		fi
	else
		echo "Inadyn is already stopped."
	fi
        ;;
    reload|restart)
        $0 stop
        $0 start
        ;;
    *)
        echo "Usage: $0 start|stop|restart|reload"
        exit 1
esac
exit 0
Then create these two links to start and stop service at system boot and shutdown:
ln -s /etc/init.d/inadyn /etc/rc2.d/S03inadyn
ln -s /etc/init.d/inadyn /etc/rc0.d/K03inadyn

Last edited by trendyserial; 11-07-2011 at 06:23 PM.
 
Old 04-06-2013, 03:18 PM   #7
jepjep
LQ Newbie
 
Registered: Apr 2013
Posts: 3

Rep: Reputation: Disabled
runlevels and script

Hello trendyserial,

Thanks for the excellent solution.
I would add to it that "/etc/init.d/inadyn" script should be executable:

Code:
 # chmod a+x /etc/init.d/inadyn
and that instead of creating links manually, the "former" way to setup a script among runlevels would be (at least in Debian?):

Code:
 # update-rc.d inadyn defaults
update-rc.d: using dependency based boot sequencing
insserv: warning: script 'inadyn' missing LSB tags and overrides
vcasa:/etc# find ./rc* -iname "*inadyn*"
./rc0.d/K01inadyn
./rc1.d/K01inadyn
./rc2.d/S20inadyn
./rc3.d/S20inadyn
./rc4.d/S20inadyn
./rc5.d/S20inadyn
./rc6.d/K01inadyn




Quote:
Originally Posted by trendyserial View Post
First of all you have to create (or edit) inadyn configuration file:

/etc/inadyn.conf

this way

Code:
# Basic configuration file for inadyn
#
# /etc/inadyn.conf
update_period_sec 600 # Check for a new IP every 600 seconds
username yourusername
password yourpassword
dyndns_system dyndns@dyndns.org
alias yourdomainname
background

Now put this code in /etc/init.d/inadyn

Code:
#!/bin/bash
case "$1" in
    start)
	if [ -f /tmp/inadyn.pid ]; then
		PID=$(cat /tmp/inadyn.pid)
		kill -0 ${PID} &>/dev/null
		if [ $? = 0 ]; then
			echo "Inadyn is already running."
		else
			/usr/sbin/inadyn
			pidof inadyn > /tmp/inadyn.pid
			PID=$(cat /tmp/inadyn.pid)
			kill -0 ${PID} &>/dev/null
			if [ $? = 0 ]; then
				echo "Inadyn started succesfully."
			else
				echo "Error starting Inadyn"
			fi
		fi
	else
		/usr/sbin/inadyn
		pidof inadyn > /tmp/inadyn.pid
		PID=$(cat /tmp/inadyn.pid)
		kill -0 ${PID} &>/dev/null
		if [ $? = 0 ]; then
			echo "Inadyn started succesfully."
		else
			echo "Error starting Inadyn"
		fi
        fi
        ;;
    stop)
	if [ -f /tmp/inadyn.pid ];then
		PID=$(cat /tmp/inadyn.pid)
		kill -0 ${PID} &>/dev/null
		if [ $? = 0 ]; then
			/bin/kill ${PID}
			kill -0 ${PID} &>/dev/null
			if [ $? = 1 ]; then
				echo "Inadyn stopped succesfully."
			else
				echo "Error stopping Inadyn"
			fi
		else
			echo "Inadyn is already stopped."
		fi
	else
		echo "Inadyn is already stopped."
	fi
        ;;
    reload|restart)
        $0 stop
        $0 start
        ;;
    *)
        echo "Usage: $0 start|stop|restart|reload"
        exit 1
esac
exit 0
Then create these two links to start and stop service at system boot and shutdown:
ln -s /etc/init.d/inadyn /etc/rc2.d/S03inadyn
ln -s /etc/init.d/inadyn /etc/rc0.d/K03inadyn
 
Old 05-30-2013, 04:50 PM   #8
Jokesterfr
LQ Newbie
 
Registered: May 2013
Posts: 1

Rep: Reputation: Disabled
Do not forget to set the --background parameter, also please match the LSB tags requirements:

Code:
#!/bin/bash

### BEGIN INIT INFO
# Provides:          inadyn
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start daemon at boot time
# Description:       Enable service provided by daemon.
### END INIT INFO

inadyn=/usr/sbin/inadyn
conf=/etc/inadyn.conf

case "$1" in
    start)
	if [ -f /tmp/inadyn.pid ]; then
		PID=$(cat /tmp/inadyn.pid)
		kill -0 ${PID} &>/dev/null
		if [ $? = 0 ]; then
			echo "Inadyn is already running."
		else
			$inadyn --background --input_file $conf
			pidof inadyn > /tmp/inadyn.pid
			PID=$(cat /tmp/inadyn.pid)
			kill -0 ${PID} &>/dev/null
			if [ $? = 0 ]; then
				echo "Inadyn started succesfully."
			else
				echo "Error starting Inadyn"
			fi
		fi
	else
		$inadyn --background --input_file $conf
		pidof inadyn > /tmp/inadyn.pid
		PID=$(cat /tmp/inadyn.pid)
		kill -0 ${PID} &>/dev/null
		if [ $? = 0 ]; then
			echo "Inadyn started succesfully."
		else
			echo "Error starting Inadyn"
		fi
        fi
        ;;
    stop)
	if [ -f /tmp/inadyn.pid ];then
		PID=$(cat /tmp/inadyn.pid)
		kill -0 ${PID} &>/dev/null
		if [ $? = 0 ]; then
			/bin/kill ${PID}
			kill -0 ${PID} &>/dev/null
			if [ $? = 1 ]; then
				echo "Inadyn stopped succesfully."
			else
				echo "Error stopping Inadyn"
			fi
		else
			echo "Inadyn is already stopped."
		fi
	else
		echo "Inadyn is already stopped."
	fi
        ;;
    reload|restart)
        $0 stop
        $0 start
        ;;
    *)
        echo "Usage: $0 start|stop|restart|reload"
        exit 1
esac
exit 0

Last edited by Jokesterfr; 05-30-2013 at 05:01 PM.
 
Old 04-14-2015, 08:21 AM   #9
francwalter
LQ Newbie
 
Registered: Apr 2015
Posts: 1

Rep: Reputation: Disabled
Quote:
Originally Posted by Jokesterfr View Post
Do not forget to set the --background parameter, also please match the LSB tags requirements...
Not necessary if background is written in the config file, e.g..

Code:
background
period         60
startup-delay  60
forced-update  40320
cache-dir      /etc/inadyn
log_file       /var/log/inadyn.log
...
And there is an error in my configuration with this script, because in /etc/inadyn.pid there is not only the pid but also another:

Code:
root@NAS:/tmp# cat inadyn.pid
30507 30510
so if I would kill this, that won't go:
Code:
root@NAS:/tmp# kill -0 30507 30510
bash: kill: (30507) - No such process

Last edited by francwalter; 04-14-2015 at 08:24 AM.
 
  


Reply

Tags
automatically, boot, command, dyndns, fedora, inadyn, line


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
cron job to execute automatically lifegamer Linux - Newbie 2 09-16-2006 08:35 AM
is it possible to automatically execute a command when cd is mounted? LiquidSlumber Linux - Software 1 03-26-2006 01:18 AM
Execute an application automatically after startx gilan Debian 6 03-24-2005 10:34 PM
CRON Process Won't Execute Automatically Transition Linux - General 5 01-14-2005 03:51 PM
execute php script automatically? brandnewbie Linux - Newbie 1 08-14-2004 05:42 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:16 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