I have a shell script similar to the following:
#!/bin/bash # Here is where I set a bunch of environment variables that are # used by the process invoked below... # Now I want to invoke the process in the background and redirect # all of the output to a log file. nohup name-of-executable > logfile.out 2>&1 & # Finally, I record the PID of the process before the script exits. echo $! > proc.pid
The use case is that periodically, someone will ssh into this machine, kick off this process and then log out of the machine. I just need to have the log file created so I can debug any issues encountered during the execution of the process.
When using my script above, the process executes correctly, the logfile is created, but no output ever gets written to the log file. I just get a zero-length file.
If I run the command
nohup name-of-executable > logfile.out 2>&1 & directly from the command line, the process executes and logs data as expected. I just don't know how to do this as part of a shell script.