Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
CHMOD a perl script created file

Posted by TedH (TedH), 5 June 2005
The blog script I'm working on does everything except CHMOD the small perl script used for adding a comment. It works a treat if I manually set the permission, but I need the file creation to do that.

The code seen is the sub routine which writes the script and shows the chmod code after closing the file. This chmod is straight out of the book.

Code:
# create new comment write script
sub newWrite {
# start
$thefile = "templates/blank.pl";   # Template file
$filext = "pl";
$newwfile = "$thefolder/$kdate";
# variables for perl script write
$a="\#\!/usr/bin/perl";
$b="require \"../shared.pl\"\;";
$c="\$cmfile \= \"$cmntbits.html\"\;";                    
$d="\$cmurl \= \"http\://www.mydomain.com/cgi-bin/myfolder/$thefolder/$cmntbits.html\"\;";
$e="\&postComment\;";

open(FILE, "<$thefile" ) ;
close(FILE) ;

open(FILE, ">$newwfile".".$filext" );
 print FILE "$a\n$b\n$c\n$d\n$e\n";
close(FILE);

### file is closed why doesn't it chmod???

# the chmod needs to have the ID number (date and time to the minute) of the entry in.
# This is record $kdate which is the ID extracted from
# the database specifically for this file's creation.
# the variable $newfile is folder and file
# The format of the chmod code is straight out of the book
# I've tried with and without quotes to no avail

chmod(0755, $newwfile);  ## the permission

}



No idea why it doesn't work - even tried full server path with no result.

Suggestions....

cheers - Ted

Posted by admin (Graham Ellis), 6 June 2005
Some ideas:

a) chmod returns the number of files successfully changed - have you checked the returned value to see whether it thinks it has succeeeded or not?   How about all the other special variables that contain error statuses (they're a bit of a mess in Perl 5!)

b) What operating system are you using?   What version of Perl?  The number given as parameter to "chmod" is Unix / Linux based, and on other operating systems it does its best - the term "moral equivalent" is sometimes used ... but of course it can't set something that's impossible.

c) What user is your script running as?  If it's under the control of the web server, then it *may* be as a different user to the command line and the directory permissions may effect things

d) (just noticed this).  What's in your $filext variable?  Shouldn't it be appended on to the end of the file name in your chmod like it is in your open?  In fact -- try this first - I think it's the likely solution.

Posted by TedH (TedH), 7 June 2005
Duhhhh!! Well.......

Graham may take out his ruler and rap my knuckles..

..only forgot to have a letter or 2 on the perl script's name didn't I.

Put a couple letters before the $kdate bit and it worked a treat.

It's at http://bluwall.com/td

still a lot of things to do yet but at least I'm getting there.

- Ted

Posted by admin (Graham Ellis), 7 June 2005
All bugs ore obvious once you've found them  



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho