我有一个运行多个实验的bash脚本(实现的时间等),但如果它已经运行,我不想运行相同的实验。
如果相同的计算机生成了一个包含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脚本中唯一地识别计算机?
答案 0 :(得分:0)
使用dmidecode
。它检查系统并返回制造商设置的序列号。你有几个选择。您可以使用dmidecode -t 2
返回类似的内容:
Handle 0x0002, DMI type 2, 8 bytes. Base Board Information
Manufacturer: Intel
Product Name: C440GX+
Version: 727281-001
Serial Number: INCY92700942
在上面的示例中,您可以看到主板的序列号,但不能看到系统的序列号。为此,您可以使用dmidecode -t 1
。解析所有这些只是麻烦,只需通过sha256sum进行管道并获得一个简单的哈希。
使用dmidecode -s system-uuid
也很有用。