Skip to content

Instantly share code, notes, and snippets.

@dannysheehan
Created February 20, 2014 06:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dannysheehan/9107830 to your computer and use it in GitHub Desktop.
Save dannysheehan/9107830 to your computer and use it in GitHub Desktop.
Find users missing .profile and .bashrc files and copy them from /etc/skel
#!/bin/bash
for h in `ls -d1 /home/*`
do
TUSER=`basename $h`
if ! getent passwd $TUSER 2> /dev/null | awk -F: '{print $7}' | grep -v "/bin/bash"
then
if [ -d $h -a ! -e $h/.profile ]
then
( su - $TUSER -c "cp /etc/skel/.profile $h" ) && ls -1d $h/.profile
else
echo $TUSER .profile ok
fi
if [ -d $h -a ! -e $h/.bashrc ]
then
( su - $TUSER -c "cp /etc/skel/.bashrc $h" ) && ls -1d $h/.bashrc
else
echo $TUSER .bashrc ok
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment