lsof command is used fot the open files in linux.Which command is used for checking if file is not open.I want to use in my script
lsof命令用于linux中的打开文件.Which命令用于检查文件是否未打开。我想在我的脚本中使用
my condition is
我的病情是
do
if [[ 'lsof | grep $r_error_file' ]]
then
error_text=$error_text$(tail -n +1 $r_error_file | grep 'Error\')
mv $r_error_file $(dirname ${r_error_file})/BkError/$(filename ${r_error_file})
fi
done
2 个解决方案
#1
1
Use fuser
command
使用fuser命令
fuser $filename
if [ $? ne 0 ]
then
# file is open, Add your code here
fi
#2
0
You need the case where the lsof
statement is false. There's a useful list of methods for manipulating truth in if statements here; but to ruin your fun serarching, you're looking for
您需要lsof语句为false的情况。这里有一个有用的方法列表,用于处理if语句中的真值;但要破坏你的乐趣,你正在寻找
if [[ ! `lsof | grep $r_error_file` ]]
then
...
fi
#1
1
Use fuser
command
使用fuser命令
fuser $filename
if [ $? ne 0 ]
then
# file is open, Add your code here
fi
#2
0
You need the case where the lsof
statement is false. There's a useful list of methods for manipulating truth in if statements here; but to ruin your fun serarching, you're looking for
您需要lsof语句为false的情况。这里有一个有用的方法列表,用于处理if语句中的真值;但要破坏你的乐趣,你正在寻找
if [[ ! `lsof | grep $r_error_file` ]]
then
...
fi