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 - 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))
Setting up multiple directories

Posted by TedH (TedH), 26 April 2007
Hi Graham, before I attempt this I thought I'd better check, because I've got feeling it could well be done the wrong way and mess things up.

I'm in the process of creating a setup script which will do the following:
1)Create a folder in the cgi-bin
 - Fill that folder with 14 scripts (after processing them).

2)Create two folders in a domain's root folder:
 - Folder 1 has 2 more folders and a few files in all 3.
 - Folder 2 has another 18 folders with around 140 files amoungst them.

Much of the work will be copy, rename and chmod. Some will be just copying images, scripts, files and putting them into their correct folders. This should be no problem for me.

I would assume there is a time element plus checking to see if each process is finished (maybe print out a notice it's been done) and done correctly. This is the bit I am unsure of. What do I need to look for in regards to this? I don't even know what terminology to use here  

There's a lot a items, so I'm trying to make the process as idiot proof as possible and all the bits will work first time.

cheers - Ted

Posted by admin (Graham Ellis), 27 April 2007
Ted, the immediate and quick answer is that is you place all your actions one after another in the same script / program, they should happen in turn with each of the items you run as a separate command or by shelling out suspecnding execution of the main script until it's completed.

Now - did I read the question right, or have I answered something else instead of what you were asking?

Posted by TedH (TedH), 27 April 2007
Hi Graham, figured as much.

"shelling out suspecnding execution of the main script until it's completed"

Does that mean waiting before running the resulting scripts?

I could have a result window - something like "Everything is now setup" and a link to an html page. That should give enough time 'just in case'. Does that sound good?

Posted by admin (Graham Ellis), 28 April 2007
on 04/27/07 at 08:41:37, TedH wrote:
"shelling out suspecnding execution of the main script until it's completed"

Does that mean waiting before running the resulting scripts?

It means that the calling script waits for one operation that it has kicked off to complete before it starts the next, so you do NOT need to take any special action.

Here's a program that does a load of setups the first time you run it, then reports what it has done on subsequent runs:

# Demonstration of shell from Perl

if (-e "demosubdir") {
       print "It already exists\n";
       print `ls -lR demosubdir`;
       print "All listed\n";
} else {
       `mkdir demosubdir`;
       `touch demosubdir/rupert.bear`;
       `touch demosubdir/momma.bear`;
       `cp peashell demosubdir/pappa.bear`;
       `od -c demosubdir/pappa.bear > demosubdir/internals`;
       print "All set up\n";

And here is how it works:

earth-wind-and-fire:~/apr07 grahamellis$ perl peashell
All set up
earth-wind-and-fire:~/apr07 grahamellis$ perl peashell
It already exists
total 16
-rw-r--r--  1 grahamel  grahamel  1687 28 Apr 07:26 internals
-rw-r--r--  1 grahamel  grahamel     0 28 Apr 07:26 momma.bear
-rw-r--r--  1 grahamel  grahamel   354 28 Apr 07:26 pappa.bear
-rw-r--r--  1 grahamel  grahamel     0 28 Apr 07:26 rupert.bear
All listed
earth-wind-and-fire:~/apr07 grahamellis$

With no need for any special timing or waiting!

Posted by TedH (TedH), 28 April 2007
Thanks Graham.

Not having seen anything like this before, I assume this is a Perl script which runs Unix commands (which I'm not allowed to do manually on my server).

I can see it checks to see if the directory exists and makes the directory "demosubdir" if it's not there. Then the "touch" - is this creating the file rupert.bear in the directory? Or checking to see if it is there?

So I would do this for each directory needed, in sequence. Or is it better to create all the directories first, then populate them (which is what I would do if doing it manually)?

I can see I'll have to dig into some Unix terminology here, hmmmm.

Cheers - Ted

Posted by admin (Graham Ellis), 28 April 2007
I don't think it's going to much matter if you create and populate the dirctories one by one, or create all the directories first then go through and populate them all.   You should consider using the built in Perl commands / functions to do as much of the work as possible as it's a little more efficient - I didn't do that on my "demo" so that I had something good with which to illustrate my answer to your earlier question.

Posted by TedH (TedH), 28 April 2007
Hi Graham, thanks a lot.
You should consider using the built in Perl commands

Yes will do.
Thanks again - Ted

This page is a thread posted to the opentalk forum at 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., 2023: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: • WEB: • SKYPE: wellho