check if program running in linux
Inshell,weusethebelowprogramtocheckifsomeprogramalreadyrunning:
exportHOMEDIR=/../../
exportJAVA_HOME=/usr/lib/jvm/java-1.6.0
exportLOGFILE=/tmp/log_`date+"%Y%m%d-%H%M%S"`.log
exportJAVA_CMD=$JAVA_HOME/bin/java
exportCLASSPATH=$JAVA_HOME/lib/tools.jar:$HOMEDIR/lib/ojdbc-14.jar:$HOMEDIR/lib/log4j-1.2.14.jar:$HOMEDIR/lib/commons-logging-1.1.jar
exportMAIN_PROGRAM=com.test.theClassEntry
ps-ef|grep"java">SomeFile
num=$(wc-lSomeFile|awk'{print$1}')
if[$num-gt0]
then
echo"thejavaprocessisrunning">$LOGFILE
exit1
else
nohup$JAVA_CMD-Xmx10g-Dflag=true-classpath"$CLASSPATH"$MAIN_PROGRAMprogram_parameter>$LOGFILE2>&1&
fi
note:
1.-Dproperty=value
Setasystempropertyvalue.Youcancallthefollowingfromanywhereinthecodetoreadthepropertiesgivenonthecommandline:
Stringvalue=System.getProperty("key","defaultvalue");
2.
http://www.linfo.org/ps.html
Analternativesetofoptionsforviewingalltheprocessesrunningonasystemis
ps-ef|less
The-eoptiongeneratesalistofinformationabouteveryprocesscurrentlyrunning.The-foptiongeneratesalistingthatcontainsfeweritemsofinformationforeachprocessthanthe-loption.
3.
http://www.thegeekstuff.com/2010/01/awk-introduction-tutorial-7-awk-print-examples/
AwkExamplePrintonlyspecificfield.
Awkhasnumberofbuiltinvariables.Foreachrecordi.eline,itsplitstherecorddelimitedbywhitespacecharacterbydefaultandstoresitinthe$nvariables.Ifthelinehas4words,itwillbestoredin$1,$2,$3and$4.$0representswholeline.NFisabuiltinvariablewhichrepresentstotalnumberoffieldsinarecord.
$awk'{print$2,$5;}'employee.txt
Thomas$5,000
Jason$5,500
Sanjay$7,000
Nisha$9,500
Randy$6,000
$awk'{print$2,$NF;}'employee.txt
Thomas$5,000
Jason$5,500
Sanjay$7,000
Nisha$9,500
Randy$6,000
Intheaboveexample$2and$5representsNameandSalaryrespectively.WecangettheSalaryusing$NFalso,where$NFrepresentslastfield.Intheprintstatement‘,’isaconcatenator.