linux开机启动

sendip

#!/bin/bash
#chkconfig: 2345 95 5
#description: script to send IP to someone

subject="IP address changed from last reboot"
sendto=your@mail.com
old_ip_file=/tmp/lan_ip_addrc
maildate_file=/tmp/maildata

send_ip_if_changed()
{
	host_name=`hostname`

	n=0
	timeout=600
	while true;do
		ip_addr=`ifconfig | grep "10.239" | awk '{ print $2 }' | cut -d":" -f2`
		if [ "${ip_addr}" != "" ]; then
			break
		fi
		n=$((n+1))
		sleep 1
		if [ "${n}" -gt "${timeout}" ]; then
			break
		fi
	done


	old_ip_addr=`cat ${old_ip_file}`
	if [ "${ip_addr}" != "${old_ip_addr}" ] ;then
		echo "Host ${host_name} changed IP to ${ip_addr}"
		echo "HostName=${host_name}" > ${maildate_file}
		echo "IPAddr=${ip_addr}" >> ${maildate_file}
		osinfo=`cat /etc/issue | sed '/^$/'d | head -1`
		#echo ${osinfo}
		echo "OS:${osinfo}" >> ${maildate_file}
		mail -s "${subject}" ${sendto} < ${maildate_file}
		rm -rf ${maildate_file}
		echo "${ip_addr}" > ${old_ip_file}
	fi
}

case $1 in
start)
	send_ip_if_changed
	;;
stop)
	echo "Nothing to do here"
	;;
restart)
	send_ip_if_changed
	;;
*)
	echo "Usage: $0 [start|stop|restart]"
	exit 1
;;
esac

exit 0

Ubuntu12.04

#!/bin/sh
### BEGIN INIT INFO
# Provides:          sendip
# Required-Start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the sendip daemon
# Description:       starts sendipusing start-stop-daemon
### END INIT INFO
得换个 LSB描述信息

sudo apt-get install mailutils
copy sendip script to /etc/init.d
cd /etc/init.d
sudo update-rc.d sendip defaults 95


CentOS6.5
copy sendip script to /etc/init.d
cd /etc/init.d
sudo chkconfig --add sendip
sudo chkconfig --level 2345 sendip on
sudo chkconfig --list | grep 'sendip'

也可以写在开机脚本 /etc/rc.d/rc.local 中


CentOS7

systemctl status rc-local.serives  #查看服务

systemctl enable rc-local.service #启动服务

把sendip脚本copy到/etc/init.d/init.d/ 文件夹下

在/etc/rc.local中添加下面

/etc/init.d/sendip start


SUSE11sp3  

SUSE 参考http://blog.csdn.net/rokii/article/details/6316443

copy sendip script to /etc/init.d
cd /etc/init.d

SUSE在 /etc/init.d 下的几个档案

1. boot.local –> 这个开机启动档案会在 rc5.d 前就有动作

2. halt.local –> 这个关机启动档案会在最后有动作

3. before.local –> 这个档案比较用不到所以不需多做解释

4. after.local –> 这个档案会在 rc5.d 之后有动作 , 就是最重要的开机启动档  没有的话 新建一个

 

上面第三及第四个档案预设是不存在的喔!!

当你看过 /etc/init.d/rc 这个档案就知道为什幺了

所以当你要使用第三或第四个档案时请自己建立, 就像妳写个 shell 一样很简单

vi after.local

#!/bin/bash
/etc/init.d/sendip start






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值