숀패밀리

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

· 2011-08-03 (수) 14:45:24 · 2416
많은 서버를 관리할때 일일이 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,188건
+
제목 글쓴이 날짜 조회
12-03-19 조회 3,404
12-03-16 조회 4,021
12-03-14 조회 3,889
12-03-13 조회 3,514
12-03-13 조회 4,369
12-03-12 조회 5,428
12-03-12 조회 1만
12-03-08 조회 5,990
12-03-06 조회 1.1만
12-03-06 조회 3,692
12-03-06 조회 6,228
12-03-02 조회 4,998
12-02-29 조회 3,563
12-02-27 조회 3,995
12-02-22 조회 3,627
12-02-20 조회 3,585
12-02-20 조회 6,702
12-02-01 조회 3,220
12-01-30 조회 8,744
12-01-29 조회 3,237
12-01-24 조회 3,415
12-01-21 조회 3,195
12-01-10 조회 3,666
11-12-26 조회 3,559
11-12-23 조회 4,984
11-12-23 조회 4,599
11-12-23 조회 4,166
11-12-23 조회 7,967
11-12-22 조회 3,691
11-12-17 조회 3,625
11-12-12 조회 3,041
11-12-08 조회 7,587
11-12-08 조회 3,454
11-12-07 조회 3,774
11-12-06 조회 5,455
11-12-02 조회 3,409
11-12-01 조회 3,109
11-11-30 조회 6,901
11-11-26 조회 3,827
11-11-24 조회 4,627
11-11-22 조회 2,990
11-11-22 조회 6,620
11-11-18 조회 4,983
11-11-16 조회 3,419
11-11-14 조회 3,439
11-11-12 조회 3,940
11-11-08 조회 3,258
11-11-06 조회 1만
11-11-06 조회 3,832
11-11-03 조회 5,519
11-11-02 조회 5,788
11-11-01 조회 9,309
11-10-19 조회 2,795
11-10-17 조회 2,596
11-10-10 조회 2,542
11-10-07 조회 3,331
11-10-06 조회 3,925
11-10-06 조회 2,478
11-10-02 조회 3,227
11-09-08 조회 4,233
11-09-08 조회 2,597
11-09-07 조회 2,606
11-09-02 조회 2,688
11-09-01 조회 3,619
11-08-28 조회 3,512
11-08-23 조회 3,359
11-08-22 조회 2,774
11-08-22 조회 2,370
11-08-13 조회 2,418
11-08-05 조회 2,872
11-08-03 조회 4,084
11-07-03 조회 2,518
11-06-15 조회 3,203
11-06-15 조회 3,039
11-05-15 조회 2,839
11-05-11 조회 5,572
11-04-12 조회 2,969
11-01-27 조회 3,810
11-01-26 조회 2,606
11-01-26 조회 4,456
11-01-18 조회 2,661
10-11-23 조회 2,777
10-10-24 조회 4,721
10-09-15 조회 4,408
10-09-07 조회 3,377
10-08-27 조회 4,069
10-08-20 조회 6,961
10-07-30 조회 5,635
10-06-30 조회 2,859
10-06-11 조회 4,617
10-06-11 조회 3,315
10-05-15 조회 4,147
10-05-10 조회 2,837
10-03-19 조회 5,403
10-03-05 조회 5,167
10-02-17 조회 5,569
09-11-21 조회 6,915
09-11-09 조회 3,988
09-11-04 조회 6,708
09-10-26 조회 3,845