Friday, December 2, 2011

How to mount smb/cifs network share on linux

Make sure you do this as root
Create a directory for mount point 
#mkdir /mnt/smb_share 
#mount -t cifs -o user=test //servernameorIP/share /mnt/smb_share 
It then prompts for your Fileshare password. After successful mounting you can
list the content of the share
#ls /mnt/smb_share 

Monday, July 4, 2011

How to find out Gateway/Router IP address under Linux/Unix

Run route command
route -n


Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface   U     1      0        0 eth0     U     1000   0        0 eth0         UG    0      0        0 eth0 is gateway IP address for the computer. The flag U indicates that route is up and G indicates gateway.

You can also run netstat command to find the gateway.
netstat -nr


Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface   U         0 0          0 eth0     U         0 0          0 eth0         UG        0 0          0 eth0

Tuesday, June 14, 2011

No init found . Try passing init = boot arg

No init found . Try passing init = boot arg . 
Busy Box v1.15.3 (Ubuntu 1:1.15.3-1ubuntu 5)built-in shell (ash) 
Enter 'help' for a list of built-in commands. 

One possible solution: 
1. Boot from the Ubuntu Live CD.
2. Open/Run Terminal.
3. Type: sudo fdisk -l (to get the device name) then press ENTER.
Disk /dev/sda: 250.1 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: **********

Device Boot Start End Blocks Id System
/dev/sda1 * 1 30238 242886703+ 83 Linux
/dev/sda2 30239 30401 1309297+ 5 Extended
/dev/sda5 30239 30401 1309266 82 Linux swap / Solaris

4. Type: sudo fsck /dev/sda1 then press ENTER.
5. Restart the system and boot normally.

Friday, June 3, 2011

How to mount and unmount an ISO image under Solaris

Mount an iso image
You can use lofiadm command to mount ISO image under Solaris.

# lofiadm -a /absolute/path/to/isoimage.iso

Here, /dev/lofi/1 is a device, now you can use the mount command to mount the iso image.

# mount -o ro -F hsfs  /dev/lofi/1   /mnt 

Unmount and detach the image

Use umount command to unmount the image

# umount /mnt

Now remove/free block device

# lofiadm -d /dev/lofi/1

Monday, May 16, 2011

Error: Not on system console, root login rejected


Edit /etc/default/login and comment out the following line.
# CONSOLE=/dev/console
Be very carefull with this for the security implications. That’s all.

Enable XDMCP on solaris 10

Solaris 10’s desktop environment is JDS which is based off of GNOME.
  1. Log in as root
  2. Open a terminal
  3. Type gdmsetup (a dialog box will appear)
  4. Click on the XDMCP tab
  5. Check the Enable XDMCP box
  6. Press Close

Monday, April 18, 2011

service dbora does not support chkconfig

This error occurs while running oracle database auto start script.
chkconfig --level 345 dbora on
service dbora does not support chkconfig.

Edit the dbora script. There is a typo in chkconfig: -20 80. It has a space in front of 20. e.g;

chkconfig: - 20 80

Now you can use the command 
chkconfig --level 345 dbora on

Friday, March 4, 2011

DRHD: handling fault status regf0003c80 Kernel panic -not syncing : DMAR hardware

  • Power on the system and press tab at boot menu
  • Pass boot parameter to the kernel
  • boot the system
  • After booting successufully, edit grub.conf for permanent setting.

"Reverse Mapping Checking: Possible Break-in Attempt!" Error with SSH

The reverse DNS had not been set up for the server.

Add remote host to your /etc/hosts file.

Gtk-warnning ** : can not open display or ** WARNING ** can not open display

The problem is with two environment variables DISPLAY and XAUTHORITY

$ su -


# export DISPLAY=0:0

# export XAUTHORITY=/home/username/.Xauthority

to verify, run a graphical program from terminal. e.g.;

# xeyes

Friday, January 7, 2011

How to change MAC address of a network interface in Linux

Type the following commands with sudo prefix or under superuser/root:

ifconfig eth0 down
ifconfig eth0 hw ether 00:24:21:3e:05:ee 

ifconfig eth0 up 

eth0 – is hardware name of your first network interface.
00:24:21:3e:05:ee is new MAC address you’d like to apply to the NIC.

These commands should be added into startup scripts if you require them to appear after Linux system reboots.

Thursday, January 6, 2011

ls command

List information about the FILEs (the current directory by default).

ls [OPTION]... [FILE]... 
-a    Shows you all files, even files that are hidden (these files begin with a . dot.)
-A    List all files including the hidden files. However, does not display the working directory (.) or the parent directory (..).
-b    Force printing of non-printable characters to be in octal \ddd notation.
-c    Use time of last modification of the i-node (file created, mode changed, and so forth) for sorting (-t) or printing (-l or -n).
-C    Multi-column output with entries sorted down the columns. Generally this is the default option.
-d    If an argument is a directory it only lists its name not its contents.
-f   Force each argument to be interpreted as a directory and list the name found in each slot. This option turns off -l, -t, -s, and -r, and turns on -a; the order is the order in which entries appear in the directory.
-F    Mark directories with a trailing slash (/), doors with a trailing greater-than sign (>), executable files with a trailing asterisk (*), FIFOs with a trailing vertical bar (|), symbolic links with a trailing at-sign (@), and AF_Unix address family sockets with a trailing equals sign (=).
-g    Same as -l except the owner is not printed.
-h     print sizes in human readable format. (e.g., 1K, 234M, 2G, etc.)
-i    For each file, print the i-node number in the first column of the report.
-l    long listing of a file or a directory contents (permissions, owners, size, and when last modified.)
-L    If an argument is a symbolic link, list the file or directory the link references rather than the link itself.
-m    Stream output format; files are listed across the page, separated by commas.
-n    The same as -l, except that the owner's UID and group's GID numbers are printed, rather than the associated character strings.
-o    The same as -l, except that the group is not printed.
-p    Displays a slash ( / ) in front of all directories.
-q    Force printing of non-printable characters in file names as the character question mark (?).
-r    Reverses the order of how the files are displayed.
-R    Includes the contents of subdirectories.
-s    Give size in blocks, including indirect blocks, for each entry.
-S   Sort by file size
-t    Shows you the files in modification time.
-u    Use time of last access instead of last modification for sorting (with the -t option) or printing (with the -l option).
-x    Displays files in columns.
-Z  Print any SELinux security context of each file
-1   Print one entry per line of output.
pathnames    File or directory to list.


ls -l
-rw-r----- 1 lalit admin 7277202 Jan 06 14:29 go2linuxworld.txt
1st CharacterFile Type: First character specifies the type of the file. 
In the example above the hyphen (-) in the 1st character indicates that this is a normal file. Following are the possible file type options in the 1st character of the ls -l output.
          - normal file
          d directory
          s socket file
          l link file 
Field 1 – File Permissions: Next 9 character specifies the files permission. Each 3 characters refers to the read, write, execute permissions for user, group and world In this example, -rw-r—– indicates read-write permission for user, read permission for group, and no permission for others.
Field 2 – Number of links: Second field specifies the number of links for that file. In this example, 1 indicates only one link to this file. 
Field 3 – Owner: Third field specifies owner of the file. In this example, this file is owned by username ‘lalit’.
Field 4 – Group: Fourth field specifies the group of the file. In this example, this file belongs to 'admin’ group.
Field 5 – Size: Fifth field specifies the size of file. In this example, ’7277202′ indicates the file size.
Field 6 – Last modified date & time: Sixth field specifies the date and time of the last modification of the file. In this example, ‘Jan 06 14:29′ specifies the last modification time of the file.
Field 7 – File name: The last field is the name of the file. In this example, the file name is go2linuxworld.txt

ls ~
List the contents of your home directory by adding a tilde after the ls command.

ls /
List the contents of your root directory.

ls ../
List the contents of the parent directory.

ls */
List the contents of all sub directories.

ls -d */

Only list the directories in the current directory.

Wednesday, January 5, 2011

Editing files with the vi editor : An Introduction

The vi program is a text editor that you can use to edit any text and particularly programs.The following are some of the important keystroke commands to get around in vi.

Adding Text in vi
i       Notifies vi to insert text before the cursor
I       Insert text at the beginning of the current line
a       Notifies vi to append text after the cursor
A       Add text to the end of the current line.
o       Open a new line below the current line and add text
O       Open a new line above the current line and add text
s       Substitute the letter underneath the cursor with letter you type, and insert text
S or c   Delete the current line and substitute it with text you type
R or C   Replace current text with text you type

Cutting and Pasting Text in vi
D        Delete from the cursor to the end of the line
dd      Notifies vi to delete the current line
#dd    Delete the following number of lines, including the current line (where # is a number)
yy      yank (i.e. copy) one line into a general buffer
#yy   Copy or "yank" the following number of lines, including the current line (where # is a number)
x        Notifies vi to delete the current character
dw      Delete the letter beneath the cursor and the rest of the word
#dw    Delete the following number of words, including the current word (where # is a number)
p        Paste data that was cut with x or dd commands or copy with yy command
J        Join the next line with the current line (erases a carriage return)
u        Notifies vi to undo the last command
      Redo the last editing command

Moving Around in a vi Text File
Ctrl+f   Scroll up one page
Ctrl+b    Scroll down one page
/string  Search forward for string

Saving or Quitting vi
:q     Quit editor
:q!   Quit editor without saving changes
:w    Save the current file without quitting
:wq    Save changes and exit editor

:f    Display filename and current line number
Esc  Notifies vi to end the insert or append mode

How to list or find the largest files, directories and Free disk space

♦ Find biggest top 10 directories in your disk

du -hs */ | sort -nr | head

♦ Find the biggest files inside directories

ls -lhS | head

♦ Find biggest files in any directory recursively

We’ll now use find, to find only files, and then sort, to have only the biggest files listed.

find -type f -ls | sort -k 7 -r -n | head -5

find helps us list only files and not directories, then sort using the column 7 (the column with the file size) we sort using -n numeric order and -r reverse order (from biggest to smallest), and finally only the first 5 files in the current directory, and sub-directory.

You can use this way

find / -type f -ls | sort -k 7 -r -n | head -5
And that will work, for all disk from root. 

du Summarize disk usage of each FILE, recursively for directories.
sort Write sorted concatenation of all FILE(s) to standard output.
head Print the first 10 lines of each FILE to standard output. With more than one FILE, precede each with a header giving the file name. With no FILE, or when FILE is -, read standard input.


Tuesday, January 4, 2011

How to find the largest file in a directory

The best way is to use ls, sorted by size and to get the biggest one, use head

ls -S | head -1

How to count how many processes each user is running in Linux

There are lots of ways to do this, we can use pipes here.

ps hax -o user | sort | uniq -c

ps will list the processes
h will remove the header
-o user prints only the user column
sort sorts in alphabetical order
uniq command can eliminate or count duplicate lines in a presorted file.