Linux 项目 shell 自动获取报告本机IP (1) | 通过shell 自动获取报告本机IP
由于电脑设置静态IP经常出现链接不上网络,动态IP又非常不方便,故有了这个想法并实现
原理:
Linux,包含PC机器,树莓派等,通过shell 自动获取报告本机IP | 通过 Mutt+Msmtp邮箱发送
此次使用树莓派3B实现步骤:
1.安装mutt 和 Msmtp
$ sudo apt -get install mutt //安装mutt,其他系统使用相应包管理 $ sudo apt-get install msmtp //安装msmtp,其他系统使用相应包管理
2.在/etc/Muttrc 下配置 mutt
## send ip to my mail set sendmail="/usr/bin/msmtp" set use_from=yes set realname=" Pi's address4 " set from = A 邮箱地址 set envelope_from=yes set crypt_use_gpgme = no
3.在/root/下 新建配置msmtp
account default host smtp.aliyun.com from your A mail @aliyun.com auth plain user your A mail @aliyun.com //A邮箱地址 password 密码 logfile ~/.msmtp.log // 存储日志
4.编写shell 获取 ip 并发送
# check network availability
while true
do
TIMEOUT=
SITE_TO_CHECK="www.163.com"
RET_CODE=`curl -I -s --connect-timeout $TIMEOUT $SITE_TO_CHECK -w %{http_code} | tail -n1`
if [ "x$RET_CODE" = "x200" ]; then
echo "Network OK, will send mail..."
break
else
echo "Network not ready, wait..."
sleep 1s
fi
done
# get the IP address of eth0
ETH0_IP_ADDR=` ifconfig wlan0 | sed -n "2,2p" | awk '{print substr($2,1)}' `
ECHO_IP=`ifconfig `
# send the Email
echo " test ifconfig wlan0:$ECHO_IP " | mutt -s "Current time:`date '+%F %T'` Raspiberry: $ETH0_IP_ADDR " B 邮箱地址
此时通过运行脚本便可发送 ip 到 B邮箱
5.添加开机自启动脚本就可实现 -->> 开机启动的多种方式设置
这次使用 更改/etc/rc.load 方式自启动,在exit0 上面添加内容
#!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. # Print the IP address _IP=$(hostname -I) || true if [ "$_IP" ]; then printf "My IP address is %s\n" "$_IP" fi #在exit0 上面添加内容 su pi -c "source /etc_sh/send_ip_mail.sh" //shell文件地址 exit
Linux 项目 shell 自动获取报告本机IP (1) | 通过shell 自动获取报告本机IP的更多相关文章
- Linux 设置IP,gate, 以及自动获取IP的方法
一.使用命令设置ubuntu的ip地址 1.修改配置文件blacklist.conf禁用IPV6: sudo vi /etc/modprobe.d/blacklist.conf 2.在文档最后添加 b ...
- VisualGDB系列9:配置VS直接通过SSH方式访问Linux项目
根据VisualGDB官网(https://visualgdb.com)的帮助文档大致翻译而成.主要是作为个人学习记录.有错误的地方,Robin欢迎大家指正. 本文介绍如何使用VS和VisualGDB ...
- VisualGDB系列6:远程导入Linux项目到VS中
根据VisualGDB官网(https://visualgdb.com)的帮助文档大致翻译而成.主要是作为个人学习记录.有错误的地方,Robin欢迎大家指正. 本文介绍如何将Linux机器上的Linu ...
- Atitit. 查找linux 项目源码位置
Atitit. 查找linux 项目源码位置 1. netstat -anp |grep 801 1.1. 1.3 启动关闭nginx3 1.2. 找到nginx配置文件4 1.3. ./etc/ ...
- Linux项目一
Linux项目一 引言: 这是我去年做的东西,一直没有时间整理,今天又要做一个基于这个项目的客户端与服务器版本. 以前我写的库文件中的函数耦合度很大,在一个函数中调用另一个函数,导致一无法拆开使用! ...
- VisualGDB:使用VS创建CMake Linux项目
转载地址:点击打开链接 根据VisualGDB官网(https://visualgdb.com)的帮助文档大致翻译而成.主要是作为个人学习记录.有错误的地方,Robin欢迎大家指正. 本文介绍如何使用 ...
- VisualGDB系列8:使用VS创建CMake Linux项目
根据VisualGDB官网(https://visualgdb.com)的帮助文档大致翻译而成.主要是作为个人学习记录.有错误的地方,Robin欢迎大家指正. 本文介绍如何使用VS来创建.构建.调试一 ...
- Linux基础知识之挂载详解(mount,umount及开机自动挂载)
Linux基础知识之挂载详解(mount,umount及开机自动挂载) 转载自:http://www.linuxidc.com/Linux/2016-08/134666.htm 挂载概念简述: 根文件 ...
- Linux项目部署发布
Linux项目部署发布 1.部署环境准备,准备python3和虚拟环境解释器,virtualenvwrapper pip3 install -i https://pypi.douban.com/sim ...
随机推荐
- 04-04 AdaBoost算法代码(鸢尾花分类)
目录 AdaBoost算法代码(鸢尾花分类) 一.导入模块 二.导入数据 三.构造决策边界 四.训练模型 4.1 训练模型(n_e=10, l_r=0.8) 4.2 可视化 4.3 训练模型(n_es ...
- Color Length UVALive - 5841
题文:见网页:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=sho ...
- Hadoop和YARN :map+shuffle+reduce走读
今天做了一个hadoop分享,总结下来,包括mapreduce,及shuffle深度讲解,还有YARN框架的详细说明等. v\:* {behavior:url(#default#VML);} o\:* ...
- 使用Prometheus监控SpringBoot应用
通过之前的文章我们使用Prometheus监控了应用服务器node_exporter,数据库mysqld_exporter,今天我们来监控一下你的应用.(本文以SpringBoot 2.1.9.REL ...
- HDU 6047 Maximum Sequence(贪心+线段树)
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=6047 题目: Maximum Sequence Time Limit: 4000/2000 MS (J ...
- python里怎么查看数据类型
python里怎么查看数据类型? python里可以通过type()函数来查看数据类型. Python 内置函数 Python 内置函数 Python type() 函数如果你只有第一个参数则返回对象 ...
- xshell rz commend not found
sudo apt-get install lrzsz 上传rz 下载sz
- CentOS6.6-MySQL报Curses library not found
cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.6.40 \> -DMYSQL_DATADIR=/application/mysql-5. ...
- [Tarjan系列] Tarjan算法与有向图的SCC
前面的文章介绍了如何用Tarjan算法计算无向图中的e-DCC和v-DCC以及如何缩点. 本篇文章资料参考:李煜东<算法竞赛进阶指南> 这一篇我们讲如何用Tarjan算法求有向图的SCC( ...
- SpringCloud学习--微服务架构
目录 微服务架构快速指南 SOA Dubbo Spring Cloud Dubbo与SpringCloud对比 微服务(Microservice)架构快速指南 什么是软件架构? 软件架构是一个包含各种 ...