./perm.sh: command substitution: line 21: unexpected EOF while looking for matching `"'
./perm.sh: command substitution: line 22: syntax error: unexpected end of file
Script:
#!/bin/bash
for dir in `/bin/cat /etc/passwd | /bin/egrep -v "(root|halt|sync|shutdown) |\
/bin/awk -F: '($8 == "PS" && $7 != "/dev/null") { print $6 }'`; do
dirperm=`/bin/ls -ld $dir | /bin/cut -f1 -d" "`
if [ `echo $dirperm | /bin/cut -c6 ` != "-" ]; then
echo "Group Write permission set on directory $dir"
fi
if [ `echo $dirperm | /bin/cut -c8 ` != "-" ]; then
echo "Other Read permission set on directory $dir"
fi
if [ `echo $dirperm | /bin/cut -c9 ` != "-" ]; then
echo "Other Write permission set on directory $dir"
fi
if [ `echo $dirperm | /bin/cut -c10 ` != "-" ]; then
echo "Other Execute permission set on directory $dir"
fi
done
I usually set PATH at the top of the script, then forget about it.
This, and a while loop, increases readability IMHO.
Also, you can handle the egrep -v within the awk (that uses ERE like egrep).
#!/bin/bash
export PATH; PATH=/bin:/usr/bin:/usr/sbin:/sbin
< /etc/passwd awk -F: '
($0!~/(root|halt|sync|shutdown)/ && $8 == "PS" && $7 != "/dev/null") { print $6 }
' |
while read dir
do
dirperm=`ls -ld "$dir" | cut -f1 -d" "`
if [ `echo $dirperm | cut -c6 ` != "-" ]; then
echo "Group Write permission set on directory $dir"
fi
if [ `echo $dirperm | cut -c8 ` != "-" ]; then
echo "Other Read permission set on directory $dir"
fi
if [ `echo $dirperm | cut -c9 ` != "-" ]; then
echo "Other Write permission set on directory $dir"
fi
if [ `echo $dirperm | cut -c10 ` != "-" ]; then
echo "Other Execute permission set on directory $dir"
fi
done
awk has the further advantage that you can limit the search to a certain field, e.g.