#!/bin/sh for i in `seq 1 10` do echo -n "[`date '+%Y/%m/%d %T'`] $i kick allalone.sh" sh ./allalone.sh & sleep 1 done #!/bin/sh # 自身が起動していたら終了 if [ $$ != `pgrep -fo $0` ]; then echo "[`date '+%Y/%m/%d %T'`] myself is already running. exit myself." exit 1 fi # debug code echo "[`date '+%Y/%m/%d %T'`] hoge 1st" sleep 3 exit 0 ekaneko@bibian ~/work/allalone % sh kick_allalone.sh [2014/05/29 15:11:55
![シェルスクリプトで二重起動防止 - Qiita](https://cdn-ak-scissors.b.st-hatena.com/image/square/b6b55bed3f9fc9139eec5eddd984855857537c05/height=288;version=1;width=512/https%3A%2F%2Fqiita-user-contents.imgix.net%2Fhttps%253A%252F%252Fcdn.qiita.com%252Fassets%252Fpublic%252Farticle-ogp-background-412672c5f0600ab9a64263b751f1bc81.png%3Fixlib%3Drb-4.0.0%26w%3D1200%26mark64%3DaHR0cHM6Ly9xaWl0YS11c2VyLWNvbnRlbnRzLmltZ2l4Lm5ldC9-dGV4dD9peGxpYj1yYi00LjAuMCZ3PTk3MiZoPTM3OCZ0eHQ9JUUzJTgyJUI3JUUzJTgyJUE3JUUzJTgzJUFCJUUzJTgyJUI5JUUzJTgyJUFGJUUzJTgzJUFBJUUzJTgzJTk3JUUzJTgzJTg4JUUzJTgxJUE3JUU0JUJBJThDJUU5JTg3JThEJUU4JUI1JUI3JUU1JThCJTk1JUU5JTk4JUIyJUU2JUFEJUEyJnR4dC1hbGlnbj1sZWZ0JTJDdG9wJnR4dC1jb2xvcj0lMjMyMTIxMjEmdHh0LWZvbnQ9SGlyYWdpbm8lMjBTYW5zJTIwVzYmdHh0LXNpemU9NTYmcz03NjViMTcyYzlkYzllNjVjZTgwMDg1MzMwMjM4OWYzYg%26mark-x%3D142%26mark-y%3D57%26blend64%3DaHR0cHM6Ly9xaWl0YS11c2VyLWNvbnRlbnRzLmltZ2l4Lm5ldC9-dGV4dD9peGxpYj1yYi00LjAuMCZoPTc2Jnc9NzcwJnR4dD0lNDBUYW51a2lUYW0mdHh0LWNvbG9yPSUyMzIxMjEyMSZ0eHQtZm9udD1IaXJhZ2lubyUyMFNhbnMlMjBXNiZ0eHQtc2l6ZT0zNiZ0eHQtYWxpZ249bGVmdCUyQ3RvcCZzPTNkZWJkYzQzN2E2ZDZkYTMzYjBkYzhjZDNkNGUyYWVh%26blend-x%3D142%26blend-y%3D486%26blend-mode%3Dnormal%26s%3D589a2cc5ca1c1c0cc6713c6e842cfd07)