Job Control: How to save output of background job in a variable
2
votes
1
answer
2788
views
Using Bash in OSX.
My script has these 2 lines:
nfiles=$(rsync -auvh --stats --delete --progress --log-file="$SourceRoot/""CopyLog1.txt" "$SourceTx" "$Dest1Tx" | tee /dev/stderr | awk '/files transferred/{print $NF}') &
nfiles2=$(rsync -auvh --stats --delete --progress --log-file="$SourceRoot/""CopyLog2.txt" "$SourceTx" "$Dest2Tx" | tee /dev/stderr | awk '/files transferred/{print $NF}')
When I use the
&
after the first line (to run the two rsync commands in parallel), my later call to $nfiles
returns nothing.
Code:
osascript -e 'display notification "'$nfiles' files transferred to MASTER," & return & "'$nfiles2' transferred to BACKUP," & return & "Log Files Created" with title "Copy Complete"'
Can't figure out what's going on. I need the 2 rsyncs to run simultaneously.
Asked by user192259
(51 rep)
Sep 30, 2016, 12:48 AM
Last activity: Mar 1, 2025, 02:01 PM
Last activity: Mar 1, 2025, 02:01 PM