Thursday 21 February 2013

Find files

$ find /dir/to/search -name "fileName"

$ find   -name "fileName*"
this will search in the current directory and its sub-directories . It turned out that on my RedHat I had to use " " instead of single quotes ' '

$ find /dir/to/search -type d  -name "dirName"
search for a directory with name "dirName"

Wednesday 20 February 2013

Symbolik links (soft link)

$ ln -s /path/to/link/to   /place/symlink/here

$ ln -s /home/user/   MySymlink
will create symbolik link "MySymlink" that will link to the path /home/user


#!/bin/sh and its options -x and -e

Let’s look at an example.
#!/bin/sh
make
echo “Build exit code was $?”
What is the exit code of the script above?
It will be zero, always. Why?
Because the exit code of a script is the exit code of the last command and the echo command will succeed with very high probability.


The shell has a convenient option -e, which causes shell to stop running a script immediately when any command exits with non-zero exit code. This makes it easy to have Jenkins know when your script fails.

By the way, there’s also one more useful shell option you might want to know about, -x, which makes shell print every command it executes.

#!/bin/sh -xe   will exit if any command exits with non-zero exit code AND will print every command that is executed

Tuesday 19 February 2013

Get information about Linux partitions

To Display Hard Disk Partition Size in Mega bytes or GB or TB:
$ df -H

To list all block devices, run:
# lsblk


NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    1   558G  0 disk
├─sda1   8:1    1   307M  0 part /boot
├─sda2   8:2    1   250G  0 part /webroot
├─sda3   8:3    1     6G  0 part [SWAP]
├─sda4   8:4    1     1K  0 part
└─sda5   8:5    1 301.7G  0 part /
sr0     11:0    1  1024M  0 rom



To determine the file system type or to find out what type of file systems currently mounted:

$ df -T

df command report filesystem disk space usage and if you pass -T option it will report filesystem type.

 $ mount

/dev/hdb1 on / type ext3 (rw,errors=remount-ro)
/dev/hdb2 on /home type ext3 (rw,errors=remount-ro)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
usbfs on /proc/bus/usb type usbfs (rw)
automount(pid3558) on /data type autofs (rw,fd=4,pgrp=3558,minproto=2,maxproto=4)
 
As you can see, second last column displays the file system type. For example first line [/dev/hdb1 on / type ext3 (rw,errors=remount-ro)] can be interpreted as follows:
  • /dev/hdb1 : Partition
  • / : File system
  • ext3 : File system type
  • (rw,errors=remount-ro) : Mount options
  
 
fdisk -l
Disk /dev/sda: 251.1 GB, 251059544064 bytes
255 heads, 63 sectors/track, 30522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0008fcd3
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          14      104448   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              14       13068   104857600   83  Linux
/dev/sda3           13068       13198     1048576   82  Linux swap / Solaris
/dev/sda4           13198       30523   139163648    5  Extended
/dev/sda5           13198       30523   139162624   83  Linux
 the star on /dev/sda1 shows that this is the bootable partition

fdisk -l | grep Disk

fdisk device   {fdisk /dev/sda1}
  
cfdisk 
 - DOS-based utility to manupulate partitions 


sfdisk -l /dev/sda

Syncronize system time on RedHat linux

Verify Network Time Protocol is installed and working:
 
$ pgrep  ntpd
 

To sync with the time server: 
as ROOT
$ /etc/init.d/ntpd stop
 
$ /etc/init.d/ntpd start 

OR

$ /etc/init.d/ntpd restart
 
 
System - Date and Time - Network time should contain your time server. 

Check SVN connection

Simply issue svn log and see if it fails.

Monday 18 February 2013

Download file to a specific location using WGET

WGET is unix command used to download file.
To download a file on specific location:


wget  -P  "C:\Users\me\Desktop"  http://address/of/file.doc

-P prefix
--directory-prefix=prefix
           Set directory prefix to prefix.  The directory prefix is the
           directory where all other files and sub-directories will be
           saved to, i.e. the top of the retrieval tree.  The default
           is . (the current directory).

Friday 15 February 2013

How to run minimized batch file as a scheduled task

In Windows, Task scheduler, Properties of the task, Actions tab, edit the task by adding:

%comspec% /c start /min 

in front of the path to the script, in the field "Program/Script" where you would browse to the script on your system, for example

%comspec% /c start /min "C:\path\to\my\batchfile.bat"

%comspec% is an environment variable that points to the location of the cmd.exe on your system.

Clicking OK will invoke dialog to ask if you if you ment all this to be parameters or not. Answer NO and the task will be saved as you would expect.
 Then, add

exit

at the end of the batch file that you want to run with minimized with Task scheduler.


That's all.