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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
file permissions ranj@chn Shell Programming and Scripting 7 06-11-2008 08:37 AM
To give the "unzip" permissions & "create" file permissions Mike1234 HP-UX 3 03-02-2008 02:34 PM
help with file permissions bbbngowc Security 3 12-21-2007 10:34 AM
File permissions beginner1 UNIX for Dummies Questions & Answers 5 04-12-2006 09:56 AM
File and Dir permissions thomas.jones UNIX for Dummies Questions & Answers 11 04-19-2002 06:35 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 05-31-2005
mohanprabu's Avatar
Registered User
 

Join Date: Nov 2004
Posts: 16
file permissions

Hi!

Is there any shell parameter that I can use in my script to check the file-permissions I have in the currect directory!?

The history behind is: My script tries to create some log files in the folder and I want to see whether I have enough permissions to do that. And exit in case I dont have.

currently I create a temp file using touch command, and check the return code ($?) of that command, and exit if it is non-zero, and remove the temp file if zero. This is a unwanted process!!

Thanks in advance,

Mohan.
Reply With Quote
Forum Sponsor
  #2  
Old 05-31-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,683
You could use

Code:
stat -c=%a logfile
That would return something like

=600 which is equivalent to -rw-------

Vino
Reply With Quote
  #3  
Old 05-31-2005
Just Ice's Avatar
Lights on, brain off.
 

Join Date: Mar 2005
Location: in front of my computer
Posts: 629
instead of creating a temp file --- create the logfile instead, check for it and exit your script if you can't create the logfile ...

echo > $logfile
[ ! -f $logfile ] && exit
Reply With Quote
  #4  
Old 05-31-2005
zazzybob's Avatar
Registered Geek
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
Code:
$ mkdir tmpdir
$ ls -ld tmpdir
drwxr-xr-x 2 bozo bozogroup 0 May 31 23:02 tmpdir
$ [ -w "./tmpdir" ] && echo "Yes I can write..."
Yes I can write...
$ chmod 500 tmpdir             
$ ls -ld tmpdir
dr-x------ 2 bozo bozogroup 0 May 31 23:02 tmpdir
$ [ -w "./tmpdir" ] && echo "Yes I can write..."
$
Cheers
ZB
Reply With Quote
  #5  
Old 05-31-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,683
[ -w "./tmpdir" ] && echo "Yes I can write..."

Perfect !

--Ripeness of experience seeks brevity of expression--

Vino
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 02:31 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0