Sponsored Content
Homework and Emergencies Homework & Coursework Questions How to verify all user home directories are writable only by their owner Post 302368538 by NuuBe on Thursday 5th of November 2009 03:56:31 AM
Old 11-05-2009
Data 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 alternative way to it.

2. Relevant commands, code, scripts, algorithms:

My friend says it's the `su - $i -c "ls -ld" 2> /dev/null | grep ^d | awk '{print $1}'` part that is causing the problem but his not sure what to do either.

3. The attempts at a solution (include all code and scripts):

Code:
#!/usr/bin/bash
clear
echo " Verifying if user home directories are writable only by their owner"
echo

TEMPFILE=/permgrep.txt
TEMPFILE2=/namegrep.txt
accno=0
h=1
no=1
Ps=0
Fs=0

if [ ! -f ${TEMPFILE} ]
then 
touch ${TEMPFILE}
fi

if [ ! -f ${TEMPFILE2} ]
then 
touch ${TEMPFILE2}
fi

ACCOUNTS=`cat /etc/passwd | awk -F: '{print $1}'`
array=($ACCOUNTS) 

for i in "${array[@]}"
do
let "accno += 1"
PRINTER=`su - $i -c "ls -ld" 2> /dev/null | grep ^d | awk '{print $1}'`
if [ -n "$PRINTER" ]
then
echo $PRINTER >> $TEMPFILE
echo $i >> $TEMPFILE2
fi
done

echo

for line in $(cat /permgrep.txt)
do

READTF2=`head -$h /namegrep.txt | tail -1`

if [ $line == 'drwxr-xr-x' ]
then
echo $no"-"$READTF2": PASS"
let "h += 1"
let "Ps += 1"

else
echo $no"-"$READTF2": FAIL"
let "h += 1" 
let "Fs += 1"
fi

let "no += 1"

done

nohodi=`expr $accno - $Ps - $Fs`

echo "   Total user accounts: "$accno
echo "   Pass: "$Ps
echo "   Fail: "$Fs
echo "   no home directory : "$nohodi

rm /namegrep.txt
rm /permgrep.txt

4. School (University) and Course Number:
TP, COH

Last edited by DukeNuke2; 11-05-2009 at 05:09 AM.. Reason: please use code tags...
 

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Delete old home directories

I have a script that deletes obselete users from /etc/passwd then moves their home directories to another location. After 30 days, I need to delete the home directories that were moved to the new location. I would appreciate any ideas on how to delete the directories after the 30 days? (2 Replies)
Discussion started by: munch
2 Replies

2. Shell Programming and Scripting

Batch delete specific folder from user home directories

Hi! Need your help. How can I delete the cache folder of multiple user home directories via automatically executed shell script on a Mac OS X Server? Example: The userdata are stored on a Xsan Volume like this: /Volumes/Xsan/userdata/mike /Volumes/Xsan/userdata/peter... (2 Replies)
Discussion started by: nipodrom
2 Replies

3. 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

4. Solaris

how to change /export/home/user dir to /home /user in solaris

Hi all i am using solaris 10, i am creating user with useradd -d/home/user -m -s /bin/sh user user is created with in the following path /export/home/user (auto mount) i need the user to be created like this (/home as default home directory ) useradd -d /home/user -m -s /bin/sh... (2 Replies)
Discussion started by: kalyankalyan
2 Replies

5. Solaris

How to unmount user home directories ??

I've allocated /exports for all user directories by making separate directories under /exports..... :rolleyes: now i need to unmount /exports . But i'm unable to do that.. How can i troubleshoot this issue. Thanks in advance:D (2 Replies)
Discussion started by: vamshigvk475
2 Replies

6. Shell Programming and Scripting

World writable home dirs

what is wrong with this script? I get: ./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... (4 Replies)
Discussion started by: greenja9
4 Replies

7. Solaris

Giving read write permission to user for specific directories and sub directories.

I have searched this quite a long time but couldn't find the right method for me to use. I need to assign read write permission to the user for specific directories and it's sub directories and files. I do not want to use ACL. This is for Solaris. Please help. (1 Reply)
Discussion started by: blinkingdan
1 Replies

8. UNIX for Beginners Questions & Answers

[Tip] Housekeeping Tasks Made Easy - User Home directories and Leftover Files

We have regularly questions about how to create users and user accounts. But regularly user accounts need to be deleted too. It is quite easy to delete the user account itself but usually the HOME directory of the user remains. It is good style to remove these directories but simply deleting... (3 Replies)
Discussion started by: bakunin
3 Replies
CHOWN(3)								 1								  CHOWN(3)

chown - Changes file owner

SYNOPSIS
bool chown (string $filename, mixed $user) DESCRIPTION
Attempts to change the owner of the file $filename to user $user. Only the superuser may change the owner of a file. PARAMETERS
o $filename - Path to the file. o $user - A user name or number. RETURN VALUES
Returns TRUE on success or FALSE on failure. EXAMPLES
Example #1 Simple chown(3) usage <?php // File name and username to use $file_name= "foo.php"; $path = "/home/sites/php.net/public_html/sandbox/" . $file_name ; $user_name = "root"; // Set the user chown($path, $user_name); // Check the result $stat = stat($path); print_r(posix_getpwuid($stat['uid'])); ?> The above example will output something similar to: Array ( [name] => root [passwd] => x [uid] => 0 [gid] => 0 [gecos] => root [dir] => /root [shell] => /bin/bash ) NOTES
Note This function will not work on remote files as the file to be examined must be accessible via the server's filesystem. Note When safe mode is enabled, PHP checks whether the files or directories being operated upon have the same UID (owner) as the script that is being executed. SEE ALSO
chmod(3), chgrp(3). PHP Documentation Group CHOWN(3)
All times are GMT -4. The time now is 02:16 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy