How to Continously Run a Unix Script in Background Without Using Crontab.

How can I keep running a unix program in the background even if I log out?

My preferred method, and arguably the easiest, is using screen:

screen -d -m ./myProcess

how to run a bash script in background automatically?

write a shell script

rm /home/c/temp/*

and add a line in the crontab

crontab -e

add the line

0 12 * * * path/to/script

It will execute you script every day at midday.

Execute script recursively without cron

If you schedule it from cron, then it isn't recursive. If you want the script to run recursively, then the answer is pretty self-evident: it should call itself. Just add:

exec $0 "$@"

at the end of the script, and make sure that during the run you don't change the positional parameters. (If you change them, you'll need to save their original values so you can call the script with them.)

edit--now that the question has been clarified in comments.

If you expect to receive a numeric argument and want to increment it by 10 on each run, then do:

exec $0 $(expr $1 + 10)

as the last line of the script. But it seems somewhat silly to do this recursively, as it makes more sense to simply execute a loop in the script.

How to run a script in the background even after I logout SSH?

Run nohup python bgservice.py & to get the script to ignore the hangup signal and keep running. Output will be put in nohup.out.

Ideally, you'd run your script with something like supervise so that it can be restarted if (when) it dies.

How to run infinitely script in background on Linux?

nohup is your friend.

nohup command &

Can I run inotifywait continually on a Linux Server without cron or incron

If a controlling terminal is closed, the child processes get signals which -if not caught- terminate them by design.

Hangup signal

If you want a child process to be shielded from this, you can start it protecting with by the nohup command.

nohup command

To start a command in the background, you apply (with most, if not all shells) & at the end.

How to get a unix script to run every 15 seconds?

I would use cron to run a script every minute, and make that script run your script four times with a 15-second sleep between runs.

(That assumes your script is quick to run - you could adjust the sleep times if not.)

That way, you get all the benefits of cron as well as your 15 second run period.

Edit: See also @bmb's comment below.



Related Topics



Leave a reply



Submit