Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking File Permissions 1

Status
Not open for further replies.

ryanc2

MIS
Apr 18, 2003
73
US
We have a script that was written to read a control file to delete records within certain directories. However, if the permissions aren't set correctly on the control file, the script deletes everything from the current working directory.

How can you check the permissions of a file in a if...then statement before moving on in the script to delete.

Thanks!
 
Not the full solution, but you can use it as a basis for your own.


perms=`ls -l file_to_check|cut -b 2-10`

owner_r=`echo $perms|cut -b 1`
owner_w=`echo $perms|cut -b 2`
owner_x=`echo $perms|cut -b 3`
group_r=`echo $perms|cut -b 4`
group_w=`echo $perms|cut -b 5`
group_x=`echo $perms|cut -b 6`
other_r=`echo $perms|cut -b 7`
other_w=`echo $perms|cut -b 8`
other_x=`echo $perms|cut -b 9`

After you have the variables you can just act on them.


Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
from man ksh

-f file True if file exists and is an ordinary file.
-r file True if file exists and is readable by current process.
-w file True if file exists and is writable by current process.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top