posts - 88, comments - 3, trackbacks - 0, articles - 0
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

几个ssh管道用法

Posted on 2012-05-09 17:13 Milo的海域 阅读(3168) 评论(0)  编辑  收藏 所属分类: MySQLLinux
原来ssh可以这样用

1. remote file copy
[root@xen74v01 ~]# cat test.pl
#!/usr/bin/perl
print 
"eth0.74"=~/(\w+)/;
print "\n";
[root@xen74v01 ~]# cat test.pl | ssh 10.1.74.76 'cat - > /tmp/test.pl'

拷贝文件时,如果文件很大,又不想影响网络IO可以用pv工具进行流量控制
pv -L10m test.pl | ssh 10.1.74.76 'cat - > /tmp/test.pl'
这里pv的行为跟cat比较类似,但是支持IO流量控制,这里设置10M/s.

2. local script remote execute
[root@xen74v01 ~]# cat test.pl
#!/usr/bin/perl
print 
"eth0.74"=~/(\w+)/;
print "\n";
[root@xen74v01 ~]# perl test.pl
eth0
[root@xen74v01 ~]# cat test.pl | ssh 10.1.74.76 'perl'
eth0
[root@xen74v01 ~]# ssh 10.1.74.76 'perl' < test.pl
eth0

这样就不用把脚本拷贝到远端去执行了

参考:
http://linux.icydog.net/ssh/piping.php
http://www.ivarch.com/programs/quickref/pv.shtml
http://www.mysqlperformanceblog.com/2009/05/20/hint-throttling-xtrabackup/

只有注册用户登录后才能发表评论。


网站导航: