我有一个运行多个实验(实现时机等)的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