I am running the following command:
nohup myscript.sh &> file.log &
The process takes very long time to complete. The nohup will collect the output and error and write it into the file.log above.
myscript.sh will activate scripts in the background process as shown below:
# myscript.sh starts here
#!/bin/bash
status_bar(){
printf "["
While kill -0 "$1" 2>/dev/null; do
printf "-"
sleep 1
done
printf "] done!"
}
pid=()
for i "${array[@]}"; do
echo starting process for "$i"
script_A.sh "$i" &
status_bar $! # I need to print this funtion output in the terminal while running with nohup command
pid="$!"
done
for id in ${pid[*]}; do
wait $id
done
echo print its done
I need some of the lines from myscript.sh and/or script_A.sh to get written on the log file as well as to be printed on the console. I tried different approaches from the following links, but nothing seems to work. How can I do that?
redirect COPY of stdout to log file from within bash script itself
How to redirect output of an entire shell script within the script itself?
using nohup -> output to file and console
nohup myscript.sh &> file.log | tail -f file.log &
The command above works but it prints all the lines and fully populates the terminal.
I need only specific lines within myscript.sh and/or script_A.sh to printed on the console so that user don't need to always open the log file for the status. (Currently, status_bar $! output is printing in the nohup log file but not in the terminal. I need to print this funtion status_bar $! output in the terminal while running with nohup command). Thanks in Advance.