码迷,mamicode.com
首页 > 系统相关 > 详细

Shell常用操作

时间:2015-03-31 14:20:19      阅读:252      评论:0      收藏:0      [点我收藏+]

标签:

1、读取配置文件中的jdbc_url参数的值($InputParamFile为待读取的目标文件绝对路径)

jdbc_url=`grep "jdbc_url" $InputParamFile | awk -F ‘=‘ ‘{print $2}‘`

2、修改配置文件jdbc_url参数的值(${jdbcConfigFilePath}为待修改的目标文件绝对路径)

sed -i "s#\${jdbc_url}#${jdbc_url}#" ${jdbcConfigFilePath}

3、启动Jetty脚本

JETTY_PORT=1$1
APP_HOME=`pwd`
app_status() {
        port=`ps -aef | grep STOP.PORT=19393 | sed -n 1p | awk {if($8~/java/)print $9} | awk -F= {print $2}`
     
        if [ -z $port ] ; then
                return 1
        fi

        if [ "$port" == "$JETTY_PORT" ] ; then
                return 0
        else
                return 1
        fi
}


if app_status ; then
     echo "app is running now....."
else
    java -DSTOP.PORT=$JETTY_PORT -Djava.net.preferIPv4Stack=true -server -Xms1G -Xmx1G -Xmn256M -XX:PermSize=256M -XX:MaxPermSize=256M  -XX:SurvivorRatio=32 -XX:MaxTenuringThreshold=3 -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+UseCMSCompactAtFullCollection -XX:CMSFullGCsBeforeCompaction=0 -XX:+CMSClassUnloadingEnabled -XX:-CMSParallelRemarkEnabled -XX:CMSInitiatingOccupancyFraction=90 -XX:SoftRefLRUPolicyMSPerMB=0 -Djava.util.logging.config.file="$YACS_HOME/yacs/conf/log4j.xml" -jar start.jar & 
fi

4、停止Jetty脚本

#$JAVA_RUN $JETTY_OPTS -jar start.jar --stop

#  del by xxx end




jsDir=`pwd`
ps -ef|grep 19393|grep -v "grep"|awk {print $2}|xargs kill -9




DOWNTIME=`date +%Y/%m/%d" "%A" "%H:%M:%S`
echo -e "\n\napp shutdown-time is: $DOWNTIME \n\n" >>app/log/error/app-error.log

5、查看Jetty运行状态

#!/bin/sh
#
# All Rights Reserved

# -------------------------------------------------------------------------------
# Environment Variable Prequisites Before Start/Stop Script for the Jetty Server
#
#   JETTY_HOME      May point at your jetty setup directory.
#
#   JAVA_HOME       Must point at your Java Development Kit installation.
#                   Required to run the with the "debug" or "javac" argument.
#
#   JRE_HOME        Must point at your Java Development Kit installation.
#                   Defaults to JAVA_HOME if empty.
#
#   JETTY_PORT      Must point at your jetty stop port, when you start jetty server.
#
#   JAVA_OPTS       (Optional) Java runtime options used when the "start",
#                   "stop", or "run" command is executed.
#
#   JETTY_RUN       (Optional) output terminal when to start jetty server.
#
#   JPDA_OPTS       (Optional) Java runtime options used when the "jpda start"
#                   command is executed. If used, JPDA_TRANSPORT, JPDA_ADDRESS,
#                   and JPDA_SUSPEND are ignored. Thus, all required jpda
#                   options MUST be specified. The default is:
#
#                   -agentlib:jdwp=transport=$JPDA_TRANSPORT,
#                       address=$JPDA_ADDRESS,server=y,suspend=$JPDA_SUSPEND
#
#   JETTY_OPTS      Must point at when to start jetty server, which can show jetty 
#                   stop port.
# ---------------------------------------------------------------------------------

BINDIR=`dirname $0`
if [ -n "$BINDIR" ] ; then
    JETTY_HOME=`cd $BINDIR > /dev/null 2>&1 && pwd`
    export JETTY_HOME
fi

if [ -z "$JETTY_HOME" ] ; then
    if [ -n "$BINDIR" ] ; then
        JETTY_HOME=`cd $BINDIR > /dev/null 2>&1 && pwd`
        export JETTY_HOME
    fi
fi

# set JAVA_HOME variable here.
#JAVA_HOME=/usr/local/test/jdk1.5.0_22

if [ -n "$JAVA_HOME"  ] ; then
    JAVA_RUN=$JAVA_HOME/bin/java
    export JAVA_HOME
else
    JAVA_RUN=`which java 2> /dev/null `
    if [ -z "$JAVA_RUN" ] ; then
        JAVA_RUN=java
    fi
fi

#set jetty start options
JETTY_PORT=19393
JETTY_OPTS="-DSTOP.PORT=$JETTY_PORT -DSTOP.KEY=secret"
JETTY_RUN="tail -f nohup.out"

#set product name for app
PRODUCT_NAME=app

export JAVA_RUN
export PATH="$JETTY_HOME/bin:$PATH"

#decide yacs status
#return 0 represent YACS is running
#return 1 represent YACS is not running
yacs_status() {
    port=`ps -aef | grep STOP.PORT=$JETTY_PORT | sed -n 1p | awk {if($8~/java/)print $9} | awk -F= {print $2}`
    echo $port
    if [ -z $port ] ; then
        return 1 
    fi
        
    if [ "$port" == "$JETTY_PORT" ] ; then
        return 0 
    else 
        return 1 
    fi
}

6、重启Jetty

./stopiuc.sh
sleep 10
./startiuc.sh

7、导入MySQL数据

installorupdatemysql()
{
if [ $reBuilddDB == "N" ];then 
 return ;
fi


    echo " start create mysql userdatabase "
    # 导入数据
    cd $install_home/SQL/Mysql/Install
    
    mysql -uroot -p$password << EOF
    source 00_create_user.sql;
    use app;
    source 01_app_install.sql;
EOF

echo " end create mysql userdatabase "
}

 

Shell常用操作

标签:

原文地址:http://www.cnblogs.com/huige-you/p/4380708.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!