# Tag Info

There are aritmetic syntax issues. Due to that it doesn't work under GNU bash, version 4.2.46(2)-release Instead: cpu_cores=$(( cpu_cores + "${row[3]}" )) load_prc=$(( "$load_mlt" / "$cpu_cores" )) Should be: cpu_cores=$(( cpu_cores + row[3] )) load_prc=$(( load_mlt / cpu_cores )) 2 I don't understand why it should be a warning to have over 80% of the system RAM available. If anything needs a warning, it should be having under 20% of RAM available, right? Reading each line into an array is overcomplicated. The read builtin command is quite good at splitting each line of input into multiple variables. (row_value_lenght is misspelled, ... 3 I’d agree with all of l0b0’s answer – including the suggestion of using grep to process /proc/cpuinfo. An alternate way to count all CPU cores using an AWK one-liner would be: cpu_cores=$(awk '/cpu cores/ { num_cores += $4} END { print num_cores}' /proc/cpuinfo) This would also remove the usage of Bash arrays, resulting in the script being POSIX-compatible ... 6 This looks pretty good. Some suggestions: [[ is preferred over [ in Bash. This script could benefit from set -o errexit -o nounset -o pipefail. You'll need to set cpu_cores=0 before referring to it in the loop, but that's just best practice. Dividing by one isn't going to do much :) The quotes are a cute feature, but I'd much rather see a summary of the ... 1 If "japan" only appears once in each section, you can store the startswith line, and simply print out the desired output immediately when the matching line is found: for line in frb: line = line.strip("\n") if line.startswith("--"): prefix = line if "japan" in line: print(prefix + line) 1 A quick Answer [Should not be used in PRODUCTION] I mainly try to answer your concern over how to avoid "for-else" to handle last edge case, and haven't reviewed much of rest of code. #!/grid/common/pkgs/python/v3.6.1/bin/python3 block_start_identifier = "--" search_word = "japan" data_block = [] block_satisfied = False with open('mydata_test.txt', 'r') ... 1 Unless there is an indentation issue, dataBlock = '' dataBlock = dataBlock + line can be written: dataBlock = line 3 To sudo or not to sudo I'm also wondering if it's better to only run the commands that need it with sudo or if I should rerun the whole script as sudo after prompting for the password like this: if [[ "$EUID" != 0 ]]; then warning "Please run as root" sudo "$0" "$@" fi Can the script do its job without root permissions? This script cannot, ...
I don't really see room for groundbreaking improvements, so this review is going to be nitpicky, brace yourself! Looping over pairs of values This loops over multiple lines, with two values per line: for i in $(cut -d' ' -f1,2 /proc/mounts | grep -F "$mdir/") I think it would be much better to write this is a while read loop, reading into a pair of ...