Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
I have a problem as mentioned below. Would like to know for some suitable fix for this.
In my directory structure (with some test scripts in that directory), as soon you enter some directory, one is supposed to run some pre-run script and then run the test scripts in that directory.
When they move to another directory, similarly they have to run respective pre-run script of that directory.
My problem is, people are running the pre-run script , running their scripts in that directory and are supposed to run post-run script of that directory (Which basically reset the flags set in pre-run).
But people are just moving to another directory without running post-run script. How can I tackle this problem.
Is there any lock mechanism in Linux, which basically locks the running of pre-run scripts back-to-back.
Thanks colucix for your suggestion. Even I thought of this overloading of cd at first instance, but this may irk other users of this system.
Thanks john test for your suggestion. But this may not suffice, as because I would not know which post-run script to run, if i just prepend post-run to pre-run. Because, user may come to this directory from any directory, And I need only respective directories post run to be run.
I was thinking of some lock in /tmp directory, Which I can check in every pre-run file and if not present then, I would proceed running pre-run or else, get the name of the lock (which I will create like pre-run-<directory name>, run the post-run of this directory name, then create lock for this pre-run and go on like that ...
Any improved suggestions ...
Thanks Wim Sturkenboom for your suggestion, but user may wish to run only a single script in the directory .
If I write a script to run pre-run, run scripts, post-run script, then he is always forced to run all scripts in the directory.
I want to give the user freedom to run his intended script.
But for this he had to run pre-run script, run his intended script and mandatorily run post-run script.
The users are running pre-run script to make their intended script. But they are not running post-run script (Which is not making the flags unset which were set in pre-run script.)
What you want to accomplish is usually handled by "flags." In you case, it would be simple to create a "per-user" directory in /tmp and do a touch /tmp/<user>/<directory name> when run the "start" script, and a rm -f /tmp/<user>/<directory name> when they run the "exit" script.
All the "start" scripts could check for the existence of any "unclosed" directories for the user.
The "test" scripts could also, individually, check that the "start" script had been run (and run it) before they run.
Basically, just use the existence of some (zero length) file to flag various states.
Here's some (untested) code:
[ -d "/tmp/locks/$USER" ] || mkdir "/tmp/locks/$USER"
if [ -e "/tmp/locks/$USER/$here" ]; then
echo Already started in this ("$here") directory.
for dir in "/tmp/locks/$USER/*";do
[ "$dir" = "$here" ] && continue
read -n 1 -p "You have not finished directory $dir. Do you want to do that now? (Y/n)" ans
case "$ans" in
[ -e "/tmp/locks/$USER" ] || ./initialization
if [ -e "/tmp/locks/$USER/$here ]
rm -f "/tmp/locks/$USER/$here ]
echo You can't run the finalization script unless the initialization script has been run.