#!/usr/bin/env bash{output=""valid_shells="^($(sed-rn'/^\//{s,/,\\\\/,g;p}'/etc/shells|paste-s-d'|'-))$"awk-vpat="$valid_shells"-F:'$(NF) ~ pat { print $1 " " $(NF-1) }'/etc/passwd|(whileread-ruserhome;do[!-d"$home"]&&output="$output\n - User \"$user\" home directory \"$home\" doesn't exist"doneif[-z"$output"];thenecho-e"\n-PASSED: - All local interactive users have a home directory\n"elseecho-e"\n- FAILED:\n$output\n"fi)}
If any users' home directories do not exist, create them and make sure the respective user owns the directory. Users without an assigned home directory should be removed or assigned a home directory as appropriate.
The following script will create a home directory for users with an interactive shell whose home directory doesn't exist: