- 论坛徽章:
- 0
|
本帖最后由 yqhzh 于 2014-09-25 10:21 编辑
目的:想把watch每次的输出都重定向到同一个到文件,用于最后的统计分析
比如说 watch -n 1 ifconfig eth0 这个命令,我试了 > , >> , tee ,但是都不能把每次的结果保存在文件中。
watch -n 1 ifconfig eth0 > /tmp/0123456.txt; 文件里面什么都没有
watch -n 1 ifconfig eth0 >> /tmp/0123456.txt; 文件里面什么都没有
watch -n 1 ifconfig eth0 | tee /tmp/0123456.txt; 输出只能保存最后一次结果,如下所示:
Every 1.0s: ifconfig eth0 Tue Sep 23 06:34:41 2014
Every 1.0s: ifconfig eth0 Tue Sep 23 06:34:41 2014
Every 1.0s: ifconfig eth0 Tue Sep 23 06:34:41 2014
eth0 Link encap:Ethernet HWaddr 00:50:56:B5:11:92
inet addr:10.91.117.25 Bcast:10.91.127.255 Mask:255.255.240.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:52982927 errors:0 dropped:0 overruns:0 frame:0
TX packets:40737873 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:7536732506 (7.0 GiB) TX bytes:6816789784 (6.3 GiB)
------------------------------------------------------------------------------------------------
下面有回帖提供了3种建议,但是这些建议输出的结果都不符合期望。
1, script -c "watch -n 1 ifconfig eth0" -a -f file
2, ( watch -n 1 ifconfig eth0 ) >>/tmp/0123456.txt
3, { watch -n 1 ifconfig eth0; } >>/tmp/0123456.txt
补充一下,这些建议的输出:
1,首先还是只记录了一次结果。
2,其次实际输出是带格式的,很难使用如下所示,这个怎么才能转成纯文本?
[root@clab1209node14 tmp]# vi file01
Script started on Tue 23 Sep 2014 10:09:42 AM EEST
^[[?1049h^[[1;43r^[(B^[[m^[[4l^[[?7h^[[H^[[2JEvery 1.0s: ifconfig eth0^[[1;202HTue Sep 23 10:09:42 2014^[[3;1Heth0 Link encap:Ethernet HWaddr 00:50:56:B5:11:92^[[4;11Hinet addr:10.91.117.25 Bcast:10.91.127.255 Mask:255.255.240.0^[[5;11HUP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1^[[6;11HRX packets:54319816 errors:0 dropped:0 overruns:0 frame:0^[[7;11HTX packets:41646968 errors:0 dropped:0 overruns:0 carrier:0^[[8;11Hcollisions:0 txqueuelen:1000^[[9;11HRX bytes:7710097150 (7.1 GiB) TX bytes:6977524236 (6.4 GiB)^[[43;225H^[[1;220H3^[[6;27H917^[[7;26H7039^[[9;24H108185^[[9;56H38831^[[43;225H^[[1;220H4^[[6;25H20029^[[7;27H117^[[9;25H22723^[[9;56H50887^[[43;225H^[[1;220H5^[[6;27H100^[[7d^H^H49^[[9;25H32426^[[9;57H7279^[[43;225H^[[1;220H6^[[6;28H47^[[7d^H^H70^[[9;26H5539^[[9;57H9722^[[43;225H^[[1;220H7^[[6;27H238^[[7;27H231^[[9;25H43784^[[9;56H67584^[[43;225H^[[1;220H8^[[6;27H305^[[7d^H^H56^[[9;26H9316^[[9;56H71809^[[43;225H^[[43;1H^[[?1049l^M^[[?1l^[>
Script done on Tue 23 Sep 2014 10:09:48 AM EEST
|
|