473,408 Members | 2,477 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Unix script for permissions

How do i write a script that takes a file as an argument and determines what permissions the owner, group and everybody has for the file?

I want to view roughly like this.
READ WRITE EXECUTE
OWNER MATT.BALLANCORE YES YES NO
GROUP USERS YES NO NO
EVERYBODY NO NO NO
Jan 15 '08 #1
3 1509
numberwhun
3,509 Expert Mod 2GB
How do i write a script that takes a file as an argument and determines what permissions the owner, group and everybody has for the file?

I want to view roughly like this.
READ WRITE EXECUTE
OWNER MATT.BALLANCORE YES YES NO
GROUP USERS YES NO NO
EVERYBODY NO NO NO

What have you tried thus far to do this? This sounds a bit like school work to me. If it is, then please post your script to do this and we can help you troubleshoot it, but please know that posting schoolwork on the site (especially expecting the answer(s)) is against the TSDN Posting Guidelines.

Regards,

Jeff
Jan 15 '08 #2
What have you tried thus far to do this? This sounds a bit like school work to me. If it is, then please post your script to do this and we can help you troubleshoot it, but please know that posting schoolwork on the site (especially expecting the answer(s)) is against the TSDN Posting Guidelines.

Regards,

Jeff
Hi Jeff, thanks for the reply.

This isn't homework, its an exercise apparrently designed to further my learning. However i'm not learning. I've been asked to further research on how to code this. Let me add, i am a complete newbie to unix. I'm familiar with the bash interface but scripting i'm finding hard to grasp. So far from my online training i've come across the the chmod command which is for permissions. I understand echo will print the text desired and > will redirect it to a file. However i have no clue to how to form the syntax. I'm use to C++ programming style and UNIX truely baffles me. Your help will be much apprieciated.
Jan 16 '08 #3
My latest attempt is :-

ls -la|grep " $1"$ | tr "\t" " " | tr -s " " | tr " " "\n" > tfile
permissions=$(head -1 tfile)
owner=$(head -3 tfile|tail -1)
rm tfile
powner=$(print -- $permissions|cut -c 2-4)
pgroup=$(print -- $permissions|cut -c 5-7)
pusers=$(print -- $permissions|cut -c 8-10)
print Filename: $1
print Owner: $owner
printf "Permissions:\tRead\tWrite\tExecute\n"

case $powner in
---)
printf "Owner:\t \tNO\tNO\tNO\n"
;;
r--)
printf "Owner:\t\tYES\tNO\tNO\n"
;;
rw-)
printf "Owner:\t\tYES\tYES\tNO\n"
;;
r-x)
printf "Owner:\t\tYES\tNO\tYES\n"
;;
rwx)
printf "Owner:\t\tYES\tYES\tYES\n"
;;
-w-)
printf "Owner:\t\tNO\tYES\tNO\n"
;;
-wx)
printf "Owner:\t\tNO\tYES\tYES\n"
;;
--x)
printf "Owner:\t\tNO\tNO\tYES\n"
;;
esac

case $pgroup in
---)
printf "Group:\t\tNO\tNO\tNO\n"
;;
r--)
printf "Group:\t\tYES\tNO\tNO\n"
;;
rw-)
printf "Group:\t\tYES\tYES\tNO\n"
;;
r-x)
printf "Group:\t\tYES\tNO\tYES\n"
;;
rwx)
printf "Group:\t\tYES\tYES\tYES\n"
;;
-w-)
printf "Group:\t\tNO\tYES\tNO\n"
;;
-wx)
printf "Group:\t\tNO\tYES\tYES\n"
;;
--x)
printf "Group:\t\tNO\tNO\tYES\n"
;;
esac

case $pusers in
---)
printf "Users:\t\tNO\tNO\tNO\n"
;;
r--)
printf "Users:\t\tYES\tNO\tNO\n"
;;
rw-)
printf "Users:\t\tYES\tYES\tNO\n"
;;
r-x)
printf "Users:\t\tYES\tNO\tYES\n"
;;
rwx)
printf "Users:\t\tYES\tYES\tYES\n"
;;
-w-)
printf "Users:\t\tNO\tYES\tNO\n"
;;
-wx)
printf "Users:\t\tNO\tYES\tYES\n"
;;
--x)
printf "Users:\t\tNO\tNO\tYES\n"
;;
esac

doesn't work tho :(

apparrently can be done within 10-25 lins without tmp file or the use of awk or sed commands
Jan 16 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Seb | last post by:
Hi, I've got something strange when uploading files on a UNIX machine with PHP 4.3.4 + Apache 1.3.29 : The uploaded file is uploaded in /va/tmp with permissions 600 (that's normal) ...
7
by: LRW | last post by:
Sorry to crosspost, but I have no idea if this is more a PHP question of general Linux question. I have a script that makes changes to image files, montages them into a jpg, and creates a Web...
3
by: dpackwood | last post by:
Hello, I have two different scripts that do pretty much the same thing. The main perl script is on Windows. It runs and in the middle of it, it then calls out another perl script that then...
2
by: gudia | last post by:
How would I, using a sql script, copy permissions assigned to a user or a role in one or more databases to another user or a role in their respective databases? Help appreciated
14
by: **--> That Guy Downstairs | last post by:
What files are needed to be #included to be able to copy files to a new directory and be portable? ie. use it in Unix (SGI and Linux) or Windows 2000. #ifdefs Ok. using dirent.h on SGI, but...
2
by: Javier | last post by:
Hello all, I'm trying to remove a hidden file (in UNIX) using the Boost::filesystem library. This is what I have: #include <boost/filesystem/operations.hpp> namespace...
0
by: =?Utf-8?B?QW5vbnltb3Vz?= | last post by:
I just posted this in microsoft.public.inetserver.iis but thought this might be a better place for it. I have the following ASP page that simply executes a DIR command on a UNC path and displays...
3
schmals
by: schmals | last post by:
Hello, I am currently writing a simple shell program for UNIX and I've run into a bit of an issue. So, every file has 9 access permissions: read, write, and execute for user, group, and others. ...
65
by: Hongyu | last post by:
Dear all: I am trying to write to a file with full directory name and file name specified (./outdir/mytestout.txt where . is the current directory) in C programming language and under Unix, but...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.