checking for command output validity


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting checking for command output validity
# 1  
Old 01-03-2009
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  
Old 01-04-2009
Quote:
Originally Posted by roddo90
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Help understanding what this ls -l command is checking in a script

Hello, we have a script that has the two following lines: ssh -qno StrictHostKeyChecking=no -o ConnectTimeout=1 user@IP 'ls -l /home/opsmgrsvc >/dev/null 2>&1' > /dev/null 2>&1 status="$(echo $?)" I can't understand what these two lines are doing? When I execute the first line nothing... (6 Replies)
Discussion started by: greavette
6 Replies

2. Shell Programming and Scripting

Confirming validity of programming language tools

so i have scripts that get run in ways similar to this: cat script.pl | perl - $1 $2 $3 cat script.rb | ruby - $1 $ 2 $3 my question is, how can i verify that that the "perl" or "ruby" or "python" tool being run on the box is actually a legit tool? meaning, someone may move the tool from... (2 Replies)
Discussion started by: SkySmart
2 Replies

3. Shell Programming and Scripting

Insert title as output of command to appended file if no output from command

I am using UNIX to create a script on our system. I have setup my commands to append their output to an outage file. However, some of the commands return no output and so I would like something to take their place. What I need The following command is placed at the prompt: TICLI... (4 Replies)
Discussion started by: jbrass
4 Replies

4. Shell Programming and Scripting

Checking if command ran in parallel

Hi, I am running below code For I in $var do .......some line of code....... nohup Sqlplus apps/apps <<EOF & My_proc($I) Exit EOF done Nohup and & is used for parallel processing. Can someone help in determining if the procedure with different arguments Was called paralley or... (3 Replies)
Discussion started by: Pratiksha Mehra
3 Replies

5. Shell Programming and Scripting

Date validity check

hi All, i have file in which it has 2000 records like, test.txt ==== 2011-03-01 2011-03-01 2011-03-01 2011-03-01 2011-03-01 2011-03-02 2011/03/02 previously i used for loop to find the date check like below, for i in `cat test.txt` do d=`echo $i | cut -c9-10| sed 's/^0*//'`;... (11 Replies)
Discussion started by: mechvijays
11 Replies

6. Shell Programming and Scripting

Checking has for a command line argument

I would like to search and print a match of the user entered $ARGV. Im terrible with hashes and really dont know where to go from here. The example data file name location phone Bugs holeintheground 5551212 Woody holeinthetree 6661313 Jerry holeinthewall 7771414... (4 Replies)
Discussion started by: sumguy
4 Replies

7. Shell Programming and Scripting

Script to check the validity of password

Hi, I have to validate the passwords for 100s of unix users across several servers. I have the list of unix users and servers with passwrods. How can I check whether a password is correct or not using a single shell script? Note : I do not have root privileges on any server. All the... (1 Reply)
Discussion started by: Pupil
1 Replies

8. Shell Programming and Scripting

Conditional checking for VMWARE command

Hello, I have to runt he following VMWARE script to take a snap shot of my machine: vmware-cmd -v /vmfs/volumes/44e9c20f-71ded630-3ac2-00137221e12a/orion/orion.vmx createsnapshot Weekly_Backup I need to check if successfully executes or not so I thought I would put it in a IF STATEMENT ... (2 Replies)
Discussion started by: mojoman
2 Replies

9. UNIX for Dummies Questions & Answers

Command display output on console and simultaneously save the command and its output

Hi folks, Please advise which command/command line shall I run; 1) to display the command and its output on console 2) simultaneous to save the command and its output on a file I tried tee command as follows; $ ps aux | grep mysql | tee /path/to/output.txt It displayed the... (7 Replies)
Discussion started by: satimis
7 Replies

10. Shell Programming and Scripting

Validity

Hey, I was wondering how I could write a bash script which accepts: cat <<% | bash ./results06 ---------------------------------------------------------- Exam Results 2006 ---------------------------------------------------------- ... (1 Reply)
Discussion started by: Xerobeat
1 Replies
Login or Register to Ask a Question