The UNIX and Linux Forums  


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 -->
  #1 (permalink)  
Old 01-03-2009
roddo90 roddo90 is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 1
checking for command output validity

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

Quote:
dirperm=$(ls -ld $(echo $user | awk -F: '{ print $6 }') | awk -F ' ' '{print $3}')
#echo $username
if [ "$username" == "$dirperm" ]
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, 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?