I have 2 scripts.
I'm calling my script2
as sh scriptpath/script2.sh &
inside script1
which compresses files using a combination of find
, xargs
and gzip
commands on 16 files at a time. It is basically a file watcher script integrated to run the process below after checking if a file is present. (Not cron)
Reference: https://it.toolbox.com/question/file-watcher-script-070510
find ${Filepath}/ -maxdepth 1 -type f -name "${Pattern}" -print0 | xargs -0 -t -n 1 -P 16 gzip > /dev/null
After calling my script 2, it's hanging at the command above.
Script1 session is getting closed and script2's shell is opening up with above command status. I need the gzip command of the second script to be run in the background and not the foreground.
Script1 - Generates few files. Exports variables to be used in script2
And then calls script2 as sh script2 needed parameters &
(ampersand to push script2 to go into background) and script1
completes, but after script 2 finds one touch file. It begins its execution. But the prompt of script2
where gzip
is executing after it finds touch file is coming to foreground.
Script2 Gunzips files created before calling script 2
fileflag=0
timer1=0
check_interval=300 # check every 5 minutes
(( check_interval_minutes=${check_interval}/60 ))
while [ ${timer1} -lt 180 ]
do
if [ -f /path/to/my/file ]
then
find ${Filepath}/ -maxdepth 1 -type f -name "${Pattern}" -print0 | xargs -0 -t -n 1 -P 16 gzip > /dev/null
else
sleep ${check_interval}
fi
(( timer1=${timer1} ${check_interval_minutes} ))
done
timer1=${timer1} ${check_interval_minutes}
is wrong. I guess a+
is missing there.