有没有检测一个陈旧的NFS挂载的好方法 [英] Is there a good way to detect a stale NFS mount
问题描述
我有一个程序我想启动仅在多次测试成功完成。
I have a procedure I want to initiate only if several tests complete successfully.
一个测试我需要的是我所有的NFS挂载都活得很好。
One test I need is that all of my NFS mounts are alive and well.
我可以做得比蛮力的方法更好:
Can I do better than the brute force approach:
mount | sed -n "s/^.* on \(.*\) type nfs .*$/\1/p" |
while read mount_point ; do
timeout 10 ls $mount_point >& /dev/null || echo "stale $mount_point" ;
done
下面暂停
是会在后台运行的命令,一定时间后会杀了它,如果没有 SIGCHLD 实用程序code>之前的时间限制被抓,返回成功/失败的明显的方式。
Here timeout
is a utility that will run the command in the background, and will kill it after a given time, if no SIGCHLD
was caught prior to the time limit, returning success/fail in the obvious way.
在英语:解析安装
的输出,检查(超时为界)每个NFS挂载点。可选的(不是在$ C $以上三)打破的第一个陈旧的坐骑。
In English: Parse the output of mount
, check (bounded by a timeout) every NFS mount point. Optionally (not in the code above) breaking on the first stale mount.
推荐答案
您可以写一个C程序,并检查 ESTALE
。
You could write a C program and check for ESTALE
.
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <iso646.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
int main(){
struct stat st;
int ret;
ret = stat("/mnt/some_stale", &st);
if(ret == -1 and errno == ESTALE){
printf("/mnt/some_stale is stale\n");
return EXIT_SUCCESS;
} else {
return EXIT_FAILURE;
}
}
这篇关于有没有检测一个陈旧的NFS挂载的好方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!