- 积分
- 403
- 帖子
- N币
-
- 主题
- A币
-
- 注册时间
- 2015-9-24
- 最后登录
- 1970-1-1
|
本帖最后由 dsouth 于 2015-10-14 15:15 编辑
树莓派启用以后常常三两天就掉电重启一次,远程就再也连不上了,所以必须把nat123加到开机启动项里
按照官网给出的自动登录命令行不通,经过各种查找,最终还是在官方论坛找到了关于自动登录命令的替代解决方法,以这个方法为基础,终于完成了自机nat123开机自启动以及防掉线w
自启动的命令分成三层,local.rc执行,autostart脚本检测,expect脚本负责自动登录
一、写自动登录脚本expect
需要安装expect库
- sudo apt-get install expect
复制代码
新建脚本expect
写入以下内容
- #!/bin/bash
- username="填你的用户名"
- mypwd="填你的密码"
- cmdnat123="sudo mono /mnt/nat123linux.sh"
- expect -c"
- spawn $cmdnat123
- while { 1 } {
- expect {
- \"press any key to Continue\" {
- send \"\r\";
- }
- \"enter your nat123 username\" {
- send \"$username\r\";
- }
- \"enter your nat123 password\" {
- send \"$mypwd\r\";
- }
- send \"$mypwd\r\";
- }
- eof {
- send \"exit\r\";
- }
- }
- sleep 5;
- }
- "
- echo "Exit ..."
- sleep 5
复制代码
二、写检测脚本autostart
新建脚本文件autostart
- sudo nano /mnt/autostart.sh
复制代码
写入以下内容
- #!/bin/bash
- while true
- do
- ps aux | grep nat123 | grep -v grep
- if [ $? -eq 0 ];then
- sleep 600
- else
- sudo screen -S nat123 bash /mnt/expect.sh
- fi
- done
复制代码
三、写入开机启动项
编辑rc.local文件
在文件中间加入以下命令
- sudo bash /mnt/autostart.sh
- exit 0
复制代码
以后再也不怕掉线停电重启了w
参考文献:
nat123 linux版树霉派开机自动登录问题
nat123软件linux版开机自动登录启动示例
linux查看指定进程是否存在的脚本
几种常见的Shell
补充内容 (2016-6-2 16:22):
一、很多有问题的孩子都犯了以下两个错误中的一个
1、路径没写对,一定要看清楚每个批处理文件的位置,写下绝对路径
2、把一整条screen命令分开来写了,改写法可以,不要写一行screen再写一行bash,命令过不去的
补充内容 (2016-6-2 16:23):
二、rc.local文件中的命令可以改为以下格式,同样亲测可用w
sudo screen -dmS nt bash /me/autostart.sh |
评分
-
查看全部评分
|