숀패밀리

많은 서버관리할때 동일작업 반복하기~ SSHinPHP

· 2011-08-03 (수) 14:45:24 · 2532
많은 서버를 관리할때 일일이 ssh접속해서 명령어치고 빠지고 하기 귀찮을때 쓰면 좋습니다
요거는 ssh2 는 지원안됍니당 ~
실행파일은 php로 작업의도에 맞게 응용하시면 됩니다 아래는 기본샘플입니당~
<?
require_once ('test_db.php'); //디비 커넥션
require_once ('ssh_in_php.php');

$db = new TestDB;

$cmd=null;
set_time_limit(0);

$qry = "select * from ip_table"; //루프돌리는 방법은 개인스탈에 따라~
$db->query($qry);

while($db->next_record())
{


try
{



$host = 아이피;
$port = 포트번호;
$user = 계정아이디;
$password = 계정패스워드;
$su = 루트패스워드;

$ssh = null;
$ssh = new SSH_in_PHP($host,$port);
$ssh->connect($user,$password);

$ssh->write("su -\n\n");
$cycle = true;
$result="";
while ($cycle) {
$data = $ssh->read();
echo $data;
if (ereg('\]$',$data)) {
// $cycle = false;
}
if (ereg('\]#',$data)) {
$cycle = false;
}

if (ereg('Password:',$data)) {
$cycle = true;
$ssh->write($su."\n");
}
if (ereg('암호:',$data)) {
$cycle = true;
$ssh->write($su."\n");
}

}


$ssh->write(" \n");
$cycle = true;
$result="";
while ($cycle) {
$data = $ssh->read();
echo $data;
if (ereg('\]$',$data)) {
// $cycle = false;
}
if (ereg('\]#',$data)) {
$cycle = false;
}

if (ereg('Password:',$data)) {
$cycle = true;
$ssh->write($su."\n");
}
if (ereg('암호:',$data)) {
$cycle = true;
$ssh->write($su."\n");
}
}

//각 서버에 test폴더 만들기
$comm=null;
$comm[]="mkdir -p /home/test \n";

for($c=0;$c<sizeof($comm);$c++)
{
$ssh->write($comm[$c]);
$cycle = true;
$result="";
while ($cycle) {
$data = $ssh->read();
echo $data;
if (ereg('\]$',$data)) {
$cycle = false;
}
if (ereg('\]#',$data)) {
$cycle = false;
}

if (ereg('yes',$data)) {
$cycle = true;
//sleep(1);
$ssh->write("Yes\n");
}

if (ereg('password:',$data)) {
$cycle = true;
$ssh->write("계정패스워드\n");
}
if (ereg('암호:',$data)) {
$cycle = true;
$ssh->write("계정패스워드\n");
}



}


$ssh->write(" \n");
$cycle = true;
$result="";
while ($cycle) {
$data = $ssh->read();
echo $data;
if (ereg('\]$',$data)) {
$cycle = false;
}
if (ereg('\]#',$data)) {
$cycle = false;
}

if (ereg('yes',$data)) {
$cycle = true;
//sleep(1);
$ssh->write("Yes\n");
}

if (ereg('password:',$data)) {
$cycle = true;
$ssh->write("계정패스워드\n");
}
if (ereg('암호:',$data)) {
$cycle = true;
$ssh->write("계정패스워드\n");
}



}
}


$ssh->disconnect();
continue;

}
catch (SSHException $e)
{
echo "에구 이서버는 잘안돼네여~";
echo "\n";
$fail_ip[]=$ip;
}


}

var_dump($fail_ip);

?><div class='small'>[이 게시물은 관리자님에 의해 2011-10-31 17:32:05 Linux에서 이동 됨]</div>

첨부파일

ssh_in_php.zip (7.4 KB) 11회 2011-08-03 14:45
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

8,187건
+
제목 글쓴이 날짜 조회
11-07-16 조회 2,949
11-07-16 조회 3,113
11-07-15 조회 2,620
11-07-13 조회 3,542
11-07-13 조회 2,778
11-07-12 조회 3,414
11-07-12 조회 2,991
11-07-12 조회 2,606
11-07-12 조회 4,785
11-07-12 조회 3,192
11-07-12 조회 2,585
11-07-12 조회 2,431
11-07-12 조회 3,355
11-07-11 조회 2,564
11-07-11 조회 2,406
11-07-11 조회 2,325
11-07-11 조회 3,703
11-07-11 조회 2,286
11-07-11 조회 2,533
11-07-11 조회 3,296
11-07-11 조회 2,459
11-07-09 조회 2,529
11-07-08 조회 3,059
11-07-08 조회 2,689
11-07-08 조회 2,797
11-07-08 조회 2,597
11-07-07 조회 3,956
11-07-07 조회 2,624
11-07-07 조회 2,242
11-07-06 조회 2,463
11-07-06 조회 2,292
11-07-05 조회 2,301
11-07-05 조회 2,192
11-07-05 조회 2,446
11-07-05 조회 2,756
11-07-04 조회 2,993
11-07-03 조회 2,666
11-07-02 조회 2,698
11-07-02 조회 2,496
11-07-01 조회 2,624
11-07-01 조회 2,909
11-07-01 조회 2,723
11-07-01 조회 3,039
11-06-29 조회 2,772
11-06-28 조회 2,587
11-06-28 조회 2,631
11-06-28 조회 2,610
11-06-28 조회 3,171
11-06-28 조회 3,218
11-06-28 조회 2,900
11-06-27 조회 3,069
11-06-27 조회 3,212
11-06-27 조회 2,165
11-06-27 조회 2,702
11-06-27 조회 2,129
11-06-26 조회 2,466
11-06-26 조회 2,894
11-06-26 조회 2,406
11-06-26 조회 2,442
11-06-25 조회 2,648
11-06-24 조회 2,793
11-06-24 조회 2,695
11-06-24 조회 2,433
11-06-24 조회 2,748
11-06-23 조회 2,887
11-06-23 조회 2,833
11-06-23 조회 2,419
11-06-23 조회 3,635
11-06-23 조회 1,952
11-06-22 조회 2,636
11-06-22 조회 2,444
11-06-22 조회 2,314
11-06-22 조회 2,893
11-06-22 조회 3,274
11-06-21 조회 2,715
11-06-21 조회 2,332
11-06-21 조회 2,363
11-06-20 조회 2,607
11-06-17 조회 2,937
11-06-16 조회 3,063
11-06-16 조회 2,103
11-06-16 조회 2,594
11-06-15 조회 2,561
11-06-15 조회 2,551
11-06-15 조회 3,306
11-06-15 조회 3,138
11-06-15 조회 3,005
11-06-14 조회 2,719
11-06-14 조회 2,708
11-06-14 조회 3,328
11-06-13 조회 2,525
11-06-13 조회 2,148
11-06-13 조회 2,454
11-06-13 조회 2,350
11-06-13 조회 2,869
11-06-13 조회 3,117
11-06-13 조회 2,817
11-06-12 조회 2,488
11-06-10 조회 2,576
11-06-10 조회 2,603