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

#!/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.

./script > logfile &

Thanks for your reply. Can I use /dev/null instead?

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

If you don't want to use the output at all, how about

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.

1 Like

Thanks Corona. Unfortunately, CentOS does not use start-stop-daemon in their init scripts.
But the nohup did the trick nice. :slight_smile: