How to manage “device or resource busy” in a script?
up vote
0
down vote
favorite
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
shell-script rm
add a comment |
up vote
0
down vote
favorite
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
shell-script rm
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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
shell-script rm
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
shell-script rm
shell-script rm
edited Jun 14 '17 at 13:00
Ketan
5,75842742
5,75842742
asked Jun 14 '17 at 12:29
Cirelli94
1011
1011
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
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
add a comment |
up vote
0
down vote
If you want to catch THAT specific error, try to probe the error code 16
on your last rm
execution. Example:
rm /path/to/foo
if [ $? -eq 16 ]; then
echo "Device busy"
fi
$?
is the special shell variable that means "exit state of the last command". If this state is zero 0
, means that the last command succeded, and if different than zero means failure and it maps to an error message. All error messages are available at Linux source file linux/include/uapi/asm-generic/errno-base.h
, and 16
is:
#define EBUSY 16 /* Device or resource busy */
If you want to deal with the proccess that is causing the open file error lsof +D /path/too/foo/
will show what files are opened inside that directory. lsof(8)
manpage.
Related stuff:
- Device or resource busy
- How to get over “device or resource busy”?
- Meaning of $? in shell scripts
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
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
add a comment |
up vote
0
down vote
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
add a comment |
up vote
0
down vote
up vote
0
down vote
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
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
answered Jun 14 '17 at 12:35
Kusalananda
119k16223364
119k16223364
add a comment |
add a comment |
up vote
0
down vote
If you want to catch THAT specific error, try to probe the error code 16
on your last rm
execution. Example:
rm /path/to/foo
if [ $? -eq 16 ]; then
echo "Device busy"
fi
$?
is the special shell variable that means "exit state of the last command". If this state is zero 0
, means that the last command succeded, and if different than zero means failure and it maps to an error message. All error messages are available at Linux source file linux/include/uapi/asm-generic/errno-base.h
, and 16
is:
#define EBUSY 16 /* Device or resource busy */
If you want to deal with the proccess that is causing the open file error lsof +D /path/too/foo/
will show what files are opened inside that directory. lsof(8)
manpage.
Related stuff:
- Device or resource busy
- How to get over “device or resource busy”?
- Meaning of $? in shell scripts
add a comment |
up vote
0
down vote
If you want to catch THAT specific error, try to probe the error code 16
on your last rm
execution. Example:
rm /path/to/foo
if [ $? -eq 16 ]; then
echo "Device busy"
fi
$?
is the special shell variable that means "exit state of the last command". If this state is zero 0
, means that the last command succeded, and if different than zero means failure and it maps to an error message. All error messages are available at Linux source file linux/include/uapi/asm-generic/errno-base.h
, and 16
is:
#define EBUSY 16 /* Device or resource busy */
If you want to deal with the proccess that is causing the open file error lsof +D /path/too/foo/
will show what files are opened inside that directory. lsof(8)
manpage.
Related stuff:
- Device or resource busy
- How to get over “device or resource busy”?
- Meaning of $? in shell scripts
add a comment |
up vote
0
down vote
up vote
0
down vote
If you want to catch THAT specific error, try to probe the error code 16
on your last rm
execution. Example:
rm /path/to/foo
if [ $? -eq 16 ]; then
echo "Device busy"
fi
$?
is the special shell variable that means "exit state of the last command". If this state is zero 0
, means that the last command succeded, and if different than zero means failure and it maps to an error message. All error messages are available at Linux source file linux/include/uapi/asm-generic/errno-base.h
, and 16
is:
#define EBUSY 16 /* Device or resource busy */
If you want to deal with the proccess that is causing the open file error lsof +D /path/too/foo/
will show what files are opened inside that directory. lsof(8)
manpage.
Related stuff:
- Device or resource busy
- How to get over “device or resource busy”?
- Meaning of $? in shell scripts
If you want to catch THAT specific error, try to probe the error code 16
on your last rm
execution. Example:
rm /path/to/foo
if [ $? -eq 16 ]; then
echo "Device busy"
fi
$?
is the special shell variable that means "exit state of the last command". If this state is zero 0
, means that the last command succeded, and if different than zero means failure and it maps to an error message. All error messages are available at Linux source file linux/include/uapi/asm-generic/errno-base.h
, and 16
is:
#define EBUSY 16 /* Device or resource busy */
If you want to deal with the proccess that is causing the open file error lsof +D /path/too/foo/
will show what files are opened inside that directory. lsof(8)
manpage.
Related stuff:
- Device or resource busy
- How to get over “device or resource busy”?
- Meaning of $? in shell scripts
edited Jun 14 '17 at 12:56
answered Jun 14 '17 at 12:39
nwildner
13.8k14075
13.8k14075
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f371074%2fhow-to-manage-device-or-resource-busy-in-a-script%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown