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 script which monitors the file passwd for change, running in the background initially. This will kickoff when a session starts, executed from the .profile.
When the passwd file is modified, it will interrupt the session and prompt the user for reason of change. After entering the reason the script now starts running in the foreground, but I want it to continue running in the background doing its job of monitoring.
Is there any way we can send it to the background from within the script.
That could be a work around, but not sure what went wrong, i am having an issue now.
The main script when notices change, calls another script which should then go into interactive mode, asking the user for reason. But not, when we enter the reason, the whole thing just stops.
I put checkpoint echo commands and found that the script enters bkp_and_cmd.sh calls the function FIM_reason and exits just before entering the while loop.
It doesnt read the reason into the variable ticket.
where was a reason got read in your script. your prompt for a reason nut never read it again you are checking for an unread reason.
NO stderr re-direction so whatever error it will throw goes to foreground
here is what i suggest:
Declare functions on top.
Do the backup first as you detect a change
read as you prompt, perhaps 'read' is what you need
Use proper redirections stderr, stdin, stdout
Still the same. I tried reading the reason first and then entering into the while loop, still the result is the same.
When prompted for the reason, the reason that is entered is not read into the variable but is hitting the terminal as command and the running process gets stopped.
If we do %% and bring it to the foreground, then it proceeds as desired. I still cant catch the bug or the programming error that I might not be aware of.
[root@vmtest02 lab]# ./watchsession.sh aa &
[root@vmtest02 lab]# change detected,Changes not written yet
Enter the ticket number or reason:
-bash: testing: command not found
+ Stopped ./watchsession.sh aa
[root@vmtest02 lab]# %%
Changes written now
The reason is testing
--> resumed watching.
Is there some way to toggle a script to foreground and background from within the script.
Like here, i want it to monitor a file for changes in the background, on sensing change come to foreground, prompt the user for reason, take backup and again go background and monitor for changes and the cycle continues.
how did you read the reason , while loop and other things i suggested?
try giving good details, please don't expect only one person to answer there could be others too watching the thread and can help you much better or earlier than me,only if they have something to check from your side.