Freeing the terminal from busy shell script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Freeing the terminal from busy shell script?
# 1  
Old 04-25-2011
Freeing the terminal from busy shell script?

Hi guys,

I wrote a basic inotifywait shell script on my CentOS 5.6 x86_64 test server that syncs any deleted files in a directory.

/usr/bin/script
Code:
#!/bin/sh
inotifywait -m -e delete /home/user/test | while read file; do
	# log event here
done

The script alone works fine. However, the terminal prompt is not available.
Is there a way to pipe the response to a specific location what will still allow the script to run, so the terminal is not trapped?

Thanks for your help.
# 2  
Old 04-26-2011
./script > logfile &
# 3  
Old 04-26-2011
Thanks for your reply. Can I use /dev/null instead?

# /usr/bin/script >/dev/null 2>&1

Last edited by TECK; 04-26-2011 at 01:01 AM..
# 4  
Old 04-26-2011
If you don't want to use the output at all, how about

Code:
nohup ./script & disown

This will redirect or close all binds to the terminal when it launches the script, put it into the background, and prevent the shell from waiting for it.

disown is not available on all shells, but if you don't have it, you don't need it either.

If you want to make it a daemon, see man start-stop-daemon.
This User Gave Thanks to Corona688 For This Post:
# 5  
Old 04-26-2011
Thanks Corona. Unfortunately, CentOS does not use start-stop-daemon in their init scripts.
But the nohup did the trick nice. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to run a shell script in background without showing in the terminal?

Hi Guys, i am having a script which checks for ip address is pingable or not,when i execute this script in terminal it keeps on showing the pinging status of every ip address and it takes more time when i check for 100 ip address,How to do run a script in background without showing in the terminal... (4 Replies)
Discussion started by: Meeran Rizvi
4 Replies

2. Shell Programming and Scripting

perl: Command works in terminal, but not in shell script

Hi, the following command works in the terminal no problem. samtools view -h rawlib.bam | perl -ne '{ @line = split( /\s+/ ); $match = 0; while( $line =~ /(\d+)M/g ) { $match = $match + $1 } if( $match >= 80 || $_ =~ /^\@/ ) { print $_ } }' | java -Xmx12G -jar... (8 Replies)
Discussion started by: jdilts
8 Replies

3. Shell Programming and Scripting

How to start a shell script in a terminal console from graphic environment?

Hello. Normally when you double click on the file name, the shell script start in background. If you want to see what is going on, you must open a terminal console and start the shell within the terminal. Is it possible to start directly a shell script in a terminal console from the file... (0 Replies)
Discussion started by: jcdole
0 Replies

4. Shell Programming and Scripting

Running shell script in Cygwin terminal

I am new to shell scripting. I tried to run a simple shell script using Cygwin terminal in Win XP env. The script I have written is as follows - #!/bin/bash a=5 ] && echo "true" || echo "false" But when I execute the script, getting some confusing error. The error I am getting are - ... (3 Replies)
Discussion started by: linux_learner
3 Replies

5. Shell Programming and Scripting

executing a shell script everytime the terminal is opened

the problem statement is Write a shell script, which gets executed the moment the user opens a terminal. It should display the message "Hello your_name, welcome to 172.16.4.120 server” How to get around this? (2 Replies)
Discussion started by: arindamlive
2 Replies

6. Shell Programming and Scripting

shell script to kill process with respect to terminal

Hi, I've a script which kills all process, but i need a script shell script(sh), where it'll kill process on that particular terminal. below is example TY=`tty` for P in $TY do `kill -9 $P 2>/dev/null`; done echo "test process killed" break ... (3 Replies)
Discussion started by: asak
3 Replies

7. Shell Programming and Scripting

Set terminal width inside a shell script

Hi all, I have a shell script which uses "mailx -H" to get the subject of a email in a Linux system. However, the subject is truncated, and I think it has something to do with the terminal width because it only returns the first 80 characters of each line. I have tried "stty columns"... (7 Replies)
Discussion started by: mezzo
7 Replies

8. UNIX for Advanced & Expert Users

Filesystem mystery: disks are not busy on one machine, very busy on a similar box

Hi, We have a filesystem mystery on our hands. Given: 2 machines, A and Aa. Machine Aa is the problem machine. Machine A is running Ubuntu, kernel 2.6.22.9 #1 SMP Wed Feb 20 08:46:16 CST 2008 x86_64 GNU/Linux. Machine Aa is running RHEL5.3, kernel 2.6.18-128.el5 #1 SMP Wed Dec 17 11:41:38... (2 Replies)
Discussion started by: mschwage
2 Replies

9. Shell Programming and Scripting

open terminal to run cmd using shell script

i want the shell script to open the terminal and in that terminal i want to run a command specified in the script... how can it be done... (2 Replies)
Discussion started by: chandrabhushan
2 Replies

10. Shell Programming and Scripting

Answer Terminal Questions With Shell Script?

First off, I am using Mac OS X, with Apple Remote Desktop. I have to install several app's on teachers' laptops which are on several cd's that I have made disk images of. (DMG's) To do rollouts quicker, I have written a script to mount the disk images and running the installers inside each of... (4 Replies)
Discussion started by: The Reepr
4 Replies
Login or Register to Ask a Question