嵌入式爱好者

5G断线重连

2022-9-27 10:43| 发布者: hai| 查看: 366| 评论: 0|原作者: hai

类目: 知识库  >  LS1012A/LS1043A/LS1046A系列产品     文档编号: 759

5G开机自启和断线重连(本次以FCU2201为例)

一、编辑脚本

  root@localhost:~# vi ./net.sh 
//脚本内容
#!/bin/bash
ping -c 2 8.8.8.8
if [ $? -eq 0 ]
then
echo "net alive" >> net.txt
       currTime=$(date +"%s") >> net.txt  //输出当前时间
       currTime=$(date +"%Y-%m-%d %T") >> net.txt
       echo $currTime >> net.txt
       
else
echo "/root/Net_Tools/quectel-CM &" >> /root/net.txt
/root/Net_Tools/quectel-CM &
#sleep 356d
fi
//赋予执行权限
root@localhost:~# chmod 777 ./net.sh

二、打开文件 /etc/crontab 并添加以下内容

  root@localhost:~# vi /etc/crontab
//文件内容
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user command
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
* *     * * *   root    /root/net.sh        
#  

添加完成之后重启开发板,看执行结果:

  root@localhost:~# ls
DI  net.sh  Net_Tools  net.txt
root@localhost:~# cat net.txt
net alive
2018-01-28 15:59:12
/root/Net_Tools/quectel-CM &
通过net.txt文件可以看出,网络是在线状态,如果不在线就会重新执行拨号脚本。

三、crontab命令介绍

1.命令功能

通过crontab 命令,我们可以在固定的间隔时间执⾏指定的系统指令或 shell script脚本。时间间隔的单位可以是分钟、⼩时、⽇、⽉、周及

2.常用命令参数

-e 编辑某个用户的crontab文件内容

  
root@localhost:~# crontab -e
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow   command

-l 显示某个用户的crontab文件内容

  
root@localhost:~# crontab -l
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow   command

-r 从/var/spool/cron⽬录中删除某个⽤户的crontab⽂件,如果不指定⽤户,则默认删除当前⽤户的crontab⽂件。(删除的是当前用户的所有定时任务)

  
root@localhost:~# ls /var/spool/cron/crontabs/root
/var/spool/cron/crontabs/root
root@localhost:~# crontab -r
root@localhost:~# ls /var/spool/cron/crontabs/root
ls: cannot access '/var/spool/cron/crontabs/root': No such file or directory

3.添加命令格式

minute: 表示分钟,可以是从0到59之间的任何整数。

hour:表示小时,可以是从0到23之间的任何整数。

day:表示日期,可以是从1到31之间的任何整数。

month:表示月份,可以是从1到12之间的任何整数。

week:表示星期几,可以是从0到7之间的任何整数,这里的0或7代表星期日。

command:要执行的命令,可以是系统命令,也可以是自己编写的脚本文件。

星号(*):代表每的意思,例如month字段如果是星号,则表示每月都执行该命令操作。

逗号(,):表示分隔时段的意思,例如,“1,3,5,7,9”。

中杠(-):表示一个时间范围,例如“2-6”表示“2,3,4,5,6”。


已解决

未解决

只是看看

QQ|小黑屋| 飞凌嵌入式 ( 冀ICP备12004394号-1 )

GMT+8, 2024-12-23 00:21

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

返回顶部