- 论坛徽章:
- 0
|
本帖最后由 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 !
|
|