This Copy Process takes some times lets say 15 min.
Now I want When This copy process gets complete then send me an email.
But My problem is This command is running in Background So How can i send a mail.
I know how to send Mail but i don't know how to send mail when process is running in Background.
Please help me out?
Store the PID of the SCP Job (in Shell, PID of immediate backgrounded job can be derived by: BGPROC_PID=$!
Monitor the processes in a loop for the presence of above Backgrounded process
Here is equivalent UNIX Code
scp -r machinename:/PathOfFile/ /Path/WhereToCopyIt/ 1>/dev/null 2>/dev/null &
BGPID=$!
while [ 1 ]; do
PR_EX=$(ps -ef | awk -v BGPID=${BGPID} '{if ($2 == BGPID) print "Process with PID '"$BGPID"' exists"}')
if [[ ${PR_EX} = "Process with PID $BGPID exists" ]]; then
echo "Waiting for the Process with PID ${BGPID} to complete its execution"
echo "Sleeping for 5 Seconds"
sleep 5
continue
else
echo "Process with PID ${BGPID} executed successfully"
break
fi
done