많은 서버를 관리할때 일일이 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>
요거는 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>
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 8130 | 9년 전 | 585 | ||
| 8129 |
|
9년 전 | 703 | |
| 8128 | 9년 전 | 555 | ||
| 8127 |
|
9년 전 | 600 | |
| 8126 | 9년 전 | 536 | ||
| 8125 | 9년 전 | 786 | ||
| 8124 |
|
9년 전 | 547 | |
| 8123 | 9년 전 | 534 | ||
| 8122 | 9년 전 | 460 | ||
| 8121 | 9년 전 | 573 | ||
| 8120 | 9년 전 | 487 | ||
| 8119 | 9년 전 | 577 | ||
| 8118 |
|
9년 전 | 654 | |
| 8117 |
|
9년 전 | 419 | |
| 8116 |
PASKRAN
|
9년 전 | 481 | |
| 8115 | 9년 전 | 481 | ||
| 8114 |
kiplayer
|
9년 전 | 620 | |
| 8113 | 9년 전 | 476 | ||
| 8112 |
|
9년 전 | 586 | |
| 8111 | 9년 전 | 420 | ||
| 8110 | 9년 전 | 465 | ||
| 8109 | 9년 전 | 392 | ||
| 8108 |
|
9년 전 | 569 | |
| 8107 |
|
9년 전 | 458 | |
| 8106 |
|
9년 전 | 459 | |
| 8105 | 9년 전 | 492 | ||
| 8104 |
|
9년 전 | 454 | |
| 8103 |
|
9년 전 | 457 | |
| 8102 |
|
9년 전 | 429 | |
| 8101 |
snshero
|
9년 전 | 819 | |
| 8100 | 9년 전 | 860 | ||
| 8099 | 9년 전 | 839 | ||
| 8098 | 9년 전 | 742 | ||
| 8097 | 9년 전 | 545 | ||
| 8096 | 9년 전 | 749 | ||
| 8095 | 9년 전 | 887 | ||
| 8094 | 9년 전 | 561 | ||
| 8093 | 9년 전 | 840 | ||
| 8092 | 9년 전 | 781 | ||
| 8091 | 9년 전 | 1167 | ||
| 8090 | 9년 전 | 794 | ||
| 8089 | 9년 전 | 1004 | ||
| 8088 | 9년 전 | 667 | ||
| 8087 | 9년 전 | 792 | ||
| 8086 | 9년 전 | 541 | ||
| 8085 | 9년 전 | 507 | ||
| 8084 | 9년 전 | 630 | ||
| 8083 | 9년 전 | 599 | ||
| 8082 | 9년 전 | 791 | ||
| 8081 | 9년 전 | 500 | ||
| 8080 | 9년 전 | 598 | ||
| 8079 | 9년 전 | 554 | ||
| 8078 | 9년 전 | 473 | ||
| 8077 | 9년 전 | 561 | ||
| 8076 | 9년 전 | 431 | ||
| 8075 | 9년 전 | 464 | ||
| 8074 | 9년 전 | 435 | ||
| 8073 | 9년 전 | 487 | ||
| 8072 | 9년 전 | 475 | ||
| 8071 |
o1o111
|
9년 전 | 926 | |
| 8070 | 9년 전 | 435 | ||
| 8069 | 9년 전 | 374 | ||
| 8068 | 9년 전 | 624 | ||
| 8067 | 9년 전 | 420 | ||
| 8066 | 9년 전 | 448 | ||
| 8065 | 9년 전 | 409 | ||
| 8064 | 9년 전 | 403 | ||
| 8063 | 9년 전 | 371 | ||
| 8062 | 9년 전 | 340 | ||
| 8061 | 9년 전 | 378 | ||
| 8060 | 9년 전 | 419 | ||
| 8059 | 9년 전 | 357 | ||
| 8058 | 9년 전 | 294 | ||
| 8057 | 9년 전 | 419 | ||
| 8056 | 9년 전 | 340 | ||
| 8055 | 9년 전 | 389 | ||
| 8054 | 9년 전 | 392 | ||
| 8053 | 9년 전 | 444 | ||
| 8052 | 9년 전 | 314 | ||
| 8051 | 9년 전 | 361 | ||
| 8050 | 9년 전 | 420 | ||
| 8049 | 9년 전 | 351 | ||
| 8048 | 9년 전 | 454 | ||
| 8047 | 9년 전 | 394 | ||
| 8046 | 9년 전 | 337 | ||
| 8045 | 9년 전 | 286 | ||
| 8044 | 9년 전 | 379 | ||
| 8043 | 9년 전 | 333 | ||
| 8042 | 9년 전 | 325 | ||
| 8041 | 9년 전 | 385 | ||
| 8040 | 9년 전 | 301 | ||
| 8039 | 9년 전 | 346 | ||
| 8038 | 9년 전 | 286 | ||
| 8037 | 9년 전 | 431 | ||
| 8036 | 9년 전 | 521 | ||
| 8035 | 9년 전 | 455 | ||
| 8034 | 9년 전 | 412 | ||
| 8033 | 9년 전 | 376 | ||
| 8032 | 9년 전 | 481 | ||
| 8031 | 9년 전 | 374 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기