많은 서버관리할때 동일작업 반복하기~ SSHinPHP
많은 서버를 관리할때 일일이 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>
게시글 목록
| 번호 | 제목 |
|---|---|
| 1959 | |
| 14479 |
MySQL
가입하기
1
|
| 14475 |
JavaScript
도와주세요
3
|
| 14474 | |
| 14469 | |
| 14466 |
Flash
이거 원리가 뭔가요 ;;
2
|
| 29747 |
HTML
회원가입폼 수정
2
|
| 14464 |
jQuery
FLEX 앞으로 어떨가요?
1
|
| 14463 | |
| 1950 | |
| 1943 | |
| 1938 | |
| 14460 |
PHP
카운트 조절하기
2
|
| 29743 |
HTML
[유트브]동영상 사이트 만들기
3
|
| 14453 |
JavaScript
sshd 접속 에러 로그
6
|
| 29738 |
HTML
도시 이름 한국어 리스트
4
|
| 1936 | |
| 24146 | |
| 25894 | |
| 1923 | |
| 1919 | |
| 1916 | |
| 1913 | |
| 24135 | |
| 24131 | |
| 25885 | |
| 14449 | |
| 1895 | |
| 1891 | |
| 1886 | |
| 14443 | |
| 1875 | |
| 25884 | |
| 14442 | |
| 1872 | |
| 29735 | |
| 14441 |
기타
서버게시판이 생겼군요.
|
| 1861 | |
| 14438 |
JavaScript
ssh로 사이트 악성코드 한번에 지울수 있나요?
2
|
| 14434 |
Flash
플래시에서 자동이로 페이지 이동하려면요?
3
|
| 1836 | |
| 29734 |
HTML
계정홈디렉토리에 파일 복사해 넣기
|
| 29727 | |
| 14430 |
기타
개인홈페이지..
3
|
| 14426 |
정규표현식
왜 서버는...
3
|
| 14425 | |
| 1828 | |
| 1813 | |
| 29725 | |
| 29719 |
HTML
html5 가이드 입니다.
5
|
| 1808 | |
| 1804 | |
| 14423 | |
| 24120 | |
| 25866 | |
| 14420 |
PHP
[펌] PHP 쉽게 배우기
2
|
| 25863 | |
| 1784 | |
| 1777 | |
| 25859 | |
| 14419 | |
| 1775 | |
| 29717 |
HTML
웹 접근성 검사 K-WAH 3.0
1
|
| 1768 | |
| 1759 | |
| 1744 | |
| 14416 | |
| 14414 |
JavaScript
메뉴 임다.
1
|
| 14413 |
jQuery
Jquery 텍스트 하이라이트 플러그인
|
| 1737 | |
| 14412 | |
| 1718 | |
| 1714 | |
| 1704 | |
| 1700 | |
| 29714 | |
| 1699 | |
| 14411 |
MySQL
mysqldumpslow
|
| 1696 | |
| 1686 | |
| 1677 | |
| 1672 | |
| 1671 | |
| 25853 | |
| 1660 | |
| 1654 | |
| 1650 | |
| 25851 | |
| 25850 | |
| 1647 | |
| 1588 | |
| 1586 | |
| 1580 | |
| 1567 | |
| 14408 |
MySQL
잠깐 짬나시는 쿼리 고수님께...
2
|
| 1553 | |
| 24109 | |
| 1551 | |
| 25849 | |
| 25848 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기