숀패밀리

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

· 2011-08-03 (수) 14:45:24 · 2490
많은 서버를 관리할때 일일이 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-04-26 조회 3,868
12-04-24 조회 3,249
12-04-23 조회 4,575
12-04-22 조회 3,264
12-04-19 조회 3,358
12-04-18 조회 4,426
12-04-18 조회 3,120
12-04-17 조회 3,395
12-04-17 조회 5,150
12-04-16 조회 3,577
12-04-13 조회 3,124
12-04-09 조회 3,181
12-04-04 조회 3,955
12-04-01 조회 3,232
12-03-31 조회 3,634
12-03-30 조회 3,243
12-03-30 조회 3,909
12-03-26 조회 3,521
12-03-26 조회 3,090
12-03-22 조회 3,245
12-03-21 조회 3,101
12-03-19 조회 3,514
12-03-17 조회 3,532
12-03-14 조회 3,266
12-03-10 조회 3,937
12-03-09 조회 3,535
12-03-09 조회 3,356
12-03-08 조회 3,827
12-03-08 조회 3,992
12-03-08 조회 4,085
12-03-03 조회 3,350
12-03-02 조회 4,669
12-02-28 조회 3,194
12-02-27 조회 3,023
12-02-25 조회 3,162
12-02-24 조회 3,860
12-02-23 조회 3,129
12-02-22 조회 3,653
12-02-22 조회 5,414
12-02-22 조회 3,986
12-02-22 조회 4,308
12-02-18 조회 3,811
12-02-17 조회 3,030
12-02-17 조회 3,437
12-02-14 조회 3,505
12-02-13 조회 3,395
12-02-10 조회 1만
12-02-08 조회 3,053
12-02-07 조회 3,387
12-02-06 조회 3,115
12-02-05 조회 3,580
12-01-31 조회 3,504
12-01-30 조회 9,695
12-01-29 조회 3,850
12-01-26 조회 3,446
12-01-25 조회 4,059
12-01-24 조회 3,452
12-01-10 조회 3,755
12-01-10 조회 4,522
12-01-09 조회 3,292
12-01-08 조회 7,154
12-01-08 조회 3,678
12-01-07 조회 5,208
12-01-04 조회 3,911
12-01-02 조회 3,133
12-01-02 조회 3,183
12-01-02 조회 3,487
12-01-01 조회 3,121
11-12-31 조회 3,433
11-12-31 조회 3,116
11-12-30 조회 3,283
11-12-30 조회 3,438
11-12-29 조회 3,652
11-12-28 조회 3,741
11-12-26 조회 3,319
11-12-23 조회 3,538
11-12-22 조회 3,081
11-12-15 조회 4,175
11-12-08 조회 3,975
11-12-05 조회 3,318
11-12-04 조회 5,730
11-12-03 조회 3,610
11-12-02 조회 3,383
11-12-01 조회 5,458
11-11-30 조회 2,934
11-11-30 조회 2,836
11-11-28 조회 3,184
11-11-26 조회 3,380
11-11-25 조회 3,375
11-11-24 조회 2,974
11-11-22 조회 3,071
11-11-22 조회 2,911
11-11-17 조회 2,843
11-11-11 조회 2,839
11-11-09 조회 2,891
11-11-08 조회 3,273
11-11-08 조회 2,566
11-11-04 조회 3,651
11-11-01 조회 2,953
11-10-26 조회 2,544