SunQuest
           Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old February 14th, 2001, 03:30 PM
ReD_5 ReD_5 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Location: LA, California
Posts: 0 ReD_5 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I wanted to set permissions for files as they are created, so I'm using the chmod function. I couldn't get it to work so I set up a "test" and still nothing.

$file_name = $co->param('file_name');
$permission = $co->param('permission');

if ($file_name) {
$success = chmod $permission, '$file_name';
if ($success == 0) {
$message = "<font face=arial color=red>Unable to set permissions for file $file_name to $permission.</font>";
}
}

Any ideas?


Reply With Quote
  #2  
Old February 14th, 2001, 05:25 PM
mickalo's Avatar
mickalo mickalo is offline
Ole` Timer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2000
Location: N.W. Iowa
Posts: 469 mickalo User rank is Private First Class (20 - 50 Reputation Level)mickalo User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 5 h 19 sec
Reputation Power: 8
Send a message via AIM to mickalo Send a message via MSN to mickalo
You made need to use back ticks to execute the system call to chmod:
Code:
$success = `chmod $permission, $file_name`;


And only use one comma, between the chmod $permission and the file_name. Besure your chmod setting is in the UNIX format, IE: 0644

Mickalo
__________________

Thunder Rain Internet Publishing

Custom Programming & Database development
Providing Personal/Business
Internet Solutions that work!

Reply With Quote
  #3  
Old February 14th, 2001, 07:35 PM
ReD_5 ReD_5 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Location: LA, California
Posts: 0 ReD_5 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy

Thanks,

I tried the back ticks...chmod still returns zero. I'm only using one comma and have the extra zero for octals. Any other ideas???

Reply With Quote
  #4  
Old February 14th, 2001, 08:20 PM
mickalo's Avatar
mickalo mickalo is offline
Ole` Timer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2000
Location: N.W. Iowa
Posts: 469 mickalo User rank is Private First Class (20 - 50 Reputation Level)mickalo User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 5 h 19 sec
Reputation Power: 8
Send a message via AIM to mickalo Send a message via MSN to mickalo
Is this on a UN*X box or NT??

Reply With Quote
  #5  
Old February 15th, 2001, 01:51 AM
ReD_5 ReD_5 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Location: LA, California
Posts: 0 ReD_5 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unix (remote-SSL Host)

Reply With Quote
  #6  
Old February 15th, 2001, 07:24 AM
mickalo's Avatar
mickalo mickalo is offline
Ole` Timer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2000
Location: N.W. Iowa
Posts: 469 mickalo User rank is Private First Class (20 - 50 Reputation Level)mickalo User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 5 h 19 sec
Reputation Power: 8
Send a message via AIM to mickalo Send a message via MSN to mickalo
Quote:
Originally posted by ReD_5
Thanks,

I tried the back ticks...chmod still returns zero. I'm only using one comma and have the extra zero for octals. Any other ideas???


Ok, I see what it is your trying to do. The $success variable is assigned a value but your not doing anthing with it, so it will always return "0". Try this:

Code:
$file_name = $co->param('file_name'); 
$permission = $co->param('permission'); 
$success = undef;
if ($file_name) { 
chmod $permission, "$file_name" and $success = 1;
if ($success != 1) {
$message = "<font face=arial color=red>Unable to set permissions for file $file_name to $permission.</font>"; 
  }
}

Now the $success variable has been assigned a value and the value is checked, and if the chmod is successfully it is set to "1" otherwise it's undefined.

Mickalo

Reply With Quote
  #7  
Old February 15th, 2001, 03:31 PM
ReD_5 ReD_5 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Location: LA, California
Posts: 0 ReD_5 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Smile

Thanks,

It works. The octals were being read as decimals so I added the oct.

chmod oct $permission, "$file_name" and $success = 1;

I originally did this

$success = chmod $permissions......

because I thought chmod returns the number of files it affects.

Again, Thanks

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > chmod func.


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway