I have the following code which works:
for file in $(find $1 -maxdepth 10000 -xdev -ignore_readdir_race); do
if [[ "$file" =~ ^($OP0|$OP1|$OP2|$OP3|$OP4|$OP5|$OP6|$OP7|$OP8|$OP9)$ ]]; then (( SkipCnt++ )) # Count of skipped files
elif [[ ! -e "$file" ]] ; then (( StalCnt++ )) # Count of files that existed last run, but don't now
elif [[ ! -s "$file" ]] ; then (( ZeroCnt++ )) # Count of zero sized files
elif [[ -d "$file" ]] ; then (( DirCnt++ )) # Count of directories
elif [[ -h "$file" || -L "$file" ]] ; then (( LinkCnt++ )) # Count of symbolic links
elif [[ -c "$file" ]] ; then (( CdevCnt++ )) # Count of character devices
elif [[ -b "$file" ]] ; then (( BdevCnt++ )) # Count of block devices
elif [[ -p "$file" ]] ; then (( PipeCnt++ )) # Count of pipes
elif [[ -S "$file" ]] ; then (( SockCnt++ )) # Count of sockets
elif [[ -f "$file" && -s "$file" ]] ; then # File must exist, and not be any of the above.
You can use any one of these three, listed fastest to slowest
tar -cS --no-recursion --warning=none "$file" &>/dev/null
# cp --preserve=all --reflink=never "$file" /dev/null
# cat "$file" 1>/dev/null
(( FileCnt++ )) # Count of files cache-loaded
else
(( SkipCnt++ )) # Count of any files not otherwise processed.
fi
I'm attempting to convert it to a case statement, but I can't figure it out... what I've got so far (I just copied each if statement to the case statement, but it keeps throwing an error):
The error:
/usr/local/bin/cachewarmup: line 43: syntax error near unexpected token `"$file"'
/usr/local/bin/cachewarmup: line 43: ` [[ "$file" =~ ^($OP0|$OP1|$OP2|$OP3|$OP4|$OP5|$OP6|$OP7|$OP8|$OP9)$ ]]) (( SkipCnt++ ));;'
The (non-working) code:
for file in $(find $1 -maxdepth 10000 -xdev -ignore_readdir_race); do
case true in
[[ "$file" =~ ^($OP0|$OP1|$OP2|$OP3|$OP4|$OP5|$OP6|$OP7|$OP8|$OP9)$ ]]) (( SkipCnt++ ));;
[[ ! -e "$file" ]]) (( StalCnt++ ));;
[[ ! -s "$file" ]]) (( ZeroCnt++ ));;
[[ -d "$file" ]]) (( DirCnt++ ));;
[[ -h "$file" || -L "$file" ]]) (( LinkCnt++ ));;
[[ -c "$file" ]]) (( CdevCnt++ ));;
[[ -b "$file" ]]) (( BdevCnt++));;
[[ -p "$file" ]]) (( PipeCnt++));;
[[ -S "$file" ]]) (( SockCnt++ ));;
[[ -f "$file" && -s "$file" ]]) tar -cS --no-recursion --warning=none "$file" &>/dev/null; (( FileCnt++ ));;
*) (( SkipCnt++ ));;
esac
Any ideas on what I'm doing wrong?