shell多进程scp传文件
  
  
   时间:2016-06-05 00:16来源:linux.it.net.cn 作者:IT
  
  
   
    
     
      昨天给大家了一个shell多进程并发,今天我们来看怎么同时批量在定义数量的服务器上执行相关命令,比起普通for/while循环只能顺序一条一条执行的效率高非常多,在管理大批服务器时非常的实用.以下脚本功能是通过scp(也可选rsync)向上千台服务器传更新包,脚本运行后同时在后台有50个scp进程向服务器传包: 
	
	
		
		
			
				
					
						| 
							02 | 
						
							ip=`cat iplist.txt|grep -v "#"|awk '{print $1}'` | 
					 
				
			 
		 
		
		
			
				
					
						| 
							04 | 
						
							answer="yes"    #定义yes/no应答变量 | 
					 
				
			 
		 
		
			
				
					
						| 
							05 | 
						
							passwd="123456" #服务器密码 | 
					 
				
			 
		 
		
		
			
				
					
						| 
							07 | 
						
							tmp_fifo_file="/tmp/$$.fifo" | 
					 
				
			 
		 
		
		
			
				
					
						| 
							09 | 
						
							exec 4<>$tmp_fifo_file | 
					 
				
			 
		 
		
		
			
				
					
						| 
							11 | 
						
							for ((i=0;i<$thead_num;i++)) | 
					 
				
			 
		 
		
		
		
		
		
		
		
		
		
		
			
				
					
						| 
							21 | 
						
							                        spawn scp -P 1000 $1 $i:$dir | 
					 
				
			 
		 
		
		
		
		
		
			
				
					
						| 
							26 | 
						
							                        } "Password:" {send "$passwd\r"} "*host" {exit 1} | 
					 
				
			 
		 
		
		
		
		
		
		
		
		
		
		
	 
 
 
 
      (责任编辑:IT) | 
    
   
 
 
  
  
  
   
   ------分隔线----------------------------