Skip to content

Instantly share code, notes, and snippets.

@jeansymolanza
Last active February 6, 2024 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeansymolanza/75f93e7874706c20e8692597d553cee5 to your computer and use it in GitHub Desktop.
Save jeansymolanza/75f93e7874706c20e8692597d553cee5 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Wrapper script to run commands with simulated interactive activity
# Command and arguments to run
CMD="$@"
# Function to simulate interactive activity
keep_alive() {
while true; do
# Send a harmless command to the shell to reset TMOUT
# Using 'date' as an example - it's benign and universally available
echo "Keep-alive signal sent at $(date)"
sleep 60 # Adjust the sleep duration to a suitable value less than TMOUT
# Check if the main command is still running
if ! kill -0 $1 2>/dev/null; then
echo "Main command completed"
return
fi
done
}
# Start the main command in the background
$CMD &
cmd_pid=$!
# Start the keep-alive function in the background
keep_alive $cmd_pid &
keep_alive_pid=$!
# Wait for the main command to finish and capture its exit status
wait $cmd_pid
cmd_exit_status=$?
# Once main command is done, kill the keep-alive process
kill $keep_alive_pid
# Exit with the status of the main command
exit $cmd_exit_status
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment