diff options
| author | chenjinsong <[email protected]> | 2018-09-27 16:11:54 +0800 |
|---|---|---|
| committer | chenjinsong <[email protected]> | 2018-09-27 16:11:54 +0800 |
| commit | 56d71f261a8bd6031e47e2bf80867049a2aa13da (patch) | |
| tree | f09257b2143782a333a9eda3395137837d9bdad1 /linuxinstall/shell | |
initial commit
Diffstat (limited to 'linuxinstall/shell')
| -rw-r--r-- | linuxinstall/shell/check_userpass.sh | 47 | ||||
| -rw-r--r-- | linuxinstall/shell/execCmdBySu.sh | 78 | ||||
| -rw-r--r-- | linuxinstall/shell/nmsagent.sh | 260 | ||||
| -rw-r--r-- | linuxinstall/shell/nmsclient_shouhu.sh | 55 | ||||
| -rw-r--r-- | linuxinstall/shell/restart.sh | 30 | ||||
| -rw-r--r-- | linuxinstall/shell/shutdown.sh | 30 | ||||
| -rw-r--r-- | linuxinstall/shell/startup.sh | 30 |
7 files changed, 530 insertions, 0 deletions
diff --git a/linuxinstall/shell/check_userpass.sh b/linuxinstall/shell/check_userpass.sh new file mode 100644 index 0000000..6e6dc7d --- /dev/null +++ b/linuxinstall/shell/check_userpass.sh @@ -0,0 +1,47 @@ +#!/usr/bin/expect + +if {$argc!=3} { + send_user "usage: check_userpass.sh ip name password\n" + exit 1 +} + +set host [lindex $argv 0] +set user [lindex $argv 1] +set pass [lindex $argv 2] + +set isSend 0 +spawn ssh -t "${user}@${host}" + +while 1 { + expect { + "* (yes/no)*" {send "yes\r"} + "* ����*" { + send "${pass}\r" + set isSend 1 + } + "* password:*" { + send "${pass}\r" + set isSend 1 + } + "Permission denied" { + send_user "Not allowed\n" + exit 1 + } + "*~]" { + send_user "OK\n" + send "exit\r" + exit 0 + } + "Last login:*" { + send_user "OK\n" + send "exit\r" + exit 0 + } + default { + send_user "error\n" + exit 2 + } + } +} + + diff --git a/linuxinstall/shell/execCmdBySu.sh b/linuxinstall/shell/execCmdBySu.sh new file mode 100644 index 0000000..4a94436 --- /dev/null +++ b/linuxinstall/shell/execCmdBySu.sh @@ -0,0 +1,78 @@ +#!/usr/bin/expect + +if {$argc!=4&&$argc!=3} { + send_user "usage: execCmdBySu.sh resultFlag command name \[password\]\n" + exit 1 +} +# 0��ִ�����ȡ�ý����1��ִ��&��̨���� +set resultFlag [lindex $argv 0] +set cmd [lindex $argv 1] +set user [lindex $argv 2] +set pass [lindex $argv 3] + +set timeout 30 +set flag 0 + +#�رտ���̨�����Ϣ +log_user 0 + +spawn whoami +expect "root" {set flag 1} + +# ��ִ������${cmd}����"echo $?",Ϊ��ȡcmd�������е�ʵ�ʽ��, �����ε���������ص������Ϣ +if {$resultFlag==0} { + spawn su - -c "${cmd};echo $?" ${user} + + #��ǰ��¼�û�����root���������� + if {$flag==0} { + expect { + "����*" {send ${pass}\r} + "password*" {send ${pass}\r} + default { + send_error "error\n" + exit 2 + } + } + } + + #����̨�����Ϣ + log_user 1 + + expect { + "* ���벻��ȷ*" {exit 1} + #----�˴���Ŀ����Ϊ���ܶ�ȡ������������ + eof {exit 0} + } + +} else { + spawn su - -c "${cmd}" ${user} + + #��ǰ��¼�û�����root���������� + if {$flag==0} { + expect { + "����*" {send ${pass}\r} + "password*" {send ${pass}\r} + default { + send_error "error\n" + exit 2 + } + } + } + expect { + "* ���벻��ȷ*" {exit 1} + #----Ϊ��&��̨������������������ + eof { + send_user "ok\n" + exit 0 + } + } +} +interact +exit 0 + + +#overlay chess +#overlay program args +#disconnect +#close -onexec 0 -i ${spawn_id} +#remove_nulls 1
\ No newline at end of file diff --git a/linuxinstall/shell/nmsagent.sh b/linuxinstall/shell/nmsagent.sh new file mode 100644 index 0000000..9450828 --- /dev/null +++ b/linuxinstall/shell/nmsagent.sh @@ -0,0 +1,260 @@ +#!/bin/sh + +# ----------------------------------------------------------------------------- +# Start/Stop Script for the NMS Client +# +# Environment Variable Prequisites +# +# NMSCLEINT_HOME May point at your Catalina "build" directory. +# +# NMSCLIENT_TASKDIR (Optional) Directory path location of taskresult directory +# Defaults to %NMSCLIENT_HOME%/task. +# +# NMSCLIENT_TMPDIR (Optional) Directory path location of temporary directory +# the JVM should use (java.io.tmpdir). Defaults to +# $NMSCLIENT_HOME/temp. +# +# JAVA_HOME Must point at your Java Development Kit installation. +# Required to run the with the "debug" argument. +# +# ----------------------------------------------------------------------------- +# resolve links - $0 may be a softlink +PRG="$0" + +#OS_TYPE=$( lsb_release -d| cut -d: -f2| cut -f2 ) +#echo $OS_TYPE +while [ -h "$PRG" ]; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`/"$link" + fi +done + +# Get standard environment variables +PRGDIR=`dirname "$PRG"` + +# Only set NMSCLEINT_HOME if not already set +[ -z "$NMSCLEINT_HOME" ] && NMSCLEINT_HOME=`cd "$PRGDIR/.." ; pwd` +cd "$NMSCLEINT_HOME"/shell + +if [ -z "$NMSCLIENT_TMPDIR" ] ; then + NMSCLIENT_TMPDIR="$NMSCLEINT_HOME"/temp +fi +if [ ! -d $NMSCLIENT_TMPDIR ] + then + mkdir $NMSCLIENT_TMPDIR +fi + +if [ -n "$4" ]; then + NMSCLIENT_TASKDIR=`dirname "$4"` +fi +if [ -z "$NMSCLIENT_TASKDIR" ] ; then + NMSCLIENT_TASKDIR="$NMSCLEINT_HOME"/task +fi + + +# -------- check jdk +# check nmsjdk +NMS_HOME=`cd "$NMSCLEINT_HOME/.." ; pwd` +cd "$NMSCLEINT_HOME"/shell +NMS_JDK="$NMS_HOME"/nmsjdk +if [ ! -e "$NMS_JDK" ] + then + echo "$NMS_JDK not exist" + exit 0 +fi +# check java -version +javaversion=`$NMS_JDK/bin/java -version 2>&1|grep "java version"` +if [ ! -n "$javaversion" ] + then + echo "$NMS_JDK cannot use, please install" + exit 0 +fi + +# -------- set jdk path +export JAVA_HOME=$NMS_JDK +export CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar +export PATH=$JAVA_HOME/bin:$PATH + +temp=$CLASSPATH +#setting libs path +libs="$NMSCLEINT_HOME"/lib/* +append(){ + temp=$temp":"$1 +} +for file in $libs; do + append $file +done +jars="$NMSCLEINT_HOME"/bin/* +for file in $jars; do + append $file +done +export NC_CLASSPATH=$temp:.:$NMSCLEINT_HOME/conf +export LD_LIBRARY_PATH=$NMSCLEINT_HOME/lib +export LANG=zh_CN.UTF-8 + +# Bugzilla 37848: When no TTY is available, don't output to console +have_tty=0 +if [ "`tty`" != "not a tty" ]; then + have_tty=1 +fi + +# ----- Execute The Requested Command ----------------------------------------- + +# Bugzilla 37848: only output this if we have a TTY +if [ $have_tty -eq 1 ]; then + echo "Using NMSCLEINT_HOME: $NMSCLEINT_HOME" + echo "Using NMSCLIENT_TMPDIR: $NMSCLIENT_TMPDIR" + echo "Using JAVA_HOME: $JAVA_HOME" + echo "Using CLASSPATH: $NC_CLASSPATH" +fi + +# ---- get jvm param +jvmconf_file=$NMSCLEINT_HOME"/conf/jvm.conf" +if [ -f $jvmconf_file ] + then + #sed -n '/Xmx=/p' $jvmconf_file | sed 's/Xmx=//g' + XmsOpt=`sed -n '/-Xms/p' $jvmconf_file` + XmxOpt=`sed -n '/-Xmx/p' $jvmconf_file` + JAVA_OPTS="$XmsOpt $XmxOpt -XX:+UseParNewGC" +else + JAVA_OPTS="-Xms64m -Xmx128m -XX:+UseParNewGC" +fi + +program="com.nis.nmsclient.NmsClient" +name="NmsClient" + +proc_id= + +# handler agent upgrade result +handleTask() +{ + if [ -d "$NMSCLIENT_TASKDIR" ] + then + cd $NMSCLIENT_TASKDIR + for i in *.upgrade;do mv "$i" "${i%.upgrade}.result";done >/dev/null 2>&1 + cd "$NMSCLEINT_HOME"/shell + fi +} +writePid() +{ + ps aux|grep java|grep $program|grep -v grep|awk '{print $2}' > $NMSCLIENT_TMPDIR/agentPid.temp +} +getPid() +{ + unset proc_id + proc_id=`ps aux|grep java|grep $program|grep -v grep|awk '{print $2}'` +} +shouhu_proc="$NMSCLEINT_HOME"/shell/nmsclient_shouhu.sh +stopShouhuProc() +{ + shouhu_proc_id=`ps aux|grep $shouhu_proc|grep -v grep|awk '{print $2}'` + if [ -n "$shouhu_proc_id" ] + then + echo "kill shouhu process ....." + kill -9 $shouhu_proc_id + fi +} +startShouhuProc() +{ + shouhu_proc_id=`ps aux|grep $shouhu_proc|grep -v grep|awk '{print $2}'` + if [ ! -n "$shouhu_proc_id" ] + then + echo "start shouhu process ....." + nohup $shouhu_proc $NMSCLIENT_TASKDIR >/dev/null & + fi +} +if [ "$1" = "start" ] ; then + getPid + if [ -n "$proc_id" ] + then + echo "$name already running......" + else + nohup java $JAVA_OPTS -classpath $NC_CLASSPATH $program >/dev/null & + sleep 3 + getPid + if [ -n "$proc_id" ] + then + echo "$name start success!!!!!" + writePid + else + echo "$name start error!!!!!" + fi + handleTask + fi +elif [ "$1" = "stop" ]; then + getPid + if [ -n "$proc_id" ] + then + stopShouhuProc + sleep 1 + echo "$name is start, now kill......" + kill -9 $proc_id + writePid + echo "$name kill ok !!!!!!!!!!!!!" + else + echo "$name is not start!!!!!!!!!!!" + fi +elif [ "$1" = "restart" ] ; then + getPid + if [ -n "$proc_id" ] + then + echo "$name is start, now restart......" + stopShouhuProc + sleep 1 + startShouhuProc + kill -9 $proc_id + getPid + if [ -n "$proc_id" ] + then + echo "$name stop error!!!!!!!!!!" + handleTask + exit 1 + fi + else + echo "$name is not start, now start......" + fi + copyError= + if [ -n "$2" ] ; then + srcFile=$2 + updateFile=/dev/null + if [ -d "$2" ]; then + srcFile="$2"/* + fi + if [ -n "$4" ]; then + updateFile=$4 + fi + if [ -n "$3" ]; then + unalias cp >/dev/null 2>&1 + cp -rvf $srcFile $3 >>$updateFile 2>&1 ||copyError=1 + fi + rm -rf $2 >/dev/null 2>&1 + fi + if [ -n "$copyError" ] + then + #----copy error + handleTask + else + #--------copy right, start proc + nohup java $JAVA_OPTS -classpath $NC_CLASSPATH $program >/dev/null & + sleep 3 + getPid + if [ -n "$proc_id" ] + then + writePid + else + echo "$name restart error!!!!!!!!!!" + handleTask + fi + fi + +else + echo "Usage: nmsagent.sh ( commands ... )" + echo "commands:" + echo " start Start $name in a separate window" + echo " restart ReStart $name in a separate window" + echo " stop Stop $name" +fi diff --git a/linuxinstall/shell/nmsclient_shouhu.sh b/linuxinstall/shell/nmsclient_shouhu.sh new file mode 100644 index 0000000..821884f --- /dev/null +++ b/linuxinstall/shell/nmsclient_shouhu.sh @@ -0,0 +1,55 @@ +#!/bin/sh + +# resolve links - $0 may be a softlink +PRG="$0" + +while [ -h "$PRG" ]; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`/"$link" + fi +done + +# Get standard environment variables +PRGDIR=`dirname "$PRG"` + +# Only set NMSCLEINT_HOME if not already set +[ -z "$NMSCLEINT_HOME" ] && NMSCLEINT_HOME=`cd "$PRGDIR/.." ; pwd` +cd "$NMSCLEINT_HOME"/shell + +NC_TASKDIR="$1" +log_file="$NMSCLEINT_HOME"/temp/job.log +echo "NC_TASKDIR:$NC_TASKDIR" >> $log_file + +#count=1 +while [ 1 -eq 1 ] +do + sleep 50 + if [ `ps -ef | grep NmsClient | grep -v grep | wc -l` -lt 1 ] + then + echo -n "Down at:" >> $log_file + date >> $log_file + # ---------- handler agent upgrade result + if [ -d "$NC_TASKDIR" ] + then + cd $NC_TASKDIR + for i in *.upgrade;do mv "$i" "${i%.upgrade}.result";done >>$log_file 2>&1 + cd "$NMSCLEINT_HOME"/shell + fi + # --------- start NC + "$NMSCLEINT_HOME"/shell/startup.sh + echo "NmsClient start...." >>$log_file + fi + sleep 1 + #count=$count+1 + + #if [ count -eq 900 ] + #then + # jpid=`ps -ef | grep java | grep -v grep | cut -c0-5` + # kill -9 $jpid + # count=1 + #fi +done
\ No newline at end of file diff --git a/linuxinstall/shell/restart.sh b/linuxinstall/shell/restart.sh new file mode 100644 index 0000000..f3c288d --- /dev/null +++ b/linuxinstall/shell/restart.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +# ----------------------------------------------------------------------------- +# Retart Script for the NMS Client +# +# ----------------------------------------------------------------------------- + +# resolve links - $0 may be a softlink +PRG="$0" + +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`/"$link" + fi +done + +PRGDIR=`dirname "$PRG"` +EXECUTABLE=nmsagent.sh + +if [ ! -x "$PRGDIR"/"$EXECUTABLE" ]; then + echo "Cannot find $PRGDIR/$EXECUTABLE" + echo "This file is needed to run this program" + exit 1 +fi + +exec "$PRGDIR"/"$EXECUTABLE" restart $1 $2 $3 "$@"
\ No newline at end of file diff --git a/linuxinstall/shell/shutdown.sh b/linuxinstall/shell/shutdown.sh new file mode 100644 index 0000000..bc5ecc9 --- /dev/null +++ b/linuxinstall/shell/shutdown.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +# ----------------------------------------------------------------------------- +# Stop Script for the NMS Client +# +# ----------------------------------------------------------------------------- + +# resolve links - $0 may be a softlink +PRG="$0" + +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`/"$link" + fi +done + +PRGDIR=`dirname "$PRG"` +EXECUTABLE=nmsagent.sh + +if [ ! -x "$PRGDIR"/"$EXECUTABLE" ]; then + echo "Cannot find $PRGDIR/$EXECUTABLE" + echo "This file is needed to run this program" + exit 1 +fi + +exec "$PRGDIR"/"$EXECUTABLE" stop "$@"
\ No newline at end of file diff --git a/linuxinstall/shell/startup.sh b/linuxinstall/shell/startup.sh new file mode 100644 index 0000000..a28c64a --- /dev/null +++ b/linuxinstall/shell/startup.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +# ----------------------------------------------------------------------------- +# Start Script for the NMS Client +# +# ----------------------------------------------------------------------------- + +# resolve links - $0 may be a softlink +PRG="$0" + +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`/"$link" + fi +done + +PRGDIR=`dirname "$PRG"` +EXECUTABLE=nmsagent.sh + +if [ ! -x "$PRGDIR"/"$EXECUTABLE" ]; then + echo "Cannot find $PRGDIR/$EXECUTABLE" + echo "This file is needed to run this program" + exit 1 +fi + +exec "$PRGDIR"/"$EXECUTABLE" start "$@"
\ No newline at end of file |
