1

Problem is that i have a bash script that requires user to login and perform operations. Everything is logged in a log file. Now issue is if user exits the terminal, the scripts keeps running and keeps logging as enter key as an input even though no one is using the script. I want help such that if terminal is closed, the script itself kills its PID. or If multiple times enter key is given as input, the script kills its PID.

Any help in this regard will be appreciated.

I am using bash scripting and using AIX.

0

Maybe build a while loop, which checks, if there are processes left, which belong to a given user like so:

while ps aux | cut -f1 -d ' ' | sort | uniq | grep -q username; do FancyCommand; sleep 1; done

if there are no more PIDs belonging to the user, the loop will stop.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.