This script tests for the SGID permissions on a directory. Remember SGID changes the effective user so that it elevates a user’s permissions for this directory. The permissions are 2770. The advantage for the sales directory is that all files created will take on the group ownership so files can be shared easily.
The script looks for the directory to verify it exists and then checks permissions with the “-perm” option with find. This test then provides a success or no success which is evaluated and sent to the administrator.
# Test for SGID on /opt/sales
find $FILE -perm 2770 | grep sales
if [ "$?" -ne "0" ]
echo "Bad Permissions" | mail -s "Permissions not correct on Sales $(date)" $ADMIN; echo "Bad Permissions"
echo "SGID Set" | mail -s "SGID set on Sales $(date)" $ADMIN; echo "SGID set on Sales"
This script could have been written differently with this line to test for permissions:
if [ -g /opt/sales ];
This would replace the find command and use the “-g” option in the test. This is cleaner code so probably a better option. You would need to exchange the then…else clauses.