Now we are using the first function (function list_src_dirs) in the next function list_src_dirs_perm_err, getting further into the output we actually need.

sed -nr ‘/\t(source|sys)\t/p’ (-n output the following filter -r extended sed) this line prints the lines which have source or sys as the group (word preceeded with a tab)

sed -r ‘/^277[05]/d’ – excludes the following numbers that start from the beginning of the line (^) 2770 or 2775, this is looking at the permissions octal output. Worth remembering that sed looks at the whole line as the output.

sort -k 2 – sorts the second key (second column) which in this case is the username, making the output in alphabetical order.

Ive started to learn bash scripting and have decided to document it on my blog. Its mainly for my reference but I guess it could also be useful for other beginners. Im not doing anything fancy so dont judge 🙂

The idea behind the script is to run on redhat source directories/files to identify which have the wrong user/group permissions and which files are checked out for longer than expected.

Ill put all the explanations in red so they are easy to read, they are currently not part of the script.

SCRIPT 1.0

#!/bin/bash

set -e #If an error occurs, the script will stop)
set -u #reports if there are any undefined variables)