Tuesday, March 20, 2012

One line for loop Linux command

Format : for i in {1..N} ; do  <command>;done;
Eg :
for i in {1..100} ;
do  sleep 2;echo `date`;done;

Installing custom init-scripts

Let’s say you want to start a script every time you start
your linux machine (Ubuntu) and stop 
when shutdown sequence initiate.

Create your script eg : ‘myScript’

1. sudo vim /etc/init.d/myScript              or ‘vi’ to write the script.
2. sudo chmod +x /etc/init.d/myScript                    [to adjust the permission]
3. sudo update-rc.d myScript defaults 98 02  [98 and 02 are the start 
                                 and stop sequence numbers respectively]
 
myScript above accept start and stop as arguments .
Refer your ‘tomcat’ script in /etc/init.d/tomcat if you want to 
know how to accept above arguments (if you dont have stop ,
then it will retry same thing at shutdown). 
my above script eg is for start/stop vpn.
 
Source reference from: https://help.ubuntu.com/community/UbuntuBootupHowto