place a shell script with tail -f in the back ground
Following script name is 123.sh and I need to put this in the background if I do 123.sh -bg this will not bring me back to the prompt but echoes what ever I put (using echo hello >> /tmp/123) in to the /temp/123 file. the only way that I have found doing this is to do "nohup 123.sh &" to put this in to the background. Is this okay or is there any better way of doing this?
#!/bin/bash # file name is 123.sh tail -f /temp/123 | while read line do echo "Loop rane for $COUNT times" let COUNT=$COUNT+1 done Thank you Best Regards |
Hello,
If you run a script like this: Code:
./scriptname.sh -bg You can execute the script directly with & at the end like this: Code:
./scriptname.sh & You can also put a script in the background with CTRL-Z until you need the script to run again. Putting it in the background this way will stop the script. The only way I know of to 'detach' a script from a terminal/console/session is by using nohup like you did. Kind regards, Eric |
Hi EricTRA, thanks for the reply
|
Hi,
You're welcome! If you consider your question/problem solved then please mark it as such using the Thread Tools. Kind regards, Eric |
Hi EricTRA, one more thing, how do I write -bg in to the script, any resource that I could refer to?
Thanks and Best Regards |
Hello,
If you only want the loop in the background then you do it like this: Code:
#!/bin/bash Best reading material I've encountered is in my personal opinion: Bash Guide for Beginners and Advanced Bash Scripting Guide in which you can find this example. Kind regards, Eric |
Grete EricTRA, thanks you and Best Regards
|
All times are GMT -5. The time now is 07:39 PM. |