The UNIX and Linux Forums  


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



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Command display output on console and simultaneously save the command and its output satimis UNIX for Dummies Questions & Answers 7 01-25-2009 08:27 PM
problem with output of find command being input to basename command... new_learner UNIX for Dummies Questions & Answers 2 12-14-2008 02:56 AM
UNIX command for checking active Fibre Channels DavoH UNIX for Dummies Questions & Answers 1 12-31-2007 06:17 PM
Validity Xerobeat Shell Programming and Scripting 1 12-04-2006 05:14 PM
command for checking temperature & humidity. pattarapongn AIX 0 10-21-2006 07:01 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #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?
  #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,365
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:13 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0