Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi all.

I'm trying to install a yabb forum on my web space but I'm having problems setting chmod permissions for each of the folders - there are dozens of files and folders that need setting. I'm suprised that a script isn't included to do this automatically. Anyway, can anyone suggest a script which could read the lists below and in turn issue the correct chmod command.

Thanks.

------- NON cgi-bin section --------- * drwxrwxrwx (chmod 777)public_html/yabbfiles * -rw-rw-rw- (chmod 666)(in ASCII)public_html/yabbfiles/*.js * drwxrwxrwx (chmod 777)public_html/yabbfiles/Attachments * drwxrwxrwx (chmod 777)public_html/yabbfiles/avatars * -rw-rw-rw- (chmod 666)(in Binary)public_html/yabbfiles/avatars/* + (all files) * drwxrwxrwx (chmod 777)public_html/yabbfiles/Buttons * -rw-rw-rw- (chmod 666)(in Binary)public_html/yabbfiles/Buttons/E +nglish/* (all files) * drwxrwxrwx (chmod 777)public_html/yabbfiles/ModImages * drwxrwxrwx (chmod 777)public_html/yabbfiles/Smilies * -rw-rw-rw- (chmod 666)(in Binary)public_html/yabbfiles/Smilies/* + (all files) * drwxrwxrwx (chmod 777)public_html/yabbfiles/Templates/Admin * -rw-rw-rw- (chmod 666)(in Binary)public_html/yabbfiles/Templates +/Admin/default/* (all files) * -rw-rw-rw- (chmod 666)(in ASCII)public_html/yabbfiles/Templates/ +Admin/default.css * drwxrwxrwx (chmod 777)public_html/yabbfiles/Templates/Forum * -rw-rw-rw- (chmod 666)(in Binary)public_html/yabbfiles/Templates +/Forum/default/* (all files) * -rw-rw-rw- (chmod 666)(in ASCII)public_html/yabbfiles/Templates/ +Forum/default.css ------- CGI-BIN section (all files in ASCII) --------- * -rwxr-xr-x (chmod 755)cgi-bin/yabb2 * -rwxr-xr-x (chmod 755)cgi-bin/yabb2/AdminIndex.pl * -rwxr-xr-x (chmod 755)cgi-bin/yabb2/FixFile.pl * -rw-rw-rw- (chmod 666)cgi-bin/yabb2/Paths.pl * -rwxr-xr-x (chmod 755)cgi-bin/yabb2/Setup.pl * -rwxr-xr-x (chmod 755)cgi-bin/yabb2/YaBB.pl * drwxrwxrwx (chmod 777)cgi-bin/yabb2/Admin * -rw-rw-rw- (chmod 666)cgi-bin/yabb2/Admin/* (all files) * drwxrwxrwx (chmod 777)cgi-bin/yabb2/Boards * -rw-rw-rw- (chmod 666)cgi-bin/yabb2/Boards/* (all files) * drwxrwxrwx (chmod 777)cgi-bin/yabb2/Convert * drwxrwxrwx (chmod 777)cgi-bin/yabb2/Convert/Boards * drwxrwxrwx (chmod 777)cgi-bin/yabb2/Convert/Members * drwxrwxrwx (chmod 777)cgi-bin/yabb2/Convert/Messages * drwxrwxrwx (chmod 777)cgi-bin/yabb2/Convert/Variables * drwxrwxrwx (chmod 777)cgi-bin/yabb2/Help/English/Admin * -rwxrwxrwx (chmod 777)cgi-bin/yabb2/Help/English/Admin/* (all fi +les) * drwxrwxrwx (chmod 777)cgi-bin/yabb2/Help/English/Gmod * -rwxrwxrwx (chmod 777)cgi-bin/yabb2/Help/English/Gmod/* (all fil +es) * drwxrwxrwx (chmod 777)cgi-bin/yabb2/Help/English/Moderator * -rwxrwxrwx (chmod 777)cgi-bin/yabb2/Help/English/Moderator/* (al +l files) * drwxrwxrwx (chmod 777)cgi-bin/yabb2/Help/English/User * -rwxrwxrwx (chmod 777)cgi-bin/yabb2/Help/English/User/* (all fil +es) * drwxrwxrwx (chmod 777)cgi-bin/yabb2/Languages/English * -rw-rw-rw- (chmod 666)cgi-bin/yabb2/Languages/English/agreement. +txt * -rw-rw-rw- (chmod 666)cgi-bin/yabb2/Languages/English/censor.txt * drwxrwxrwx (chmod 777)cgi-bin/yabb2/Languages/English/* (remaini +ng files) * drwxrwxrwx (chmod 777)cgi-bin/yabb2/Members * -rw-rw-rw- (chmod 666)cgi-bin/yabb2/Members/* (all files) * drwxrwxrwx (chmod 777)cgi-bin/yabb2/Messages * -rw-rw-rw- (chmod 666)cgi-bin/yabb2/Messages/* (all files) * drwxrwxrwx (chmod 777)cgi-bin/yabb2/Modules/Digest * -rwxrwxrwx (chmod 777)cgi-bin/yabb2/Modules/Digest/HMAC_MD5.pm * -rwxrwxrwx (chmod 777)cgi-bin/yabb2/Modules/Digest/MD5.pm * drwxrwxrwx (chmod 777)cgi-bin/yabb2/Modules/Time * -rwxrwxrwx (chmod 777)cgi-bin/yabb2/Modules/Time/HiRes.pm * drwxrwxrwx (chmod 777)cgi-bin/yabb2/Modules/Upload * -rwxrwxrwx (chmod 777)cgi-bin/yabb2/Modules/Upload/CGI.pm * drwxrwxrwx (chmod 777)cgi-bin/yabb2/Modules/Upload/CGI * -rwxrwxrwx (chmod 777)cgi-bin/yabb2/Modules/Upload/CGI/Util.pm * drwxrwxrwx (chmod 766 or 777)cgi-bin/yabb2/Sources * -rwxr-xr-x (chmod 755)cgi-bin/yabb2/Sources/* (all files) * drwxrwxrwx (chmod 766 or 777)cgi-bin/yabb2/Templates * drwxrwxrwx (chmod 766 or 777)cgi-bin/yabb2/Templates/default * -rw-rw-rw- (chmod 666)cgi-bin/yabb2/Templates/default/* (all fil +es) * drwxrwxrwx (chmod 766 or 777)cgi-bin/yabb2/Variables * -rw-rw-rw- (chmod 666)cgi-bin/yabb2/Variables/* (all files)

READMORE tags added by Arunbear

Replies are listed 'Best First'.
Re: Issuing chmod commands using perl
by ambrus (Abbot) on Feb 19, 2006 at 15:08 UTC

    If the task is simple enough, you can try solving this without perl, using find and other utilities. An untested example is

    find . -type d -print0 | xargs -0 chmod 00777

    If you have to use perl, I recommend the File::Find module or merlyn's File::Finder.

    Update: I've misunderstood the question, sorry. You want to read the filenames from the list you gave, not blindly chmod all files.

Re: Issuing chmod commands using perl
by turo (Friar) on Feb 19, 2006 at 17:37 UTC

    I've made an script, that read the list you subbmitted ... You can generate a shell script, for chmodding all your listed files:

    perl -ne '($permissions,$file)=/(\d{3})\)(?:[^\)]+\))?(\S+)/ and print + "chmod $permissions $file\n"' list
    ...

    Hope that helps ...

    perl -Te 'print map { chr((ord)-((10,20,2,7)[$i++])) } split //,"turo"'
      In your script, insert something like -
      system ("chmod 755 cgi-bin/yabb2"); system ("chmod 755 cgi-bin/yabb2/AdminIndex.pl"); system ("chmod 755 cgi-bin/yabb2/FixFile.pl"); system ("chmod 666 cgi-bin/yabb2/Paths.pl"); system ("chmod 755 cgi-bin/yabb2/Setup.pl"); system ("chmod 755 cgi-bin/yabb2/YaBB.pl"); system ("chmod 777 cgi-bin/yabb2/Admin"); system ("chmod 666 cgi-bin/yabb2/Admin/*"); system ("chmod 777 cgi-bin/yabb2/Boards"); system ("chmod 666 cgi-bin/yabb2/Boards/*"); system ("chmod 777 cgi-bin/yabb2/Convert"); system ("chmod 777 cgi-bin/yabb2/Convert/Boards"); system ("chmod 777 cgi-bin/yabb2/Convert/Members"); system ("chmod 777 cgi-bin/yabb2/Convert/Messages"); system ("chmod 777 cgi-bin/yabb2/Convert/Variables"); system ("chmod 777 cgi-bin/yabb2/Help/English/Admin"); system ("chmod 777 cgi-bin/yabb2/Help/English/Admin/*"); system ("chmod 777 cgi-bin/yabb2/Help/English/Gmod"); system ("chmod 777 cgi-bin/yabb2/Help/English/Gmod/*"); system ("chmod 777 cgi-bin/yabb2/Help/English/Moderator"); system ("chmod 777 cgi-bin/yabb2/Help/English/Moderator/*"); system ("chmod 777 cgi-bin/yabb2/Help/English/User"); system ("chmod 777 cgi-bin/yabb2/Help/English/User/*"); system ("chmod 777 cgi-bin/yabb2/Languages/English"); system ("chmod 666 cgi-bin/yabb2/Languages/English/agreement.txt"); system ("chmod 666 cgi-bin/yabb2/Languages/English/censor.txt"); system ("chmod 777 cgi-bin/yabb2/Languages/English/*"); system ("chmod 777 cgi-bin/yabb2/Members"); system ("chmod 666 cgi-bin/yabb2/Members/*"); system ("chmod 777 cgi-bin/yabb2/Messages"); system ("chmod 666 cgi-bin/yabb2/Messages/*"); system ("chmod 777 cgi-bin/yabb2/Modules/Digest"); system ("chmod 777 cgi-bin/yabb2/Modules/Digest/HMAC_MD5.pm"); system ("chmod 777 cgi-bin/yabb2/Modules/Digest/MD5.pm"); system ("chmod 777 cgi-bin/yabb2/Modules/Time"); system ("chmod 777 cgi-bin/yabb2/Modules/Time/HiRes.pm"); system ("chmod 777 cgi-bin/yabb2/Modules/Upload"); system ("chmod 777 cgi-bin/yabb2/Modules/Upload/CGI.pm"); system ("chmod 777 cgi-bin/yabb2/Modules/Upload/CGI"); system ("chmod 777 cgi-bin/yabb2/Modules/Upload/CGI/Util.pm"); system ("chmod 766 cgi-bin/yabb2/Sources"); system ("chmod 755 cgi-bin/yabb2/Sources/*"); system ("chmod 766 cgi-bin/yabb2/Templates"); system ("chmod 766 cgi-bin/yabb2/Templates/default"); system ("chmod 666 cgi-bin/yabb2/Templates/default/*"); system ("chmod 766 cgi-bin/yabb2/Variables"); system ("chmod 666 cgi-bin/yabb2/Variables/*");

        I said shell script ... not perl script ...
        to make a perl script, would be more cool to use the 'chmod' perl function; but it didn't works for wildcarded paths like "/home/somewhere/*" ...

        A little more work ... but yesterday, i was a little bit lazzy ...

        Regards
        turo

        perl -Te 'print map { chr((ord)-((10,20,2,7)[$i++])) } split //,"turo"'
A reply falls below the community's threshold of quality. You may see it by logging in.