私はコマンドを含むファイルの各行を読み取り、1つずつ実行し、コマンドが失敗した場合に停止するbashスクリプトを作成しました。
while read -r line
do
$line || exit 1
done< /root/ansi-pb/sample.txt
Sample.txt には次のコマンドがあります。
echo "hello world"
free -m
mvn -version
date
echo "bye"
このスクリプトを即座に作成して失敗したコマンドが発生した場合は、テキストファイルで修正してスクリプトを再実行するときに最初から始めるのではなく、失敗したコマンドから始める必要があります。
どうすればいいですか?
ベストアンサー1
#!/bin/bash
echo "$0 $$"
##Here do your stuff and redirect the errors to a log file
##if an error is found say using $?, use the following
kill -SIGSTOP $$
##After you'r done correcting your file
##use kill -SIGCONT <pid> on a console, the process shall continue
## Put in a mechanism to retry the last executed command
echo "I am done!!! after SIGSTOP $$"
exit 0
これは単なる例示であり、要求に応じて所望の方法で実施することができる。