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
Thousand Parsec 0.5.0 (C++ Server branch) iBot Software Releases - RSS News 0 05-01-2008 06:10 PM
Thousand Parsec 0.3.0 (Python wxWindows Client branch) iBot Software Releases - RSS News 0 02-19-2008 02:50 AM
removing thousand of carriage returns using sed ml5003 Shell Programming and Scripting 4 06-09-2006 06:22 PM
65 thousand dollar question mud What's on Your Mind? 10 10-22-2005 02:35 PM

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 12-20-2007
invinzin21 invinzin21 is offline
Registered User
  
 

Join Date: Dec 2007
Location: Philippines, Cebu City
Posts: 75
getting thousand of permissions

Hi, I would like to ask if someone could help me to shorten this process.
If example i will have a thousand files and i want to get there permisions. pls help.

$ sh researcher2.sh
rm /home/aris/logs/logna
rm a12
for i in `aclget /usr/bin/uname`
do
grep -e $i ownership | awk '{print $1}'
done > a12
echo /usr/bin/uname has the permission of `cat a12` > /home/aris/logs/logna

rm a12
for i in `aclget profile`
do
grep -e $i ownership | awk '{print $1}'
done >> a12
echo profile has the permission of `cat a12` >> /home/aris/logs/logna

rm12
for i in `aclget cron.sh`
do
grep -e $i ownership | awk '{print $1}'
done >> a12
echo cron.sh has the permission of `cat a12` >> /home/aris/logs/logna

clear
cp logna /home/aris/a/orig
cat /home/aris/logs/logna


this is the output :

/usr/bin/uname has the permission of 5 5 5
profile has the permission of 1
cron.sh has the permission of 1 7 7 7

------------------------------------------------------------------------i already tried this one, but it didnt work

y=`cat test`
for x in `aclget $y`
do
grep -e $x ownership | awk '{print $1}' >> file122
echo $y permisions is `cat file122` >> file1
done
cat file1


$ cat test
/usr/bin/uname
profile
cron.sh
  #2 (permalink)  
Old 12-20-2007
invinzin21 invinzin21 is offline
Registered User
  
 

Join Date: Dec 2007
Location: Philippines, Cebu City
Posts: 75
This is the value of ownership if you may ask.

$ cat ownership
1 --x
2 -w-
3 -wx
4 r--
5 r-x
6 rw-
7 rwx
  #3 (permalink)  
Old 12-20-2007
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,131

Code:
#! /usr/local/bin/perl

open(DATA, "< test") || die "Unable to open file test\n";
while (<DATA>) {
        chomp;
        printf  "%s has permission %o \n", $_ , (stat($_))[2]& 0777;
}
close(DATA);
exit 0

  #4 (permalink)  
Old 12-20-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,558
if you have stat in your system (AIX?)

Code:
# stat -c "%a:%n" *

if you have GNU find

Code:
# find  /path -printf "%m:%p\n"

  #5 (permalink)  
Old 12-20-2007
invinzin21 invinzin21 is offline
Registered User
  
 

Join Date: Dec 2007
Location: Philippines, Cebu City
Posts: 75
sir's,
thanks for the support, but only perl works w/ me. Currently there is no stat command in my aix. I really thank Sir Perderabo.

It is much better if it is purely shell script, no problem w/ perl,but this script will be the script to all of our servers. We know that diffrnt servers diffrnt perl.
  #6 (permalink)  
Old 12-20-2007
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,131
perl does vary quite a bit between versions and this can cause portability problems. But I doubt that you will be able to find any perl version which cannot run that little script. It stays with just a few basic things. And you wanted speed. There is no way to come close to the performance of the perl script with a shell script.
  #7 (permalink)  
Old 12-20-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,558

Code:
#!/bin/sh
# assume no setuid,setgid bits set.
ls -l | awk '
BEGIN{
perm["rwx"]=7
perm["rw-"]=6
perm["r--"]=4
perm["-wx"]=3
perm["--x"]=1
perm["r-x"]=5
pern["-w-"]=2
}
{
 uperm = substr($1,2,3)
 gperm = substr($1,5,3)
 operm = substr($1,8,3) 
 printf "%s has permission: %s%s%s\n", $9,perm[uperm],perm[gperm],perm[operm]
}
'

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 04:25 AM.


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