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

Wednesday, February 15, 2012

Disable root login in Ubuntu – Avoid unexpected ‘OMG’ problems.


Recently I faced a huge issues in my production environment ,where ppl try to login as root to system which made system more unstable(Yes I know its in mess- super democracy server). As you know Ubuntu came with ‘Sudo’ concept which gives all the privilege’s that you want in systems. There for don not allow root user in your system especially in production. More details can be found in : https://help.ubuntu.com/community/RootSudo

 Two steps to block any root logins :
1.      Disable Root user : 
sudo passwd -dl root

2.  Disable root login in ssh config:
vim /etc/ssh/sshd_config
PermitRootLogin no
And restart sshd -- > /etc/init.d/sshd restart


BTWAY: I was able to recover lost root password from a linux machine. Will update on that in future release .

Monday, February 6, 2012

Detect USB Flash Drivers in linux

Following Script Display possible USB devices attached to the system : Tested on Ubantu 10.04 LTS

#!/bin/sh
#author sanjeewaF

for udi in $(/usr/bin/hal-find-by-capability --capability storage)
do
    device=$(hal-get-property --udi $udi --key block.device)
    vendor=$(hal-get-property --udi $udi --key storage.vendor)
    model=$(hal-get-property --udi $udi --key storage.model)

   if  [ `hal-get-property --udi $udi --key linux.sysfs_path | grep -i usb | wc -l` -gt 0 ]
   then
           echo "Possible USB:"
           parent_udi=$(hal-find-by-property --key block.storage_device --string $udi)
           mount=$(hal-get-property --udi $parent_udi --key volume.mount_point)
           label=$(hal-get-property --udi $parent_udi --key volume.label)
            media_size=$(hal-get-property --udi $udi --key storage.removable.media_size)
           size=$(( media_size/(1000*1000*1000) ))
            printf "$vendor  $model  $device  $mount  $label "${size}GB" \n"
    fi
done

Wednesday, October 26, 2011

Set Date In Ubantu

1 . Set Timezone 2. sudo date --set="26 OCT 2011 19:51:00" 3 You can sync the Hw clock aswell : hwclock -w

Tuesday, August 30, 2011

Tomcat Remote Debug in linux

add folowing inside /etc/default/tomcat6

JAVA_OPTS="${JAVA_OPTS} -Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"

and restart . tomcat debug is now in port 8787

Monday, August 22, 2011

linux + convert file to Unix format

1. vi filename
2. Esc --> : set fileformat=unix
3.wq!