0

I have a little script that have to remove some files. How can I manage the device or resource busy error of rm? Can I catch it? Like a try/catch? So that if I catch it I, for example, sleep 3 seconds and then retry..

Thanks

Ketan
  • 9,226
Cirelli94
  • 303

1 Answers1

1

If it's an error that you think will go away after some time, then you could try a simple loop:

while ! rm some files; do
    echo 'rm failed, sleeping for 5 seconds'
    sleep 5
    echo 'retrying...'
done
Kusalananda
  • 333,661