Gossamer Forum
Home : General : Perl Programming :

easy chmod

Quote Reply
easy chmod
Code:

# Build a .html file for indexing.
open (FILE, ">$build_root_path/deeplink.html") or &cgierr ("Reason: $!");
print FILE "# TL Int. # \n\n\n";
print FILE $html;
close FILE;



Currently I use the above code to build a html-file (deeplink.html), only now I need to set the permission of the file on 777. This so I can rebuild my database from telnet AND online. Why? Because my new provider doesn't support the feature that I have the same userrights on my cgi-bin - forgot the name ;-)


To do this I put the follwoing sub just after the first one, but I have no clue what it means. (the 'if' part)

It works, but shouldn't there me a easier and neater way?

Code:
if (chmod ($build_db_per, "$build_root_path/deeplink.html")) {;
# BUGFIX: Avoid permission problems.
}


But more important:

Is it dangerous to have all html-files set with permission 777. What can happen?

Last edited by:

cK: May 27, 2002, 3:35 AM
Quote Reply
Re: [cK] easy chmod In reply to
>>
It works, but shouldn't there me a easier and neater way?
<<

Im not sure why you are using the "if"....just do:

chmod ($build_db_per, "$build_root_path/deeplink.html");

If you want to check it chmods properly do:

chmod ($build_db_per, "$build_root_path/deeplink.html") || die "Could not chmod: $!";

>>
Is it dangerous to have all html-files set with permission 777. What can happen?
<<

You should use 666.
Quote Reply
Re: [Paul] easy chmod In reply to
Will 666 be enough?

With telnet and crontab the fileowner = 'mylogin'. And with online re-building I get 'permission denied to acces file' and when I delete all files and re-build them online the fileowner = '99'.

How can I easyly check without messing with my script if 666 is enough? (What is the diff. between 666 and 777.)
Quote Reply
Re: [cK] easy chmod In reply to
I would CHMOD them to 755. Just make sure to password protect your directory etc. etc. Maybe the following table will help you understand why I recommend (in your situation) to CHMOD the file to 755. In an idea world, I wouldn't recommend the setup you'e currently using, of course.

Code:
Owner Group Public
Read (4) x x x
Write (2) x
Execute (1) x x x

Totals 7 5 5

Update: Ah well. Maybe not. I think I may have mis-understood what you're trying to do here.

- wil

Last edited by:

Wil: May 27, 2002, 5:19 AM
Quote Reply
Re: [Wil] easy chmod In reply to
Would I need to use 757 ?

=> The owner 'my login' AND 'public' (when I re-build online) needs to be able to write, open en delete -html files. Or I would need to ask my hoster to install 'the feature that all cgi-bin scripts are run under my username'.
Quote Reply
Re: [cK] easy chmod In reply to
Yeah, 755 should be fine for that. I wouldn't recommend you change ownership of your CGI applications to your usernames, and I would be very worried if your host allowed this.

Why don't you try it with 755 and see what the outcome is?

- wil
Quote Reply
Re: [Wil] easy chmod In reply to
I used both 755 and 777, but this is what happens:

First deleted all files, then re-build with telnet (no problems)

Then re-build online, get: unable to chmod: deeplink.xml. Reason: Operation not permitted

Why?
Quote Reply
Re: [cK] easy chmod In reply to
Why?

You've just answered your own question by cutting and pasting the error message you got: Operation not permitted.

Now why do you want to unlink the file and then write a new one? Woulnd' it be far easier for you to set the permissions once with telnet and then just replace the file's contents or append to it as you see fit. Unlinking and then recreating the file everytime is a waste of time.

- wil
Quote Reply
Re: [Wil] easy chmod In reply to
Oeps, didn't make something clear.

Deleted all files by hand! Just to make sure I have a clean start!

Then the telnet-session build the file and set permission to 755. Direct after the online-session just tried to open (and re-write) the concent. Didn't use unlinink. And afterward the online-script didn't seems allwowed to set permissions. And that's what I didn't understand!
Quote Reply
Re: [cK] easy chmod In reply to
Why do you need to set permissions to the file through your web browser is the file has already been created with the correct permissions? Why are you trying to re-apply permissions to it after every edit?

- wil
Quote Reply
Re: [Wil] easy chmod In reply to
>Why do you need to set permissions to

I don't but it's the same script! Should I edit the script so the permissions are only set when telnetting?
Quote Reply
Re: [cK] easy chmod In reply to
OK. Reverse a few steps here. Am I right in assuming that you are:

1. Creating a file using some sort of script you run through telnet.
2. Update this file by executing a command through your web browser.

If this is the case, then you should only need to set file permissions once with a telnet command (don't even bother doing this through your script) and then your script should be able to run through your browser fine. There is no need to reset permissions every time you run the script.

- wil
Quote Reply
Re: [Wil] easy chmod In reply to
>>
I would CHMOD them to 755.
<<

You want 666 so they can be read/written by only the owner/group. Why on earth do you want them executable?