scripting - Is there a way to create a bash script that will only run for X hours? -
is there way create bash script run x hours? i'm setting cron job initiate script every night. script runs until condition met, exporting it's status holding variable keep track of 'where is' after each iteration. intention start-up process every night, run few hours, , stop, holding status until process starts next night. short of somehow collecting start time, , checking against current time in each iteration of loop, there easier way this? bash scripting not forte (i know enough things done , dangerous) , have not done before. appreciated. thanks. use gnu coreutils gnu coreutils contains actual timeout binary, invoked this: # timeout after 5 seconds when sleeping 30 /usr/bin/timeout 5s /bin/sleep 30 in case, you'd want specify hours instead of seconds, timeout in 2 hours use 2h instead of 5s . see timeout(1) or info coreutils 'timeout invocation' additional options. hacks , workarounds native timeouts or gnu timeout command be