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 Maheshwari
  • 9,054
  • 6
  • 40
  • 53
Cirelli94
  • 283
  • 4
  • 10

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
  • 320,670
  • 36
  • 633
  • 936