많은 서버를 관리할때 일일이 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>
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 7930 | 9년 전 | 372 | ||
| 7929 | 9년 전 | 265 | ||
| 7928 | 9년 전 | 376 | ||
| 7927 | 9년 전 | 299 | ||
| 7926 | 9년 전 | 645 | ||
| 7925 | 9년 전 | 314 | ||
| 7924 | 9년 전 | 287 | ||
| 7923 | 9년 전 | 323 | ||
| 7922 | 9년 전 | 344 | ||
| 7921 | 9년 전 | 375 | ||
| 7920 | 9년 전 | 297 | ||
| 7919 | 9년 전 | 312 | ||
| 7918 | 9년 전 | 475 | ||
| 7917 | 9년 전 | 318 | ||
| 7916 | 9년 전 | 384 | ||
| 7915 | 9년 전 | 369 | ||
| 7914 | 9년 전 | 382 | ||
| 7913 | 9년 전 | 507 | ||
| 7912 | 9년 전 | 381 | ||
| 7911 | 9년 전 | 333 | ||
| 7910 | 9년 전 | 364 | ||
| 7909 | 9년 전 | 471 | ||
| 7908 | 9년 전 | 370 | ||
| 7907 | 9년 전 | 323 | ||
| 7906 | 9년 전 | 336 | ||
| 7905 | 9년 전 | 329 | ||
| 7904 | 9년 전 | 300 | ||
| 7903 | 9년 전 | 298 | ||
| 7902 | 9년 전 | 516 | ||
| 7901 |
|
9년 전 | 716 | |
| 7900 | 9년 전 | 540 | ||
| 7899 | 9년 전 | 348 | ||
| 7898 | 9년 전 | 339 | ||
| 7897 | 9년 전 | 297 | ||
| 7896 | 9년 전 | 319 | ||
| 7895 | 9년 전 | 425 | ||
| 7894 | 9년 전 | 348 | ||
| 7893 | 9년 전 | 280 | ||
| 7892 | 9년 전 | 329 | ||
| 7891 | 9년 전 | 713 | ||
| 7890 | 9년 전 | 1176 | ||
| 7889 | 9년 전 | 733 | ||
| 7888 |
limsy1987
|
9년 전 | 531 | |
| 7887 | 9년 전 | 502 | ||
| 7886 | 9년 전 | 390 | ||
| 7885 | 9년 전 | 362 | ||
| 7884 | 9년 전 | 372 | ||
| 7883 | 9년 전 | 358 | ||
| 7882 | 9년 전 | 366 | ||
| 7881 | 9년 전 | 398 | ||
| 7880 | 9년 전 | 521 | ||
| 7879 | 9년 전 | 417 | ||
| 7878 | 9년 전 | 1160 | ||
| 7877 | 9년 전 | 707 | ||
| 7876 | 9년 전 | 438 | ||
| 7875 | 9년 전 | 512 | ||
| 7874 |
|
9년 전 | 783 | |
| 7873 | 9년 전 | 483 | ||
| 7872 | 9년 전 | 619 | ||
| 7871 | 9년 전 | 448 | ||
| 7870 | 9년 전 | 572 | ||
| 7869 | 9년 전 | 393 | ||
| 7868 | 9년 전 | 384 | ||
| 7867 | 9년 전 | 381 | ||
| 7866 | 9년 전 | 444 | ||
| 7865 | 9년 전 | 403 | ||
| 7864 | 9년 전 | 466 | ||
| 7863 | 9년 전 | 456 | ||
| 7862 | 9년 전 | 434 | ||
| 7861 | 9년 전 | 594 | ||
| 7860 | 9년 전 | 595 | ||
| 7859 | 9년 전 | 365 | ||
| 7858 | 9년 전 | 673 | ||
| 7857 | 9년 전 | 1022 | ||
| 7856 | 9년 전 | 484 | ||
| 7855 | 9년 전 | 701 | ||
| 7854 | 9년 전 | 700 | ||
| 7853 | 9년 전 | 541 | ||
| 7852 | 9년 전 | 474 | ||
| 7851 | 9년 전 | 448 | ||
| 7850 | 9년 전 | 543 | ||
| 7849 | 9년 전 | 317 | ||
| 7848 | 9년 전 | 369 | ||
| 7847 | 9년 전 | 592 | ||
| 7846 | 9년 전 | 407 | ||
| 7845 | 9년 전 | 370 | ||
| 7844 | 9년 전 | 368 | ||
| 7843 | 9년 전 | 374 | ||
| 7842 | 9년 전 | 370 | ||
| 7841 | 9년 전 | 355 | ||
| 7840 | 9년 전 | 364 | ||
| 7839 | 9년 전 | 396 | ||
| 7838 | 9년 전 | 479 | ||
| 7837 | 9년 전 | 325 | ||
| 7836 | 9년 전 | 361 | ||
| 7835 | 9년 전 | 442 | ||
| 7834 |
|
9년 전 | 1170 | |
| 7833 | 9년 전 | 377 | ||
| 7832 | 9년 전 | 374 | ||
| 7831 | 9년 전 | 509 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기