Startup script start.sh This script is used to start the project, log logs and PID
#!/bin/shprg=" $" #$ A represents the current startup script
# Get the true path of the file while[-H"$PRG"]; Dols= ' Ls-ld"$PRG"' link= ' Expr"$ls": ' .*-> \ (. *\) $"'ifExpr"$link": '/.* ' >/dev/null; then PRG="$link" ElsePRG= ' DirName"$PRG"`/"$link"Fidone#intercepting file PathsPrgdir= ' DirName"$PRG"` [ -Z"$APP _home"] && app_home= ' CD"$PRGDIR">/dev/null; PWD ' [-Z"$APP _pid"] && app_pid=$APP _home/PID file_list= ' ls${app_home}' Jar_file=""Log_file=""
# Fill variable values forFILEinch $FILE _list Do if["${file##*.}"="Jar" ]; Then Jar_file="${app_home}/${file}"Log_file="${file%.*}.log"Fidoneif[-Z$JAR _file ]; Then Echo"error:no jar file in $APP _home"Exitfiif[- F "$APP _pid" ]; Then PID= ' Cat$APP _pid' RM-rf$APP _pidfi
# load config file, start Java project with Java-jar *.jar, and output to log file source/etc/profileopts="-dfile.encoding=utf8-djasypt.encryptor.password=${jasypt_password}-djava.security.egd=file:/dev/./urandom- Xmx512m-verbose:gc-xx:+printgcdetails-xx:+printgcdatestamps-xx:+heapdumponoutofmemoryerror-xloggc:gc.log"nohup Java$DEBUG-jar$OPTS ${jar_file}>$APP _home/${log_file}2>&1 &PID=$!Echo$PID>${app_pid}if[ !- F $APP _home/App.log]; Then Echo"begin ... ..">>$APP _home/App.logfi
If judgment parameter
[-a file] True if file exists [-B file] True if file exists and is a block special file [-C File] True if file exists and is a word special file [-(d file] True if file is present and is a directory [! -D file] indicates that the following directory does not exist [-e File] True if file files exist [- FFile ] True if file exists and is a normal file [-g file] True if file exists and SGID is set (SUID is the set User ID, SGID is the set Group ID) [-h file] True if file exists and is a symbolic connection [-K file] True if file exists and the sticky bit has been set [-p file] If file exists and is a name pipe (f if O) is a true pipe is a way of inter-process communication in Linux, and other such as signal (signal), Semaphore, message queue, shared memory, socket (socket) and so on. [-R File] True if file exists and is readable [-s file] True if file exists and the size is not 0 [-T FD] True if the file descriptor FD is open and points to a terminal [-u file] True if file exists and set Suid (set UserID) [-W file] True if file exists and is writable [-x file] True if file exists and is executable [-O file] True if file exists and is a valid user ID [-G file] True if file exists and is a valid user group [-L file] True if file exists and is a symbolic connection [-N file] If file exists and has been mod if IED since it is last read is true [-S file] If file exists and is a socket true [file1–nt file2] If file1 have been changed more recently than File2 or file1 exists and file2 does not true [File1–ot file2] If file1 is older than file2, or file2 exists and file1 does not exist [File1–ef File2] True if File1 and File2 point to the same device and node number [-o Optionname] true if the shell option "Optionname" is turned on [-Z string] "String" is true if the length is zero [-N string] or [string] "string" length is not 0 non-Zero is true [Sting1==STRING2] If 2 strings are the same. "=" may be used instead of "= =" forstrict POSIX compliance is true [string1!=string2] True if the string is not equal [string1<string2] if "string1" sorts before " string2" lexicographicallyinchThe current locale is true
prgdir= ' dirname "$PRG" 'Part of the directory used to intercept files
[[email protected] AA] # DIRNAME/DATA/SSTH/EXCENTER/AA/data/ssth/excenter
"${file##*.}" = "jar"
${}: Used for string interception, it and # (intercept left),% (intercept right)
${file#*/}: Delete the first/its left string: Dir1/dir2/dir3/my.file.txt${file##*/}: Delete last/ And the string to the left: My.file.txt${file#*.} : Remove the first one. And its left string: file.txt${file##*.} : Remove the last one. And its left string: txt${file%/*}: Delete the last/ and its right string:/dir1/dir2/dir3${file%%/*}: Delete the first/ and the string to the right: (null value)${file%.*}: Delete the last one . And the string to the right:/dir1/dir2/dir3/my.file${file%%.*}: Delete the first one . And the string to the right:/dir1/dir2/dir3/my
nohup java $DEBUG-jar $OPTS ${jar_file} > $APP _home/${log_file} 2>&1 &This statement has done three things: 1
nohup * &: Indicates uninterrupted execution of commands, where & means uninterrupted meaning 2
>: is a shorthand for 1>, which indicates standard output 3
2>&1: Output standard error to standard output channel
There are three common streams and their code in the operating system: standard input stream stdin:0 standard output stream stdout:1 standard error stream stderr:2
Example: Distinguishing between standard output and error output
[[email protected] AA]#llTotal dosage 4-rw-r--r--. 1 root root 8 May 24 09:50A.txt[root@test AA]#ls a.txt b.txtLS: Unable to access b.txt: No file or directory A.txt[root@test AA]#ls a.txt b.txt 1> output 2>err #将标准输出到output文件, outputting error to err file[[email protected] AA]#llTotal dosage 12-rw-r--r--. 1 root root 8 May 24 09:50a.txt-rw-r--r--. 1 root root 51 May 24 09:52Err-rw-r--r--. 1 root root 6 May 24 09:52Output[root@test AA]#Cat ErrLS: Unable to access b.txt: No file or directory [root@test AA]#Cat OutputA.txt[root@test AA]#ls a.txt b.txt 1> output 2>&1 #转换为上面的内容即是, both standard and error outputs are placed in the specified file[[email protected] AA]#Cat OutputLS: Unable to access b.txt: No file or directory A.txt
>/dev/null> is the standard output,/dev/null indicates that the output is not displayed in the console
Shell Scripting Learning