From 547235ea7ed87fe2f48072f84c3bef6a8078b3f9 Mon Sep 17 00:00:00 2001 From: Patrick Marchand Date: Wed, 14 Nov 2018 14:52:01 -0500 Subject: [PATCH] Audited scripts/stats.sh Shellcheck pass and code cleanup. Set stricter error handling with sh options. Removes the for loop and cat(1) in favor of directly calling the file with cut(1) and piping the output to a while read loop. Read https://github.com/koalaman/shellcheck/wiki/SC2002 for more info. Adds proper variable globbing. Removes the large block of commented code, if this turns out to be necessary, we can add a condition check to the script instead of uncommenting on a per case basis. --- scripts/stats.sh | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/scripts/stats.sh b/scripts/stats.sh index ed9f480..fa9cfb0 100755 --- a/scripts/stats.sh +++ b/scripts/stats.sh @@ -1,23 +1,13 @@ #!/bin/sh -for dir in `cat /etc/proftpd/vpasswd | cut -d : -f 6`; do -#for dir in /home/dalleFTP/reynaud_mila; do - if [ -d $dir ]; then - du -s $dir | cut -f 1 >$dir/.size - chmod 644 $dir/.size +set -o errexit +set -o nounset +#set -x - #mtime=0 - #export IFS=$'\n' - #for file in `find $dir -type f -not -name .size -not -name .last-modified`; do - # timestamp=`stat -c %Y $file` - # if [ $timestamp -gt $mtime ]; then - # mtime=$timestamp - # fi - #done - #unset IFS - - #echo $mtime >$dir/.lastmodified - #chmod 644 $dir/.lastmodified +cut -d : -f 6 /etc/proftpd/vpasswd | while read -r dir; do + if [ -d "$dir" ]; then + du -s "$dir" | cut -f 1 > "$dir"/.size + chmod 644 "$dir"/.size fi done