I want to keep polling file till it arrives at the location for 1 hour.
My dir : /home/stage
File Name (which I am looking for): abc.txt
I want to keep polling directory /home/stage
for 1 hour but within the 1 hour if abc.txt
file arrives then it should stop polling and should display the message file arrived
otherwise after 1 hour it should display that file has not arrived
.
Is there any way to achieve this in Unix?
Another bash
method, not relying on trap handlers and signals, in case your larger scope already uses them for other things:
#!/bin/bash
interval=60
((end_time=${SECONDS}+3600))
directory=${HOME}
file=abc.txt
while ((${SECONDS} < ${end_time}))
do
if [[ -r ${directory}/${file} ]]
then
echo "File has arrived."
exit 0
fi
sleep ${interval}
done
echo "File did not arrive."
exit 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With