起動時にプログラムスクリプトを自動起動(展開)

シェルスクリプトベース

Linux スクリプトを起動時に自動的に開始するためのいくつかの方法

システムの起動時にロードする必要がある構成ファイル

/etc/profile、/root/.bash_profile
/etc/bashrc、/root/.bashrc
/etc/profile.d/*.sh、/etc/profile.d/lang.sh
/etc/sysconfig/i18n、/etc /rc.local(/etc/rc.d/rc.local)

1. ブート ファイルを変更します: /etc/rc.local (または /etc/rc.d/rc.local)

1. rc.local ファイルを編集します
[root@localhost ~]# vi /etc/rc.local

2. rc.local ファイルを変更し、exit 0 の前に次のコマンドを追加します。保存して終了。
/etc/init.d/mysqld start # mysql が起動します
/etc/init.d/nginx start # nginx が
Supervisord を起動します -c /etc/supervisor/supervisord.conf # Supervisord が起動します
/bin/bash /server/scripts/ test .sh >/dev/null 2>/dev/null

3. 最後に、rc.local ファイルの実行権限を変更します
[root@localhost ~]# chmod +x /etc/rc.local
[root@localhost ~]# chmod 755 /etc/rc.local

2. 自分でシェルスクリプトを書く

記述したスクリプト (.sh ファイル) をディレクトリ /etc/profile.d/ に配置すると、このディレクトリ内のすべてのシェル スクリプトがシステムの起動後に自動的に実行されます。

脚本

#!/bin/bash
# detetction3d_zs为要杀死的进程名称
#echo "$1"
sudo ./detetction3d_zs

pid=`ps -ef | grep  'detetction3d_zs' | grep -v grep | grep -v bash | awk '{print $2}'`
 
echo "$pid"
 
if [ -n "$pid" ]
then
        echo "kill -9 pid:$pid"
kill -9 $pid
fi
sleep 9
echo "$pid"
#result = /home/nvidia/yolo/runs/detect/exp6
#https://ultralytics.com/assets/Arial.Unicode.ttf

conda activate p36
cd yolo
#python detect.py --weights yolov5s.pt --source /home/nvidia/Leador_storage/zs/xiaomayi/128G/test/data/video/result2last.avi
/home/nvidia/Leador_storage/zs/miniforge-pypy3/envs/p36/bin/python3 detect.py --weights yolov5s.pt --source 0

まずプログラム detect3d_zs を開始し、9 秒間スリープしてから、yolo 検出アルゴリズムを開始します。

おすすめ

転載: blog.csdn.net/qq_39523365/article/details/129714364