Chinaunix首页 | 论坛 | 博客
  • 博客访问: 174427
  • 博文数量: 40
  • 博客积分: 2697
  • 博客等级: 少校
  • 技术积分: 750
  • 用 户 组: 普通用户
  • 注册时间: 2010-09-27 16:55
文章分类

全部博文(40)

文章存档

2012年(1)

2011年(13)

2010年(26)

分类: WINDOWS

2010-12-29 21:15:15

 近几天,公司正在开发集群管理系统,系统要运行在linux下和windows下,我这几天的任务就是开发集群系统里面一个组件,用于安装erlang虚拟机,和检测虚拟机状态。在linux用的是shell,由于以前也写过这方面的,所以功能比较容易实现。但在windows下,刚开始还是感觉有点难,不过最后还是完成任务了,这才知道原来bat和shell就像两兄弟一样,是如此的相识,把写的代码贴上来,仅供有需要的朋友参考,不懂可以问我哈。
 
linux下:
一、部署erlang
#!/bin/bash
#this shell is used to deploy erlang###
#                         2010-12-23#####
#                               note.yang##
CURRENT_DIR=~+
RAMROOT=home/seasky/ramdisk
PASSWORD=address.config
IP=$1
/usr/local/bin/sshpass -p `grep $1 $CURRENT_DIR/$PASSWORD|awk -F "=" '{print $2}'`  scp -r ${CURRENT_DIR}/shell
/usr/local/bin/sshpass -p `grep $1 $CURRENT_DIR/$PASSWORD|awk -F "=" '{print $2}'` ssh ${IP} -l root "cd /tmp/shell&&sh -x destorydisk.sh&& sh -x initramdisk.sh"
/usr/local/bin/sshpass -p `grep $1 $CURRENT_DIR/$PASSWORD|awk -F "=" '{print $2}'` scp -r ${CURRENT_DIR}/erlang*.gz
/usr/local/bin/sshpass -p `grep $1 $CURRENT_DIR/$PASSWORD|awk -F "=" '{print $2}'` ssh ${IP} -l root "cd /tmp/shell&&./tar.sh"
 
 
二、检测网络状态、内存盘、erlang工作目录
 
 
#!/bin/bash
#this script is used to check remote host_status,ramdisk_status,erl_status
URRENT_DIR=~+
IP=$1
PASSWORD=address.config
SHELL=$3
BAD=1
/usr/local/bin/sshpass -p `grep $1 $CURRENT_DIR/$PASSWORD|awk -F "=" '{print $2}'` ssh "ls /bin/" >/dev/null 2>&1
 HOST_STATUS=$?
 if [ $HOST_STATUS = 0 ];then
 :
else
 echo "close"
 exit $BAD
fi
/usr/local/bin/sshpass -p `grep $1 $CURRENT_DIR/$PASSWORD|awk -F "=" '{print $2}'` ssh ${IP} -l root "df -h |grep ramdisk" >/dev/null 2>&1
 RAMDISK_STATUS=$?
    if [ $RAMDISK_STATUS = 0 ];then
 :
else
 echo "memdisk_unready"
 exit $BAD
fi
/usr/local/bin/sshpass -p `grep $1 $CURRENT_DIR/$PASSWORD|awk -F "=" '{print $2}'` ssh ${IP} -l root "ls -l  /home/seasky/ramdisk/erlang" >/dev/null 2>&1
 var=$?
 if [ $var = 0 ];then
 echo "erl_home:/home/seasky/ramdisk/erlang"
else
 echo "erl_unready"
 exit $BAD
fi
 
 
windows下:
 
一、同上。
 
 
@echo off
@rem
@rem \ this bat file is used to deploy erlan
@rem        at 2010-12-23
@rem
@set local_erlang_packet_dir=D:\deploy_erlang\erlang_small.tar.gz
@set remote_erlang_packet_dir=/home/seasky/ramdisk/
@set local_shell_dir=D:\deploy_erlang\shell
@set remote_shell_dir=/tmp
@set plink=F:\plink.exe
@set pscp=F:\pscp.exe
@set port=22
@rem
@ for /f "tokens=1,2 delims==" %%i in (F:\new\deploy_erlang\address.config)do if "%%i"=="%1" set ver=%%j
@rem echo.%ver%
@rem =====================================
@rem Transfer shell files to a remote host
@ %pscp% -pw %ver%  -r  %local_shell_dir%
@rem ==================================================================
@rem
@rem =======================================================
@rem Execute remote host scripts, the initialization remdisk
@%plink% -pw %ver%-P %port%  "cd /tmp/shell&&sh -x destorydisk.sh&& sh -x initramdisk.sh"
@rem =========================================================================================
 
@rem =======================================
@rem Transfer erlang packet to a remote host
@ %pscp% -pw %ver%-r %local_erlang_packet_dir%
@rem ==============================================================================
@rem
@rem ===================
@rem unzip erlang packet
@%plink% -pw %ver% -P %port%   "cd /tmp/shell&&sh -x tar.sh"
@rem ====================================================
@rem filished deploy erlang environment
echo "Deployment of Erlang environment completed"
 
二、
 
@echo off
@rem
@rem this bat is used to check the seasky hosts status
@rem                                              at 2010-12-23
@rem                                                note.yang
@rem
@rem
@set plink=F:\plink.exe
@set pscp=F:\pscp.exe
@set port=22
@set ERLANG_WORK_DIR=/home/seasky/ramdisk/erlang
@set grep_ramdisk="grep ramdisk"
@rem
@rem HOST_STATUS
@echo on
@ for /f "tokens=1,2 delims==" %%i in (F:\new\deploy_erlang\address.config)do if "%%i"=="%1" set ver=%%j
@echo.%ver%
%plink% -pw %ver% -P %port% "ls /bin/"  >nul 2>NUl
@if ERRORLEVEL 1 goto do
@if ERRORLEVEL 0 goto donot
:do
@echo  close
@rem
@goto exit >nul 2>nul
:donot
@echo.
@echo.
@rem RAMDISK_STATUS
 @%plink% -pw %2 -P %port% "df -h |%grep_ramdisk%" >nul 2>NUl
 @ if ERRORLEVEL 1 goto BAD
 @ if ERRORLEVEL 0 goto SUCCESSFUL
 :BAD
 @echo memdisk_unready
 @REM
 @goto exit >nul 2>nul
 :SUCCESSFUL
 @echo.
 @rem
@REM ERLANG_STATUS
%plink% -pw %2 -P %port% "ls %ERLANG_WORK_DIR%" >nul 2>NUL
@ IF ERRORLEVEL 1 GOTO FAILED
@ IF ERRORLEVEL 0 GOTO OK
:FAILED
@ECHO.
@ECHO.
@ ECHO erl_unready
@REM
@goto exit >nul 2>nul
:OK
@ECHO.
@REM
@REM
@REM ERLANG_WORK_DIR
  @%plink% -pw %2 -P %port% "ls -l %ERLANG_WORK_DIR%" >nul 2>NUL
  @ECHO.
  @ECHO. 
  @IF ERRORLEVEL 1 GOTO NO_ERLANG_WORK_DIR
  @IF ERRORLEVEL 0 GOTO ERLANG_WORK_DIR
  :NO_ERLANG_WORK_DIR
  @ECHO.
  @REM
  :ERLANG_WORK_DIR
  @ ECHO erl_home:%ERLANG_WORK_DIR%
  @REM
  @REM
  @REM
@REM
@REM
本地系统只执行部署和检测两个脚本,当执行脚本时,会把远端需要的脚本推送过去执行。远端脚本主要功能有,创建内存盘,创建erlang目录,安装erlang.
windows下有两个工具,plink和pscp.   与linux下ssh和scp功能类似,实现了连接和传递的功能。
 
阅读(2949) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~