The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 01-04-2009
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361
Quote:
Originally Posted by roddo90 View Post
hi, i'm trying to write a script to check if the home directories of users are set correctly. below is an extract of the script

Please put code between [code] tags.
Quote:
Code:
dirperm=$(ls -ld $(echo $user | awk -F: '{ print $6 }') | awk -F ' ' '{print $3}')

I don't understand exactly what you are trying to do, but that looks far more complicated than it need be. For example, couldn't part of that be done more easily with:

Code:
eval "dir=~$user"
Quote:
Code:
#echo $username
if [ "$username" == "$dirperm" ]

The == operator is not standard.
Quote:
Code:
then
echo $username [PASS]
else
if [ -z "$dirperm" ]
then
echo $username [FAIL - Directory Does not Exists!]
else
echo $username [FAIL]
here, i am trying to put the name of the owner of the home directory into the variable dirperm (by reading lines in /etc/passwd). however, it seems that when the directory is invalid,

What do you mean by "invalid" and where do you test for that?
Quote:
the "does not exist" error message pops out and messes up the script output.
how can i do a check to see if the output of ls -ld in the script is valid?

What do you mean by "invalid"? If you want to check whether it exists, use test -d.