Sponsored Content
Full Discussion: test and if condition
Top Forums Shell Programming and Scripting test and if condition Post 302123668 by cfajohnson on Tuesday 26th of June 2007 02:28:57 PM
Old 06-26-2007
Quote:
Originally Posted by ciroredz
Guys look at this:
i have to write a script that takes a file as an argument. The script should be able to determine what permissions the owner, group and everybody has for the file passed in. The output should be displayed similar to this.

READ WRITE EXECUTE
OWNER LEE.BALLANCORE YES YES NO
GROUP USERS YES NO NO
EVERYBODY NO NO NO

This should get you started:

Code:
permreport()
{
  printf "%s\t" "$1"
  shift
  r=${1%??}
  wx=${1#?}
  w=${wx%?}
  x=${wx#?}
  for p in $r $w $x
  do
      case $p in
          -) printf "NO \t" ;;
          *) printf "YES\t" ;;
      esac
  done
  echo
}

FILE=$1
set -f
set -- $( ls -ld "$FILE" )

type_perms=$1
links=$2
owner=$3
group=$4
size=$5
month=$6
day=$7
time=$8 ## may be year
filename=$9 ## may include symlink target

perms=${type_perms#?}
filetype=${type_perms%"$perms"}
goperms=${perms#???}
uperms=${perms%"$goperms"}
gperms=${goperms%???}
operms=${goperms#???}

permreport OWNER $uperms
permreport GROUP $gperms
permreport WORLD $operms

Note that this doesn't take into account setuid and README bits.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

need help with test condition in shell script

I'm new to scripting and I need help with a bourn shell script. What i'm trying to do is a test condition where "if the time is within 2 hours, it's true" and so on. The time is in the following format DATE=`/bin/date +"%Y%m%d%H%S"` for example, 20060907152000. So, what the script first... (9 Replies)
Discussion started by: pieman8080
9 Replies

2. Shell Programming and Scripting

Condition test ( [[ ]] ) doubt

Hi , I have a doubt on condition test ( ] ). Pls refer blow program. #!/bin/ksh TEMP= if ;then echo $TEMP else print 'invalid option' fi Above script's TEMP variable has no value so it gives "invalid option" as output. But I got an error before priting the string . Result : ... (2 Replies)
Discussion started by: thambi
2 Replies

3. UNIX for Dummies Questions & Answers

Condition test

Hi there, When I try to do a condition on test: $ str1=abcd $ test $str1 $ echo $? 0 Is there anyway to display the answer to be 'TRUE' or 'YES'? rather than 0? If so, how can I do it without using awk or sed. (2 Replies)
Discussion started by: felixwhoals
2 Replies

4. Shell Programming and Scripting

Test condition

Hello, what is the better and correct way to perform a comparison: I have been using the following with no problems: if ] then .... fi I have seen this also used : if then .... fi When I try : if then .... fi I get an error like .... the test condition expects a... (4 Replies)
Discussion started by: gio001
4 Replies

5. Shell Programming and Scripting

test condition

Hi there, I tried to search for this almost everywhere, but didnt get any proper information on it. What is the difference between ] Some of the code works when I have only single condition i.e. ] && $dothis1 || $dothis2 But if i try to include another testcondition to the... (1 Reply)
Discussion started by: tostay2003
1 Replies

6. Shell Programming and Scripting

How to check weather a string is like test* or test* ot *test* in if condition

How to check weather a string is like test* or test* ot *test* in if condition (5 Replies)
Discussion started by: johnjerome
5 Replies

7. UNIX for Advanced & Expert Users

Condition to test if a host can be pinged

I have a much larger script that takes an input file of hosts and determines if we support them and checks to ensure the FQDN coincides with our DNS. For instance, the hostname may return a different FQDN when passed to the "host" command, so I keep the value of the output of the "host" command... (4 Replies)
Discussion started by: MaindotC
4 Replies

8. UNIX for Advanced & Expert Users

Lower case test condition

I want to locate directories that are upper, lower or have both upper and lower cases. What I have is: find /tmp/$var2 -type d' " ); && echo "host case is incorrect" || echo "host case is correct" This actually is part of a larger script and it does work but the problem is that it... (3 Replies)
Discussion started by: newbie2010
3 Replies

9. UNIX for Dummies Questions & Answers

Simple negated test condition

Without grep, I'd like to make a test condition so that any a word that does not have the successive letters car in it will be echoed. for example, bluecar will contain "car" so it will show up as a no var=bluecar $ echo $var|if ]; then echo "yes";fi yes this variable contains "car" so I... (5 Replies)
Discussion started by: newbie2010
5 Replies

10. UNIX for Beginners Questions & Answers

Test a condition for n times and take action

i have to test a condition for n times and if its value is greater than one each time for continuous 5 iterations it will take action My Approach run the same command 5 times in for loop and divert the output to a file and then read the values from file and use if else if and take action ... (1 Reply)
Discussion started by: abhaydas
1 Replies
CHOWN(1)								FSF								  CHOWN(1)

NAME
chown - change file owner and group SYNOPSIS
chown [OPTION]... OWNER[:[GROUP]] FILE... chown [OPTION]... :GROUP FILE... chown [OPTION]... --reference=RFILE FILE... DESCRIPTION
This manual page documents the GNU version of chown. chown changes the user and/or group ownership of each given file, according to its first non-option argument, which is interpreted as follows. If only a user name (or numeric user ID) is given, that user is made the owner of each given file, and the files' group is not changed. If the user name is followed by a colon or dot and a group name (or numeric group ID), with no spaces between them, the group ownership of the files is changed as well. If a colon or dot but no group name follows the user name, that user is made the owner of the files and the group of the files is changed to that user's login group. If the colon or dot and group are given, but the user name is omitted, only the group of the files is changed; in this case, chown performs the same function as chgrp. OPTIONS
Change the owner and/or group of each FILE to OWNER and/or GROUP. -c, --changes like verbose but report only when a change is made --dereference affect the referent of each symbolic link, rather than the symbolic link itself -h, --no-dereference affect symbolic links instead of any referenced file (available only on systems that can change the ownership of a symlink) --from=CURRENT_OWNER:CURRENT_GROUP change the owner and/or group of each file only if its current owner and/or group match those specified here. Either may be omit- ted, in which case a match is not required for the omitted attribute. -f, --silent, --quiet suppress most error messages --reference=RFILE use RFILE's owner and group rather than the specified OWNER:GROUP values -R, --recursive operate on files and directories recursively -v, --verbose output a diagnostic for every file processed --help display this help and exit --version output version information and exit Owner is unchanged if missing. Group is unchanged if missing, but changed to login group if implied by a `:'. OWNER and GROUP may be numeric as well as symbolic. AUTHOR
Written by David MacKenzie. REPORTING BUGS
Report bugs to <bug-coreutils@gnu.org>. COPYRIGHT
Copyright (C) 2002 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICU- LAR PURPOSE. SEE ALSO
The full documentation for chown is maintained as a Texinfo manual. If the info and chown programs are properly installed at your site, the command info chown should give you access to the complete manual. chown (coreutils) 4.5.3 February 2003 CHOWN(1)
All times are GMT -4. The time now is 02:50 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy