Ctrl + Cで現在のコマンドを終了しますが、スクリプトの実行を続けます。

Ctrl + Cで現在のコマンドを終了しますが、スクリプトの実行を続けます。

1行を実行し、しばらくスリープ状態を維持し、ファイルを記録していくつかのパターンが表示されていることをtail -f確認し、ctrl + cを押して終了し、tail -fbashスクリプトの実行が終了するまで次の行に進みます。 :

これまで私がしたことは次のとおりです。

#!/bin/bash


# capture the hostname
host_name=`hostname -f`


# method that runs tail -f on log_file.log and looks for pattern and passes control to next line on 'ctrl+c'

echo "==================================================="
echo "On $host_name: running some command"
some command here

echo "On $host_name: sleeping for 5s"
sleep 5

# Look for: "pattern" in log_file.log
# trap 'continue' SIGINT
trap 'continue' SIGINT
echo "On $host_name: post update looking for pattern"
tail -f /var/log/hadoop/datanode.log | egrep -i -e "receiving.*src.*dest.*"


# some more sanity check 
echo "On $host_name: checking uptime on process, tasktracker and hbase-regionserver processes...."
sudo supervisorctl status process


# in the end, enable the balancer
# echo balance_switch true | hbase shell

スクリプトは機能しますが、エラーが発生します。何を変更する必要があります/私は間違っていますか?

./script.sh: line 1: continue: only meaningful in a `for', `while', or `until' loop

ベストアンサー1

このcontinueキーワードは、あなたが考える意味とは全く関係ありません。これは、ループの次の繰り返しを継続することを意味します。ループ外では意味がありません。

探していると思います。

trap ' ' INT

シグナルを受け取った後は何もしたくないので(フォアグラウンドジョブの終了を除く)、トラップにコードを入れないでください。空の文字列は特別な意味を持つため、空でない文字列が必要です。つまり、信号は無視されます。

おすすめ記事