- 论坛徽章:
- 18
|
本帖最后由 bikkuri 于 2014-04-22 14:43 编辑
好吧,我来说说原始目的。
我为我的busybox盒子们在公网上找了两个Linux服务器来做云,盒子们可以在云上进行数据交换。
但是这两个Linux服务器其实不是很稳定,而且提供方出于各种考虑,其实对权限上加了N多限制。
比如ps命令不能用,df命令不能用,凡是涉及到系统方面的、其他用户信息方面的命令统统不能用。
在这种情况下,我就想在程序里做一个简单的redunancy。
算法如下:
unset host
if ping host1 < 200ms then
ssh to host1 and execute "date>file1; check the size of file1;remove file1"
if the size of file1 is greater than 0, then the disk on host1 is not full, then host1 could be selected. -> host=host1
fi
if host is not set then
if ping host2 < 200ms then
ssh to host2 and execute "date>file1; check the size of file1;remove file1"
if the size of file1 is greater than 0, then the disk on host1 is not full, then host2 could be selected. -> host=host2
fi
fi
现在两个host的情况是ping值都在10ms左右,但是host1的硬盘满了,也就是说在host1上执行date>file1命令会出错:
date: write error: No space left on device
文件file1会被生成但是文件长度为0。
但是现在的问题是,如果手工执行的话,程序可以正确选择host=host2,但是放在crontab里每5分钟执行一次,执行后host还是空值。
damcool 发表于 2014-04-22 09:46
说原始目的,这段代码有点莫名其妙. |
|