有关于shell中的option的项目
需求:
./auto_reboot.sh 1 nncase_face
1. 判断是否存在 /etc/init.d/run.sh_auto_back
是:
已经开启,不用做其他操作
否:
cp run.sh run.sh_auto_back
run.sh 加入内容或脚本
0. 判断是否存在 /etc/init.d/run.sh_auto_back
是:
mv run.sh_auto_back run.sh
否:
不用做其他操作
此脚本从/etc/init.d/rc.sysinit调用
分析:
1.当系统reboot重启过程中,会默认开启单摄(执行脚本:./v4l2_drm.out -f video_drm_1080x1920.conf -e 1)
2.ps -ef |grep v4查到其pid,并杀掉
3.sleep 10s
4.开启双摄(nncase、AI demo、多路视频播放都按照1~4的步骤来进行)
auto_reboot.sh
#!/bin/sh # 说明: 开机后自动执行reboot重启 # 结束后会等待10秒,然后自动重启,在等待中按ctrl+c可以结束自动重启 #echo -e "执行 --------- \033[46m ./v4l2_drm.out -f video_drm_1080x1920.conf -e 1 \033[0m -------------" camera=/root/sd/p3/switch_drm.sh nncase_face=/root/sd/p3/nncase_face_drm.sh nncase_object=/root/sd/p3/nncase_object_drm.sh face_detect=/root/sd/p3/facedetect_drm.sh if [ "$1" = "0" ]; then # 取消自动重启 if [ ! -f /etc/init.d/run.sh_autoreboot ]; then echo "没有设置自动重启,不需要取消!" else #sed -i '/wpa_supplicant/{n;N;d}' /etc/init.d/run.sh mv -f /etc/init.d/run.sh_autoreboot /etc/init.d/run.sh fi echo "已取消开机重启" fi if [ "$1" = "1" ]; then # 设置开机自动重启 if [ -f /etc/init.d/run.sh_autoreboot ]; then # 已经设置了开机启动 echo "已设置开机启动" else cd /etc/init.d cp -f run.sh run.sh_autoreboot echo while [ -n "$1" ] do case "$1" in camera) sed -i "/wpa_supplicant/a $camera" /etc/init.d/run.sh;; nncase_face) sed -i "/wpa_supplicant/a $nncase_face" /etc/init.d/run.sh;; nncase_object) sed -i "/wpa_supplicant/a $nncase_object" /etc/init.d/run.sh;; face_detect) sed -i "/wpa_supplicant/a $face_detect" /etc/init.d/run.sh;; esac shift done sync fi echo "现在执行reboot即可自动重启" fi
修改版
#!/bin/sh # 说明: 开机后自动执行reboot重启 # 结束后会等待10秒,然后自动重启,在等待中按ctrl+c可以结束自动重启 #echo -e "执行 --------- \033[46m ./v4l2_drm.out -f video_drm_1080x1920.conf -e 1 \033[0m -------------" camera=/root/sd/p3/switch_drm.sh nncase_face=/root/sd/p3/nncase_face_drm.sh nncase_object=/root/sd/p3/nncase_object_drm.sh face_detect=/root/sd/p3/facedetect_drm.sh if [ "$1" = "0" ]; then # 取消自动重启 if [ ! -f /etc/init.d/run.sh_autoreboot ]; then echo "没有设置自动重启,不需要取消!" else #sed -i '/wpa_supplicant/{n;N;d}' /etc/init.d/run.sh mv -f /etc/init.d/run.sh_autoreboot /etc/init.d/run.sh fi echo "已取消开机重启" exit fi if [ "$1" = "1" ]; then # 设置开机自动重启 if [ -f /etc/init.d/run.sh_autoreboot ]; then # 已经设置了开机启动 echo "已设置开机启动" exit else cd /etc/init.d cp -f run.sh run.sh_autoreboot fi fi if [ -n "$2" ];then case "$2" in camera) sed -i "/wpa_supplicant/a $camera" /etc/init.d/run.sh;; nncase_face) sed -i "/wpa_supplicant/a $nncase_face" /etc/init.d/run.sh;; nncase_object) sed -i "/wpa_supplicant/a $nncase_object" /etc/init.d/run.sh;; face_detect) sed -i "/wpa_supplicant/a $face_detect" /etc/init.d/run.sh;; esac sync echo "现在执行reboot即可自动重启" fi
nncase_face.sh
#!/bin/sh [ -n "$1" ] && run_time=$1 || run_time=10 function kill_demo() { pid=$(ps -ef|egrep '(encode_app|isp-tuningd|ffmpeg|v4l2_drm|retinaface_mb_320|object_detect_demo|face_alignment|face_detect|face_expression|face_landmarks|face_recog|hand_image_classify|head_pose_estimation|license_recog|object_detect|open_pose|person_detect|self_learning|simple_pose)' | grep -v 'grep'| awk '{print $1}') [ -n "$pid" ] && kill -2 $pid kill -9 $pid &>/dev/null # 如果kill -2 不能结束用kill -9 结束 } kill_demo echo -e "执行 --------- \033[46m ./retinaface_mb_320_bf16.sh \033[0m -------------" cd /app/ai/shell ././retinaface_mb_320_bf16.sh & sleep $run_time ; kill_demo; sleep 2 echo -e "执行 --------- \033[46m ./retinaface_mb_320_uint8.sh \033[0m -------------" ./retinaface_mb_320_uint8.sh & sleep $run_time ; kill_demo; sleep 2
...其他脚本类似
提示个工具化的知识点:
#! /bin/bash echo while [ -n "$1" ] do case "$1" in camera) sed -i "/wpa_supplicant/a $camera" /etc/init.d/run.sh;; nncase_face) sed -i "/wpa_supplicant/a $nncase_face" /etc/init.d/run.sh;; nncase_object) sed -i "/wpa_supplicant/a $nncase_object" /etc/init.d/run.sh;; face_detect) sed -i "/wpa_supplicant/a $face_detect" /etc/init.d/run.sh;; esac shift done
用于完成 ./test 第一个参数 第二个参数

浙公网安备 33010602011771号