コマンドは1つですが、ホストは複数のプライベートスクリプトでタイムアウトを使用します

コマンドは1つですが、ホストは複数のプライベートスクリプトでタイムアウトを使用します

私はSSHをデバイスに接続し、SCPを介してファイルを転送し、デバイス名に基づいて名前を付けてから次のファイルに移動するスクリプトを書いています。私の問題は、デバイスにアクセスできないとスクリプトが永久に中断されることです。これは私のコードです。

#!/bin/bash
echo "Starting Backup of Ubiquiti Radios"
#cut -d' ' -f2 /usr/tmp/Script/Links.csv
#cut -d' ' -f1 /usr/tmp/Script/Links.csv
while read one two; do 
    if sshpass -p 'supersecretpassword' scp -o StrictHostKeyChecking=no control@"$two":/tmp/system.cfg /mnt/hgfs/Ubiquiti/$one.cfg; then
        echo $one Success!
    else
        echo $one Failed
    fi
done < /usr/tmp/Script/Links.csv

そのまま動作しますが、使用中のタイムアウトにより、次のデバイスに移動するのではなく、スクリプト全体がキャンセルされます。どんなアイデアでも大いに感謝します。

ベストアンサー1

timeout次のコマンドを試してください。

#!/bin/bash
echo "Starting Backup of Ubiquiti Radios"
while read one two; do 
  if timeout 60 sshpass -p 'supersecretpassword' scp -o StrictHostKeyChecking=no control@"$two":/tmp/system.cfg /mnt/hgfs/Ubiquiti/$one.cfg; then
    echo "$one Success!"
  else
    echo "$one Failed"
  fi
done < /usr/tmp/Script/Links.csv

おすすめ記事