Bash执行命令显示进度和结果
2023-04-18 12:35:46 时间
文章目录
Bash执行命令显示进度和结果
1.代码
#!/bin/bash
#*************************************************************
#Author: yangruitao
#Date: 2021-02-01
#FileName: system_check.sh
#*************************************************************
#color.sh是我另一篇博客介绍的内容,感兴趣的朋友可以看看
. color.sh
process() {
pid=$1
i=0
while kill -0 $pid 2>/dev/null
do
i=$(((i+1) % 4))
printf "."
sleep 1
done
}
cmd_with_process() {
$1 &
pid=$!
process $pid &
wait $pid
if [ $? -eq 0 ]; then
echo_green "[ok]"
else
echo_red "[fail]"
fi
}
case $1 in
check_cmd)
shift
cmd_with_process "$*"
;;
*)
echo_blue "Usage $0 [check_services|check_cmd]"
echo_yellow "Forexample: $0 check_cmd sleep 10"
cmd_with_process "sleep 10"
;;
esac
2.测试效果
相关文章
- 卧槽!出了一个Python实时目标跟踪系统神器!
- 禁止 Python 子类覆盖父类方法
- Python表白代码:太秀了,用过的人都找到了对象...【满屏玫瑰盛开】
- Python中[-1]、[:-1]、[::-1]、[n::-1]、[:,:,0]、[…,0]、[…,::-1] 的理解
- 来了!Python 官方发布了整套的中文PDF 文档(共27本)
- EasyNVR优化多通道情况下程序关闭的速度
- 数字后端——ECO
- Python中for语句的使用方法
- Python中的排序函数--sorted()函数
- C 跌落神坛,Python 终登榜首 | TIOBE 10 月编程语言排行榜
- 给Python初学者推荐的IDE!
- 八个python免费自学网站一周熟练python(抓紧收藏)
- C 语言是“最环保”的编程语言
- 我用Python写了一个邮箱脚本发给班花,没想到事情闹大了...
- Python 中报错 “TypeError: ‘list‘ object is not callable”的解决方法
- 用Python实现自动发消息,自定义内容,太省事了!
- Python报错:PermissionError: [Errno 13] Permission denied
- Python 文件读取的4种方式
- Python列表元素为字典时,如何根据其中某个相同的键值进行元素合并
- Python取出字典中的值