- 论坛徽章:
- 0
|
用net: penssh先 写了个简单批量脚本,但是跑完后当前tty格式变了(有时候正常),执行结果到result.txt是正确的,有人遇到过吗。
sub Batch_cmd {
my $host=shift;
chomp($host);
my $ssh = Net::OpenSSH->new($host,%param);
my @out=$ssh->capture2({tty=>1},$cmd); 可能跟这个有关,应为我在sudo里设置了Defaults requiretty,所以一般用户都是执行sudo command.
print RES "---$host---\n";
print RES @out;
$ ./run_batch.pl -l server_list -o result.txt
-----------------------------------------------------------------
run_batch.pl v1.0
-----------------------------------------------------------------
1.run_batch.pl -u <username> -p </home/username/.ssh/id_rsa
2.run_batch.pl -l <server_list> -o <result.txt>
-----------------------------------------------------------------
You must execute Step.1 to set initial id for OPENSSH
----------------------------------------------------------------
Please input your batch command
sudo df -h
[jimmy@zhangchl perl]$
cat catchsegv
cat catchsegv
cat catchsegv
这是结果文件
$ cat result.txt
---test01---
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_test01-lv_root
6.5G 5.5G 658M 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 67% /
tmpfs 250M 0 250M 0% /dev/shm
/dev/vda1 485M 29M 432M 7% /boot
|
|