linux - Bash: Check if script already ran on this computer -
i have bash-script runs several experiments (timing of implementations etc.), not want run same experiment if ran.
an experiment ran iff same computer produced output file, contains 280 lines.
what following (for experiments):
# remove prefix tmp=${3#*/} # remove suffix instance=${tmp%.*} # set output path output_path=statistics/experiment-$1-$2-${instance}.csv if [ -f ${output_path} ]; # output file exists, check if contains 280 lines lc=`wc -l ${output_path} | cut -f1 -d' '` if [[ ${lc} == 280 ]]; # did, done echo "$(date -r) [skipping ] instance processed ${1} (${2}) on ${3} - skipping experiment!" # not else exit 0 fi # experiment stopped prematurely, rerun echo "$(date -r) [rerunning] instance not processed ${1} (${2}) on ${3} - rerunning experiment! (${lc}/280 runs)" # remove old file rm -f ${output_path} fi # run experiment echo "$(date -r) [running ] running experiment ${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 ${1} (${2}) on ${3} in ${total} seconds."
but not check if experiment ran on same computer. initial though use ip link show eth0 | awk '/ether/ {print $2}'
mac address of computer , store output file in directory, e.g. statistics/ff:ff:ff:ff:ff/experiment1.csv
, (given ip
installed) guaranteed mentioned command return mac address? or there otherways uniquely identify computer bash-script?
use dmidecode
. examines system , returns serial number set manufacturer. have several options. use dmidecode -t 2
returns like:
handle 0x0002, dmi type 2, 8 bytes. base board information manufacturer: intel product name: c440gx+ version: 727281-001 serial number: incy92700942
in example above, can see serial number of motherboard not system. can use dmidecode -t 1
. can hassle parse pipe through sha256sum , simple hash.
using dmidecode -s system-uuid
useful well.
Comments
Post a Comment