LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-08-2006, 03:31 AM   #16
mike9287
Member
 
Registered: May 2006
Location: North England
Distribution: Mandriva
Posts: 64

Original Poster
Rep: Reputation: 15

Quote:
Originally Posted by timmeke
Code:
user=`whoami`;
echo "Current user is: $user";
should do it.
whoami prints the eUID (effective User ID). So, when you "su" to impersonate someone else, the whoami output changes too.

To get the name of the user who owns the file, is slightly different.
You can use your version of "stat" to get the UID and username (if available) (cfr your post of "man stat").

Hi m8,

Thanks for the Info, I need to insert the name on the same line as OWNER so what I plan to do is create a variable based on UID and then in my first SED substitution instead of getting rid of the first "-" regular file symbol of the output from ls -l completely I will replace I it with the variable, that way its on the right line to start with and my second AWK print can be{print "OWNER " $1, $2, $3, $4 }and should look like this.

OWNER $OWNER_VAR YES YES NO

Thanks for the info.

Mike
 
Old 06-08-2006, 04:47 PM   #17
mike9287
Member
 
Registered: May 2006
Location: North England
Distribution: Mandriva
Posts: 64

Original Poster
Rep: Reputation: 15
Hi temmeke, took your advice and came up with this script:

Code:
#!/bin/sh
# script to determine permission that owner, group
# and everybody has of a file passed to it
USER=`whoami`
echo "Hello $USER, which file would you like to see permissions on?"
read FILE
stat $FILE |
awk '/Uid:/ {print $2, $5}' |
sed -e 's/[0-9]//g;s/)//g;s/\///g;s/(//g; #Extract Uid and permissions
s/-//1;                                   #then convert permissions
1,9s/x/YES /g;                            #into readable form
1,9s/w/YES /g;                            #and pipe to AWK
1,9s/-/NO /g;                             #to format fields
1,9s/r/YES /g' |                          #and display relevant output
awk 'BEGIN {print "                             READ\t WRITE\t EXECUTE" "\n"}
{print "OWNER   "$10,      "            "$2"\t",$3"\t",$4"\t"}
{print "GROUP   USERS                   "$4"\t",$5"\t",$6"\t"}
{print "EVERYBODY                       "$7"\t",$8"\t",$9"\n"}'
and now I get this

Code:
Hello michael.kelly, which file would you like to see permissions on?
file
                                READ     WRITE   EXECUTE

OWNER   michael.kelly           YES      YES     YES
GROUP   USERS                   YES      NO      YES
EVERYBODY                       YES      NO      YES

[michael.kelly@unix michael.kelly]$

Not bad for a n00b who couldnt even append a line of text to a file a week ago eh?

Works fine, thanks for you help!

Mike

Last edited by mike9287; 06-08-2006 at 04:51 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash shell script - variable magic needed (no idea how to approach this) arrenlex Programming 8 03-02-2006 06:41 PM
permissions - is this the best approach? Chinook Linux - Security 3 01-19-2006 06:38 PM
Best upgrade approach oxman Fedora - Installation 2 12-24-2004 03:08 PM
backup approach ulaoulao Linux - Software 0 10-05-2004 08:03 AM
How do i approach those security advisories vavoem Linux - Security 1 09-11-2004 08:24 PM


All times are GMT -5. The time now is 08:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration