Notice me about server's IP address using github

来源:互联网 发布:hyperion数据库重构 编辑:程序博客网 时间:2024/05/17 13:06

1. Problem

The computing machine uses DHCP configuration, and it needs to be shutdown everyday. But I only want to login to it using ssh, rather than the native way. So I need to know its IP address.

2. Analysis

  • Autostart script is a good idea.
  • It needs to do two things:1. access to Internet; 2. tell me IP address
  • sendmail is a good tool. But when I use it, it often fails to send email to me.
  • github is an awesome tool.

3. Solution

1.Create a repository and add origin to github. Make sure you can git push without inputting username and password. My native repository is $HOME/.ipaddress
2.Create shell script named updateIP.sh in /etc/init.d/. Here is the content.

#!/bin/bash/etc/init.d/rjsupplicant.shsleep 10wget -q --tries=10 --timeout=20 --spider http://www.baidu.comif [[ $? -eq 0 ]]; then        echo "Online"        cd $HOME/.ipaddress         echo `ifconfig | grep -i "inet addr"` > readme         echo `date` >> readme        git add .         git commit -m "`date`"         git push origin masterelse        echo "Offline"fi
sudo chmod +x /etc/init.d/updateIP.sh

3.Make it autostart.

sudo vim /etc/xdg/autostart/updateIP.desktop
[Desktop Entry]Type=ApplicationName=updata IP using gitComment=Tell about IP address using githubExec=/etc/init.d/updateIP.shNoDisplay=false

Done.

4. Auto find ip address and use it to login

ip_file="`wget -qO- https://raw.githubusercontent.com/DuinoDu/ipaddress/master/readme`"dl_addr=$(echo $ip_file | grep -i 'inet addr'|cut -d : -f 2 | cut -d ' ' -f 1)echo $dl_addrssh -4CXv cv@$dl_addr
0 0
原创粉丝点击