免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2022 | 回复: 0
打印 上一主题 下一主题

用perl openssh::net 写了个类似psshd的工具 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2014-12-31 15:54 |只看该作者 |倒序浏览
本帖最后由 aku1 于 2014-12-31 15:58 编辑

用perl openssh::net 写了个类似psshd的多线程工具,完善后把代码贴给大家参考,
目前我没有把ssh交互放进去,建立互信,生成ssh passprhase ,然后直接交给ssh-agent去处理。
目前基本功能:
并发跑ssh 命令
平发跑脚本
传文件到远端/远端到本地
计划加日志和审计功能
回写结果到当前目录下的result.txt
/msfte.pl
----------------------------------------------------------------------------------------------        
msfte.pl v0.1
----------------------------------------------------------------------------------------------
1.msfte.pl -u <username> -p </home/username/.ssh/id_rsa ##initial user/ssh key
2.msfte.pl -t <60>          specify 60s timeout of ssh connection  ##SSH repeat try
3.msfte.pl -l <server_list> ";" between multi commands:<uptime;ls>  ##Batch commands
4.msfte.pl -l <server_list> -b  </tmp/test01.sh> ##execute the script ##Run the script
5.msfte.pl -l <server_list> -s  <Put the file/dir to remote server:/tmp> ##Put
6.msfte.pl -l <server_list> -g  <Get the file/dir from remote server to the currect dir>
----------------------------------------------------------------------------------------------
You must execute Step.1 to set initial id for OPENSSH
----------------------------------------------------------------------------------------------      
$ cat server_list
test01
test02
$ ./msfte.pl -l server_list
Please input your batch command
df -h
$ ./msfte.pl -l server_list -b get_server_info.pl
$ ./msfte.pl -l server_list -g /tmp/*.mef3
$ ls -l *.mef3
-rw-r--r--. 1 jimmy jimmy 2285 Dec 31 15:44 IBM_30DEC2014_test01.mef3
-rw-r--r--. 1 jimmy jimmy 2272 Dec 31 15:44 IBM_30DEC2014_test02.mef3
[jimmy@zhangchl perl]$ cat result.txt
---test01---
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_test01-lv_root
                      6.5G  5.5G  655M  90% /
tmpfs                 250M     0  250M   0% /dev/shm
/dev/vda1             485M   29M  432M   7% /boot
---test02---
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_test01-lv_root
                      6.5G  4.1G  2.1G  68% /
tmpfs                 250M     0  250M   0% /dev/shm
/dev/vda1             485M   29M  432M   7% /boot
---test02---
Your OS probably is a VM
--------------The Server Summary----------------------
The OS Version is Red Hat Enterprise Linux Server release 6.0 (Santiago)
The Manufacturer is Red Hat
The Product Number is KVM
The Product Model is RHEL 6.3.0 PC
The serial Number is Not Specified
The CPU mode is        QEMU Virtual CPU version (cpu64-rhel6)
Use of uninitialized value $b in concatenation (.) or string at /tmp/get_server_info.pl line 99.
The number of physical CPU is       
Use of uninitialized value $c in concatenation (.) or string at /tmp/get_server_info.pl line 100.
The number of CPU cores is       
The number of logical CPUs is        1
The Memory is        1G
The DISK vda is 9G
------------------------------------------------------
---test01---
Your OS probably is a VM
--------------The Server Summary----------------------
The OS Version is Red Hat Enterprise Linux Server release 6.0 (Santiago)
The Manufacturer is Red Hat
The Product Number is KVM
The Product Model is RHEL 6.3.0 PC
The serial Number is Not Specified
The CPU mode is        QEMU Virtual CPU version (cpu64-rhel6)
Use of uninitialized value $b in concatenation (.) or string at /tmp/get_server_info.pl line 99.
The number of physical CPU is       
Use of uninitialized value $c in concatenation (.) or string at /tmp/get_server_info.pl line 100.
The number of CPU cores is       
The number of logical CPUs is        1
The Memory is        1G
The DISK vda is 9G
------------------------------------------------------
The file/dir from test02 had been obtained to the current dir successfully !
The file/dir from test01 had been obtained to the current dir successfully !
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP