我有一個運行多個實驗(實現時機等)的bash腳本,但如果它已經運行,我不想運行相同的實驗。Bash:檢查腳本是否已經在這臺計算機上運行
實驗已經運行if if same計算機產生一個輸出文件,其中包含280行。
我現在要做的是以下(所有實驗):
# Remove the prefix
tmp=${3#*/}
# Remove the suffix
instance=${tmp%.*}
# Set the output path
output_path=statistics/experiment-$1-$2-${instance}.csv
if [ -f ${output_path} ];
then
# The output file exists, check if it contains 280 lines
LC=`wc -l ${output_path} | cut -f1 -d' '`
if [[ ${LC} == 280 ]]; then
# It did, thus we are done
echo "$(date -R) [SKIPPING ] Instance already processed for ${1} (${2}) on ${3} - Skipping experiment!"
# Do not do anything else
exit 0
fi
# The experiment was stopped prematurely, rerun it
echo "$(date -R) [RERUNNING] Instance not fully processed for ${1} (${2}) on ${3} - Rerunning experiment! (${LC}/280 runs)"
# Remove old file
rm -f ${output_path}
fi
# Run the experiment
echo "$(date -R) [RUNNING ] Running experiment for ${1} (${2}) on ${3}"
start=$(date +%s)
./bin/Experiment --algorithm $1 --dbms $2 --instance_path $3 > ${output_path}
total=$(($(date +%s)-${start}))
echo "$(date -R) [FINISHED ] Finished experiment for ${1} (${2}) on ${3} in ${total} seconds."
但這不檢查,如果實驗在同一臺計算機上運行。我最初的做法是使用ip link show eth0 | awk '/ether/ {print $2}'
來獲取計算機的MAC地址,然後將輸出文件存儲在一個目錄中,例如, statistics/ff:ff:ff:ff:ff/experiment1.csv
,但((假設安裝了ip
)是否保證所提到的命令會返回一個MAC地址?或者還有其他方法來從bash腳本中唯一標識一臺計算機嗎?
也許你可以使用主機名而不是IP或MAC地址? – Pierre
我認爲,對於我的用例來說,這應該足夠了! – YnkDK