많은 서버를 관리할때 일일이 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>
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 8030 | 9년 전 | 414 | ||
| 8029 | 9년 전 | 335 | ||
| 8028 | 9년 전 | 294 | ||
| 8027 | 9년 전 | 306 | ||
| 8026 | 9년 전 | 379 | ||
| 8025 | 9년 전 | 410 | ||
| 8024 | 9년 전 | 397 | ||
| 8023 | 9년 전 | 424 | ||
| 8022 | 9년 전 | 338 | ||
| 8021 | 9년 전 | 360 | ||
| 8020 | 9년 전 | 359 | ||
| 8019 | 9년 전 | 374 | ||
| 8018 | 9년 전 | 477 | ||
| 8017 | 9년 전 | 559 | ||
| 8016 | 9년 전 | 382 | ||
| 8015 | 9년 전 | 415 | ||
| 8014 | 9년 전 | 346 | ||
| 8013 | 9년 전 | 267 | ||
| 8012 | 9년 전 | 270 | ||
| 8011 | 9년 전 | 476 | ||
| 8010 | 9년 전 | 332 | ||
| 8009 | 9년 전 | 348 | ||
| 8008 | 9년 전 | 316 | ||
| 8007 | 9년 전 | 465 | ||
| 8006 | 9년 전 | 501 | ||
| 8005 |
|
9년 전 | 994 | |
| 8004 | 9년 전 | 384 | ||
| 8003 | 9년 전 | 454 | ||
| 8002 | 9년 전 | 347 | ||
| 8001 |
|
9년 전 | 689 | |
| 8000 | 9년 전 | 457 | ||
| 7999 | 9년 전 | 407 | ||
| 7998 | 9년 전 | 466 | ||
| 7997 | 9년 전 | 335 | ||
| 7996 | 9년 전 | 564 | ||
| 7995 | 9년 전 | 509 | ||
| 7994 | 9년 전 | 401 | ||
| 7993 | 9년 전 | 470 | ||
| 7992 | 9년 전 | 542 | ||
| 7991 | 9년 전 | 288 | ||
| 7990 | 9년 전 | 323 | ||
| 7989 | 9년 전 | 329 | ||
| 7988 | 9년 전 | 757 | ||
| 7987 | 9년 전 | 460 | ||
| 7986 | 9년 전 | 463 | ||
| 7985 | 9년 전 | 541 | ||
| 7984 | 9년 전 | 459 | ||
| 7983 | 9년 전 | 697 | ||
| 7982 | 9년 전 | 557 | ||
| 7981 | 9년 전 | 514 | ||
| 7980 | 9년 전 | 535 | ||
| 7979 | 9년 전 | 526 | ||
| 7978 | 9년 전 | 490 | ||
| 7977 | 9년 전 | 431 | ||
| 7976 | 9년 전 | 891 | ||
| 7975 | 9년 전 | 404 | ||
| 7974 | 9년 전 | 448 | ||
| 7973 | 9년 전 | 631 | ||
| 7972 | 9년 전 | 422 | ||
| 7971 | 9년 전 | 497 | ||
| 7970 | 9년 전 | 339 | ||
| 7969 | 9년 전 | 577 | ||
| 7968 | 9년 전 | 426 | ||
| 7967 | 9년 전 | 410 | ||
| 7966 | 9년 전 | 414 | ||
| 7965 |
|
9년 전 | 1045 | |
| 7964 | 9년 전 | 434 | ||
| 7963 | 9년 전 | 443 | ||
| 7962 | 9년 전 | 442 | ||
| 7961 |
전갈자리남자
|
9년 전 | 532 | |
| 7960 | 9년 전 | 1000 | ||
| 7959 | 9년 전 | 585 | ||
| 7958 | 9년 전 | 435 | ||
| 7957 | 9년 전 | 390 | ||
| 7956 | 9년 전 | 389 | ||
| 7955 | 9년 전 | 493 | ||
| 7954 | 9년 전 | 427 | ||
| 7953 | 9년 전 | 471 | ||
| 7952 | 9년 전 | 393 | ||
| 7951 | 9년 전 | 528 | ||
| 7950 | 9년 전 | 422 | ||
| 7949 | 9년 전 | 417 | ||
| 7948 | 9년 전 | 355 | ||
| 7947 | 9년 전 | 970 | ||
| 7946 | 9년 전 | 488 | ||
| 7945 | 9년 전 | 430 | ||
| 7944 | 9년 전 | 490 | ||
| 7943 | 9년 전 | 420 | ||
| 7942 | 9년 전 | 435 | ||
| 7941 | 9년 전 | 427 | ||
| 7940 | 9년 전 | 927 | ||
| 7939 | 9년 전 | 418 | ||
| 7938 | 9년 전 | 433 | ||
| 7937 | 9년 전 | 324 | ||
| 7936 | 9년 전 | 907 | ||
| 7935 | 9년 전 | 506 | ||
| 7934 | 9년 전 | 485 | ||
| 7933 | 9년 전 | 612 | ||
| 7932 | 9년 전 | 551 | ||
| 7931 | 9년 전 | 611 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기