当前位置:网站首页>shell 脚本 失败自动重复执行
shell 脚本 失败自动重复执行
2022-07-26 10:43:00 【aLLLiyyy】
在我们通过terminal 与linux系统交互的时候,经常会用到一些命令。然而有些命令是耗时操作的,比如我要举例的同步下载命令。我们不可能几个小时守在电脑旁边等着命令执行结束再进行一些操作。更可恨的是,命令有可能执行失败,这时候需要重新执行。我们需要一个能够接收到上一次命令的结果,然后根据结果做相应的处理,比如重新开始命令等等。
代码如下
#!/bin/bash
repo sync
echo "======sync starting======"
while(($? == 1))
do
sleep 3
du -sh >> abc.txt
echo "======sync failed,re sync starting====="
repo sync
done
这段代码里面开头 #! /bin/bash为指定脚本执行的解释器,靠哪种shell解释器去执行本shell脚本。
repo sync 为下载脚本,如果他执行错误,那么$?就读取到1,所以就进入一个循环,
du -sh >> abc.txt 这段代码就是写入当前文件夹的总容量数据到 abc.txt 这个文件要事先建立好。
然后再次执行 repo sync 直到他正常结束命令为止。
边栏推荐
- MD5 encryption
- 一文详解Nodejs中fs文件模块与path路径模块
- 从蚂蚁的觅食过程看团队研发(转载)
- Issue 7: how do you choose between curling up and lying flat
- C language callback function
- Uninstall Meizu app store
- [leetcode daily question 2021/5/8]1723. The shortest time to complete all work
- RT-Thread 学习笔记(六)--- 开启基于SPI Flash的elmfat文件系统(上)
- Sql Server 之SQL语句对基本表及其中的数据的创建和修改
- 1748.唯一元素的和
猜你喜欢

Issue 7: how do you choose between curling up and lying flat

在altium designer中禁用USBJATG
控制随机抽中几率 [ C# | Random ]

Mlx90640 infrared thermal imager temperature sensor module development notes (VI) pseudo color coding of infrared images

Successfully transplanted stemwin v5.22 on Shenzhou IV development board

Flutter编译报错 version of NDK matched the requested version 21.0.6113669. Versions available locally: 2
![[leetcode daily question 2021/4/23]368. Maximum divisible subset](/img/0b/32ca862963c842a93f79eaac94fb98.png)
[leetcode daily question 2021/4/23]368. Maximum divisible subset

.net5wtm (asp.net core) PgSQL unpacking operation

Disable usbjatg in Altium Designer

IAR sprintf 浮点 在UCOS 总格式化成0.0的问题
随机推荐
抽象工厂及其改进示例
工厂模式详解
使用Geoprocessor 工具
2021-08-12函数递归_和鹏哥学习C语言
RT thread learning notes (I) -- configure RT thread development environment
剑指Offer(四十九):把字符串转换成整数
RT thread learning notes (VII) -- open the elmfat file system based on SPI flash (middle)
11 handle "self assignment" in operator=
.net5wtm (asp.net core) PgSQL unpacking operation
[leetcode daily question 2021/4/23]368. Maximum divisible subset
flutter 背景变灰效果,如何透明度,灰色蒙板遮罩
Simple use of json-c Library -- converting JSON files to struct
第6期:大学生应该选择哪种主流编程语言
使用定位实现左中右布局,中间内容自适应
创建EOS账户 Action
MFC图片控件
Flutter报错 Incorrect use of ParentDataWidget When the exception was thrown, this was the stack:
Halcon模板匹配之Shape
Successfully transplanted stemwin v5.22 on Shenzhou IV development board
按二进制数中1的个数分类