Run bash script in background


To run a bash script in the background as a daemon.

Run the below

nohup ./SCRIPTHERE &

You may need to press enter afterwards, just check its running by doing a

ps -ef | grep SCRIPTHERE
Advertisements

pssst…ps


ps is another great facility in linux. It allows you to monitor what processes are running on a server. Using the below command we can identify the top CPU hungry processes.
ps

ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10

result

%CPU   PID USER     COMMAND
29.6   651 jboss    /usr/jdk1.6.0_12/bin/java -server -Xms2048m -Xmx2048m -XX:+AggressiveHeap -XX:+UseParallelGC -XX:PermSize=128m -XX:MaxPermSize=256m -Djava.awt.headless=true -Dsun.jnu.encoding=UTF-8 -Dfile.encoding=UTF-8 -Dlog4j.configuration=log4j.configuration.properties -Dprogram.name=run.sh -Djava.endorsed.dirs=/usr/local/jboss-4.0.3SP1/lib/endorsed -classpath /usr/local/jboss-4.0.3SP1/bin/run.jar:/usr/jdk1.6.0_14/lib/tools.jar org.jboss.Main
 0.5  8539 apache   /usr/local/apache2/bin/httpd -k start
 0.5  8208 apache   /usr/local/apache2/bin/httpd -k start
 0.5  8154 apache   /usr/local/apache2/bin/httpd -k start
 0.5  8129 apache   /usr/local/apache2/bin/httpd -k start
 0.5  8127 apache   /usr/local/apache2/bin/httpd -k start
 0.4  4712 root     /usr/bin/ruby /usr/sbin/puppetd --server=someserverhere.server.com
 0.2 15860 nscd     /usr/sbin/nscd
 0.0     9 root     [ksoftirqd/3]