Monday, January 3, 2022

[SOLVED] How do I know if a bash script is running with nohup?

Issue

I have a script to process records in some files, it usually takes 1-2 hours. When it's running, it prints a progress of number of records processed.

Now, what I want to do is: when it's running with nohup, I don't want it to print the progress; it should print progress only when it run manually.

My question is how do I know if a bash script is running with nohup?

Suppose the command is nohup myscript.sh &. In the script, how do I get the nohup from command line? I tried to use $0, but it gives myscript.sh.


Solution

You could check if STDOUT is associated with a terminal:

[ -t 1 ]


Answered By - lukuluku