I have the following function set up which looks at a given directory and decompresses any files using qpress. It also records how long the process runs for.
fc_decompress () {
startTime="$(date +%s)";
find "$1/" -type f -iname '*.qp' -exec sh -c 'for f in "$@"; do /usr/bin/qpress -d "$f" "$(dirname "$f")" && rm "$f"; done' find-sh {} +
endTime="$(date +%s)";
runTime=$(( ${endTime}-${startTime} ));
echo "Total Run Time: ${runTime}";
}
If I run the function as:
fc_decompress "${testDir}"
It works fine. However, on some occasions this can be a lengthy process so I figured I would run it as:
nohup sh -c 'fc_decompress "${testDir}"' &
But this no longer works, giving the error:
sh: fc_decompress: command not found
How can I pass the function into the nohup
command so I can set it running and walk away?
(fc_decompress "{testDir}" &)
. That won't be immune to SIGHUP, but won't be sent a SIGHUP either if the terminal is torn down. If that's not enough, you can trap the SIGHUP. Look here for a lengthier discussion and examples. – Feb 13 '19 at 15:45bg_nohup(){ (trap '' HUP; "$@" &) }; bg_nohup func args...
– Feb 13 '19 at 15:52(fc_decompress "{testDir}" &)
seems to do what I need. – IGGt Feb 13 '19 at 16:03