World writable home dirs


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting World writable home dirs
# 1  
Old 03-13-2014
World writable home dirs

what is wrong with this script?
I get:
Code:
./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:
Code:
#!/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


Last edited by vbe; 03-13-2014 at 01:47 PM.. Reason: code tags
# 2  
Old 03-13-2014
Missing double quotes:
Code:
for dir in `/bin/cat /etc/passwd | /bin/egrep -v "(root|halt|sync|shutdown)"

Also the script is poorly written. I see UUOC and other utilities. It can be improved a lot.
This User Gave Thanks to Yoda For This Post:
# 3  
Old 03-13-2014
any critiques would be appreciated....
# 4  
Old 03-13-2014
Why use cat at the beginning?
Code:
/bin/egrep -v "(root|halt|sync|shutdown)" /etc/passwd |etc...

# 5  
Old 03-13-2014
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).
Code:
#!/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.
Code:
$1!~/(root|halt|sync|shutdown)/

Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. What is on Your Mind?

Mad World Remix of Moby Video (Are You Lost In The World Like Me)

This is an excellent video comment on modern society and the remix is good too: https://www.youtube.com/watch?v=5DU1B_XkyIk 5DU1B_XkyIk Watch the video above and post your comments. (3 Replies)
Discussion started by: Neo
3 Replies

2. UNIX for Dummies Questions & Answers

**HELP** how to do a listing of dirs and all sub dirs only

I am trying to get a listing of ALL directories only under /export (as an example). I can get all the dirs directly under /export but I need any sub dirs under those dirs. I've looked (here and google) but can not find anything that works (4 Replies)
Discussion started by: bbraml
4 Replies

3. Solaris

/dev/null not writable

Hi, after a server (solaris 10) got rebooted, Im faced with the problem that in one of my zones (whole zone) /dev/null is only writeable for root crw-r--r-- 1 root sys 13, 2 Jul 8 10:16 /dev/null Unfortunatly chmod didnt help at this point and since its a productive system I dont... (11 Replies)
Discussion started by: bin-doph
11 Replies

4. UNIX for Dummies Questions & Answers

How to find root owned world writable files?

Being a system administrator i came across a statement as " Excluding temporary directories /tmp and /var/tmp, no root owned files should be in world writable directories" While the above statement may look straight forward but how would i check if there are any such directories in the... (7 Replies)
Discussion started by: pinga123
7 Replies

5. Homework & Coursework Questions

How to verify all user home directories are writable only by their owner

1. The problem statement, all variables and given/known data: Need to verify that all user home directories are writable only by their owner on Solaris. The script posted below is workable but it is taking a long time to display the results, and I don't seem to be able to fix it or find any... (6 Replies)
Discussion started by: NuuBe
6 Replies

6. Shell Programming and Scripting

How to verify all user home directories are writable only by their owner

Hi, I'm currently working on my school assignment on how to verify that all user home directories are writable only by their owner on Solaris with VMware. But I'm not sure why my codes take a very long time to display the results. My friend says it's the `su - $i -c "ls -ld" 2> /dev/null | grep... (1 Reply)
Discussion started by: NuuBe
1 Replies

7. UNIX for Advanced & Expert Users

writable protected file

Greetings I am trying to create a solution that will log information into a file. That is the easy part. What I am trying to do is have a front end script that ill ask a user what their reasoning is for logging in and log that reason into a file. The hard part I am finding is that I need that... (10 Replies)
Discussion started by: Smoker
10 Replies

8. AIX

How to find world writable files? (AIX)

Hi Group, Could someone tell me how to find world writable files on my server? I can use find command in conjuction with -perm option and I will get an output. But what I need is an output which looks similar to ls -l output. Meaning, it should give me the full path of the file along with the... (1 Reply)
Discussion started by: matifr
1 Replies
Login or Register to Ask a Question