Linux is a non-root user remote execution shell command notes

1. Remote execution

In the current execution user file. Bashrc configures the environment variable to be executed, similar / etc / profile

Note: If some commands are installed globally, no need to configure in environment variables

/Home/deploy_user/.bashrc

/////// // begin /////////

Export java_home = / usr / local / yourDir / Tools / JDK1.8.0_151

Export path = $ java_home / bin: $ PATH

Export classpath =.: $ java_home / jre / lib / rt.jar: $ java_home / lib / Tools.jar: $ java_home / lib / dt.jar: $ ClassPath

Export lang = zh_cn.utf-8

///////// End ////////////

2. Remote execution command

SSH [email protected] “/Home/deploy_user/deploy_sh/deploy_8091.sh”

3. Script of the target host:

//////// // begin ////////

#! / bin / bash

#Rtrive Pid of Current Java Code

Export dst_dir = / usr / local / yourDir / backend / Node4Customer

Export jar_name = tojoy-backend-0.0.1-snapshot.jar

Export jar_port = 8091

#export pid = `ps -ef | grep java | GREP $ {jar_name} | awk -f ” ‘{Print $ 2}’`

Export pid = `netstat -tnulp | grep $ {jar_port} | Grep java | awk -f ” {print $ 7} ‘| awk -f’ / ” {print $ 1} ‘`

Echo The Current Killed Java Pid IS $ {PID}

#firstly kill the capital java code

KILL -9 $ {PID}

export JVM_OPTS = “- server -Xms2G -Xmx2G -Xmn896M -Xss512k -XX: PermSize = 96M -XX: MaxPermSize = 256M -XX: + UseConcMarkSweepGC -XX: + UseParNewGC -XX: CMSFullGCsBeforeCompaction = 1 -XX: + UseCMSCompactAtFullCollection -XX: + CMSParallelRemarkEnabled -XX: + UseCMSInitiatingOccupancyOnly -XX: CMSInitiatingOccupancyFraction = 70 -XX: + CMSClassUnloadingEnabled -XX: + DisableExplicitGC -XX: + HeapDumpOnOutOfMemoryError “

#start the java code again

Echo java_home is $ {java_home}

#this Operation IS VIP

CD $ {DST_DIR}

Nohup java -jar $ {jvm_opts} $ {jar_name}> / dev / null &

Echo Sleep for 2 SECONDS

Sleep 2

//////////////////////

¡¾summary¡¿

1> If the command is installed instead of unzipped configuration, it is necessary to configure the environment variable of the current user, otherwise, must be configured in the current user environment variable;

2> Perform the log back to the device / dev / NULL by NOHUP, avoiding the increase in NOHUP.out;

3> In the current host, the script on the target host is executed, which is quite open for the current user to log in to SSH;

4> To verify that the existing environment variables are effective, you can analyze the Echo log; [Tips]

If you feel satisfied, you can choose to support, your support is my biggest motivation:

Related Posts