one MUST NOT use files with fixed names in world-writable directories such as
/tmp(hence the switch to~/tmphere, or use a dedicated area in/varor~/var/~/.local/$XDG_RUNTIME_DIR...).there's nothing bash-specific in that code, so no need to add that bash dependency.
with
-n, extra arguments toperlare the input to the scriptas Chris already said, you had issues with your quoting.
you have a
AUTOSERV/AUTOSERVEdiscrepancy..is a regex operator that matches any single character. Use\.or[.]to match a literal dot.beware that usage of
dateis GNU-specific. Not alldateimplementations support a-doption, and among those that do, it can be for something totally unrelated like on BSDs or they don't recogniseyesterday(like with thedateof busybox or toybox).perlcan also do date manipulation¹ if you need that script to be portable to non-GNU systems.You could easily change that to use a single regexp such as:
/STATUS:\s+(?:SUCCESS|FAILURE|TERMINATED)\b.+MACHINE:\s+(\w+.\w+.\w+)$/replace
keys %countwithsort cmp, keys %countif you want the list of machines to be sorted lexically.exec, common in wrapper scripts like this one is just to save a process. It tells the shell to runperlin the same process rather than in a child process and wait for it.cmddoesfork()+exec(cmd)&wait(child), whileexec cmd(which maybe should have been callednofork cmd) is justexec(cmd)so even though it's longer to type, it's simpler/shorter to run for the system and uses less resource.%m%d%Yis not a very good choice of timestamp format. It's ambiguous and its lexical order (like in the output ofls) does not match the chronological order.%Y-%m-%dor%Ffor short is much better as it's universally recognised, and sorts lexically chronologically (at least for years 0001 to 9999).catis the command to concatenate files, it makes little sense to use it for one file. Usingcmd < input > output(or<input cmd >output, but notcmd > output < input) also has the benefit that ifinputcan't be opened for reading, thencmdwon't be run andoutputwon't be clobbered.
¹ For instance here by adding -MPOSIX and a BEGIN{@t = localtime; $t[3]--; $dt = strftime "%m%d%Y", @t} or even as a hack just -M'POSIX;@t = localtime; $t[3]--; $dt = strftime "%m%d%Y", @t'.