lsofコマンドを使用してsetup.shのインスタンスを1つだけ実行しています。しかし、私はsetup.shで引数を渡す必要があった。lsof linuxコマンドで引数の値で実行中のインスタンスをカウントする
setup.sh machine1に setup.sh machine2で setup.sh machine3に
setup.sh machine1には、実行していると、再び同じコマンドが実行されている場合setup.sh machine1には完了するまで、だから、それは待機します。私はlsofがプロセスのためであり、可能ではないかもしれないと思うが、待っているロジックのための他の良い提案?
私が何らかの引数を渡そうとすると、lsofコマンドで構文エラーが発生しましたが、私は以下を試しましたが運はありません。私の目的はmachine1を使用するインスタンスを1つだけ実行し、誰かがmachine1引数でsetup.shを実行しようとすると、待機する必要があります。他のファイルロック/待機ロジック?
if ([[ $(lsof -t \setup.sh 'machine1'| wc -l) > 1 ]]); then
if ([[ $(lsof -t '\setup.sh machine1'| wc -l) > 1 ]]); then
if ([[ $(lsof -t "\setup.sh machine1"| wc -l) > 1 ]]); then
ワーキング: if ([[ $(lsof -t \setup.sh| wc -l) > 1 ]]); then
echo -e "\tWaiting for 2 minutes...\n"
sleep 2m
else
echo -e "\tFree now to run setup.sh\n"
fi
は動作しません(構文エラー):
if ([[ $(lsof -t \setup.sh| wc -l) > 1 ]]); then
echo -e "\tWaiting for 2 minutes...\n"
sleep 2m
else
echo -e "\tFree now to run setup.sh\n"
fi
if ([[ $(lsof -t \setup.sh machine1| wc -l) > 1 ]]); then
echo -e "\tWaiting for 2 minutes...\n"
sleep 2m
else
echo -e "\tFree now to run setup.sh\n"
fi
なぜ 'setup.sh'の前にスラッシュを入れたのですか? – Inian
現在、スクリプトが配置されている/実行中のパスです。 –