Showing posts with label Redhat Linux. Show all posts
Showing posts with label Redhat Linux. Show all posts

Tuesday, 12 August 2014

what is a defunct process

A process marked <defunct> is partly dead, waiting to be fully destroyed by its parent.
Sometimes the process args will be unavailable; when this happens, ps will instead print the executable name in brackets.


Thursday, 7 August 2014

force uninstall an rpm package

How to uninstall an rpm package forcefully if the respective  package installed locations are deleted by mistake?

rpm -e  httpd  --nodeps --noscripts 

reference: http://www.linuxquestions.org/questions/linux-general-1/force-uninstall-by-rpm-103840/

Wednesday, 8 May 2013

Unix/Linux Tips and Tricks



Trick 1: Unmounting the unresponsive DVD drive
The newbie states that when he pushes the Eject button on the DVD drive of a server running a certain Redmond-based operating system, it will eject immediately. He then complains that, in most enterprise Linux servers, if a process is running in that directory, then the ejection won't happen. For too long as a Linux administrator, I would reboot the machine and get my disk on the bounce if I couldn't figure out what was running and why it wouldn't release the DVD drive. But this is ineffective.
Here's how you find the process that holds your DVD drive and eject it to your heart's content: First, simulate it. Stick a disk in your DVD drive, open up a terminal, and mount the DVD drive:
# mount /media/cdrom
# cd /media/cdrom
# while [ 1 ]; do echo "All your drives are belong to us!"; sleep 30; done

Now open up a second terminal and try to eject the DVD drive:
# eject
You'll get a message like:
umount: /media/cdrom: device is busy
Before you free it, let's find out who is using it.
# fuser /media/cdrom
You see the process was running and, indeed, it is our fault we can not eject the disk.
Now, if you are root, you can exercise your godlike powers and kill processes:
# fuser -k /media/cdrom
Boom! Just like that, freedom. Now solemnly unmount the drive:
# eject
fuser is good.

Trick 2: Getting your screen back when it's hosed
Try this:
# cat /bin/cat
Behold! Your terminal looks like garbage. Everything you type looks like you're looking into the Matrix. What do you do?
You type reset. But wait you say, typing reset is too close to typing reboot or shutdown. Your palms start to sweat—especially if you are doing this on a production machine.
Rest assured: You can do it with the confidence that no machine will be rebooted. Go ahead, do it:
# reset
Now your screen is back to normal. This is much better than closing the window and then logging in again, especially if you just went through five machines to SSH to this machine.
David, the high-maintenance user from product engineering, calls: "I need you to help me understand why I can't compile supercode.c on these new machines you deployed."
"Fine," you say. "What machine are you on?"
David responds: " Posh." (Yes, this fictional company has named its five production servers in honor of the Spice Girls.) OK, you say. You exercise your godlike root powers and on another machine become David:
# su - david
Then you go over to posh:
# ssh posh
Once you are there, you run:
# screen -S foo
Then you holler at David:
"Hey David, run the following command on your terminal: # screen -x foo."
This will cause your and David's sessions to be joined together in the holy Linux shell. You can type or he can type, but you'll both see what the other is doing. This saves you from walking to the other floor and lets you both have equal control. The benefit is that David can watch your troubleshooting skills and see exactly how you solve problems.
At last you both see what the problem is: David's compile script hard-coded an old directory that does not exist on this new server. You mount it, recompile, solve the problem, and David goes back to work. You then go back to whatever lazy activity you were doing before.
The one caveat to this trick is that you both need to be logged in as the same user. Other cool things you can do with the screen command include having multiple windows and split screens. Read the man pages for more on that.
But I'll give you one last tip while you're in your screen session. To detach from it and leave it open, type: Ctrl-A D . (I mean, hold down the Ctrl key and strike the A key. Then push the D key.)
You can then reattach by running the screen -x foo command again.

Trick 4: Getting back the root password
You forgot your root password. Nice work. Now you'll just have to reinstall the entire machine. Sadly enough, I've seen more than a few people do this. But it's surprisingly easy to get on the machine and change the password. This doesn't work in all cases (like if you made a GRUB password and forgot that too), but here's how you do it in a normal case with a Cent OS Linux example.
First reboot the system. When it reboots you'll come to the GRUB screen. Move the arrow key so that you stay on this screen instead of proceeding all the way to a normal boot.
Next, select the kernel that will boot with the arrow keys, and type E to edit the kernel line.
Use the arrow key again to highlight the line that begins with kernel, and press E to edit the kernel parameters. When you get to the screen , simply append the number 1 to the arguments .
Then press Enter, B, and the kernel will boot up to single-user mode. Once here you can run the passwd command, changing password for user root:
sh-3.00# passwd
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully

Now you can reboot, and the machine will boot up with your new password.

Trick 5: SSH back door
Many times I'll be at a site where I need remote support from someone who is blocked on the outside by a company firewall. Few people realize that if you can get out to the world through a firewall, then it is relatively easy to open a hole so that the world can come into you.
In its crudest form, this is called "poking a hole in the firewall." I'll call it an SSH back door. To use it, you'll need a machine on the Internet that you can use as an intermediary.
In our example, we'll call our machine blackbox.example.com. The machine behind the company firewall is called ginger. Finally, the machine that technical support is on will be called tech.
Here's how to proceed:
  1. Check that what you're doing is allowed, but make sure you ask the right people. Most people will cringe that you're opening the firewall, but what they don't understand is that it is completely encrypted. Furthermore, someone would need to hack your outside machine before getting into your company. Instead, you may belong to the school of "ask-for-forgiveness-instead-of-permission." Either way, use your judgment and don't blame me if this doesn't go your way.
  2. SSH from ginger to blackbox.example.com with the -R flag. I'll assume that you're the root user on ginger and that tech will need the root user ID to help you with the system. With the -R flag, you'll forward instructions of port 2222 on blackbox to port 22 on ginger. This is how you set up an SSH tunnel. Note that only SSH traffic can come into ginger: You're not putting ginger out on the Internet naked.
You can do this with the following syntax:
~# ssh -R 2222:localhost:22 thedude@blackbox.example.com
Once you are into blackbox, you just need to stay logged in. I usually enter a command like:
thedude@blackbox:~$ while [ 1 ]; do date; sleep 300; done
to keep the machine busy. And minimize the window.
  1. Now instruct your friends at tech to SSH as thedude into blackbox without using any special SSH flags. You'll have to give them your password:
root@tech:~# ssh thedude@blackbox.example.com .
  1. Once tech is on the blackbox, they can SSH to ginger using the following command:
thedude@blackbox:~$: ssh -p 2222 root@localhost
  1. Tech will then be prompted for a password. They should enter the root password of ginger.
  2. Now you and support from tech can work together and solve the problem. You may even want to use screen together!

Friday, 23 November 2012

zip command in linux

The following examples illustrate typical uses of the command zip for packaging a set of files into an "archive" file, also called "zip file". The command uses the standard zip file format. The archive files can therefore be used to tranfer files and directories between commonly used operating systems.
zip archivefile1 doc1 doc2 doc3
This command creates a file "archivefile1.zip" which contains a copy of the files doc1, doc2, and doc3, located in the current directory.

zip archivefile1 *
This command creates a file "archivefile1.zip" which contains a copy of all files in the current directory in compressed form. However, files whose name starts with a "." are not included. The extension ".zip" is added by the program.

zip archivefile1 .* *
This version includes the files that start with a dot. But subdirectories are still not included.

zip -r archivefile1 .
This copies the current directory, including all subdirectories into the archive file.

zip -r archivefile2 papers
This copies the directory "papers", located in the current directory, into "archivefile2.zip".

zip -r archivefile3 /home/joe/papers
This copies the directory "/home/joe/papers" into "archivefile3.zip". Since in this case the absolute path is given, it doesn't matter what the current directory is, except that the zip file will be created there.
The command unzip extracts the files from the zip file.
unzip archivefile1.zip 

This writes the files extracted from "archivefile1.zip" to the current directory. 

Thanks to all Linux related Websites.

Tuesday, 6 November 2012

Install RPM, ingore dependencies and scriptlets



Installation of RPM files without checking for any dependency and without executing package scriptlets.

Syntax    :   rpm -ivh  --nodeps --noscripts <rpm_name>
Example:    rpm -ivh --nodeps --noscripts   ux-core-12.1.0.3.0-20120906.x86_64.rpm


Monday, 5 November 2012

Re register Linux Server System with RHN

Re register Linux Server System with RHN ( Red Hat Network )

Q. 
After re-installing my HP server system, RHN is not working. How do I re-register my system with Red Hat Network (RHN) again?

A.

This is known issue and it can be easily fix after reinstalling system. All you have to do is login to RHN web management online.
a) Look for Systems tab in
b) Select the name of the old system in the System List.
c) Now delete it by clicking on the delete system link
d) Confirm the removal
e) Login to your system and delete /etc/sysconfig/rhn/systemid file using rm command, enter:
# rm /etc/sysconfig/rhn/systemid

f) Now register box with the update agent using rhn_register, enter:
# rhn_register
rhn_register is a client program that registers your system with Red Hat Network (or a Red Hat Network Satellite). After registering, your system can recieve software updates, install new software, and remotely manage your system. It can run both in graphical and text modes.

Steps to Configure Yum to access RHN

Make sure you have backup in /var/ftp/pub


Create a file
#vim /etc/yum.repos.d/local.repo
[local.repo]
name=my repo
baseurl=file:///var/ftp/pub/Server
enabled=1
gpgcheck=0

:wq! save and exit

open a file
#vim /etc/yum.conf
make sure gpgcheck=0

:wq! save and exit

#yum clean all
#yum update all

[Note]
If yum update all show a error it means your rpm repositery is croupted .How to repair it

#cd /var/ftp/pub/Server
#rpm -ivh creatrepo*
#creatrepo -v /var/ftp/pub/Server

Now again run command
#yum clean all
#yum update all

How to install packages via yum ?

eg.= #yum install dhcpd* (for install dhcp pakages)


How to remove packages via yum ?
#yum remove dhcpd

More examples of packges
#yum install postfix*
#yum install sendmail*
#yum install bind*
#yum install kde* (for install kde desktop envirment)


Author of this artical is:- sandeeprhce5

Thursday, 27 September 2012

How to Repair Linux File System?

My ESX VM Linux Server haulted at single user mode ( init 1 ) , after doing a restart as a result of  file system check up failure ( fsck process).

So, how to trouble shoot it?

You will see a black screen with the following information as given below:

"This is the key: the filesystem is corrupted, probably due to an unclean shutdown. It needs to be repaired. Try entering the root password, which should

give you a '#' prompt.
Type: fsck -A -y "

My Approach to it to trouble shoot  File System corruption issue:

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

1.Before executing fsck, unmount all filesystems to make sure  that  no disk i/o happens.Then do fsck, then remount or just say "init 6".
2.Tips on mounting:
a.mount -o rw /  to freshly mount a disk onto / with read and write permissions to  root filesystem.
b.mount -o remount,rw  /  to  unmount,remount the disk onto / with read adn write permissions to root user or system admin.

RHEL6.2X64_Shalni: Disk name :  /dev/sda1:

So, user command :  e2fsck -f /dev/sda1  is  ok

Is shalini's machine having /dev/sda3. let me check:

e2fsck -f /dev/sda3


Reference :

So how the hell you are gonna Surviving a Filesystem Failures? Most of time fsck (front end to ext2/ext3 utility) can fix the problem, first simply run

e2fsck - to check a Linux ext2/ext3 file system (assuming /home [/dev/sda3 partition] filesystem for demo purpose), first unmount /dev/sda3 then type

following command :
# e2fsck -f /dev/sda3
Where,

    -f : Force checking even if the file system seems clean.

Please note that If the superblock is not found, e2fsck will terminate with a fatal error. However Linux maintains multiple redundant copies of the

superblock in every file system, so you can use -b {alternative-superblock} option to get rid of this problem. The location of the backup superblock is

dependent on the filesystem's blocksize:

    For filesystems with 1k blocksizes, a backup superblock can be found at block 8193
    For filesystems with 2k blocksizes, at block 16384
    For 4k blocksizes, at block 32768.

Tip you can also try any one of the following command(s) to determine alternative-superblock locations:
# mke2fs -n /dev/sda3
OR
# dumpe2fs /dev/sda3|grep -i superblock
To repair file system by alternative-superblock use command as follows:
# e2fsck -f -b 8193 /dev/sda3

However it is highly recommended that you make backup before you run fsck command on system, use dd command to create a backup (provided that you have spare

space under /disk2)
# dd if=/dev/sda2 of=/disk2/backup-sda2.img

Links:
http://www.cyberciti.biz/tips/surviving-a-linux-filesystem-failures.html
http://www.cyberciti.biz/tips/understanding-unixlinux-filesystem-superblock.html


First of all, list all the super blocks of /dev/sda1:

Following command displays primary and backup superblock location on /dev/sda3:
# dumpe2fs /dev/sda1 | grep -i superblock

Learned that, backup superblock is at 8193,24577,40961,57345,73729,204801,221185,401489:

So, let me try with alternative superblock to recognize the filesystem which ext3 written on /dev/sda1:

Command to load alternative superblock : e2fsck -f -b 8193 /dev/sda1 -  Linux

File system is fixed now on inodes,userdata,file metadata etc..


Big problem that confused me:
Now, On VMWare Linux :  how to repair /dev/mapper/VolGroup-lv_root :
check for all mount points using cat /proc/mounts


Steps I followed from Murthy Sir:

1.In single user mode # vi /etc/fstab
2.Renamed 1 2 flags  to 0 0  for logical volume which mounted on /.This tells init to ignore "FileSystem Check and FileSystem Backup".
3.use # sync  command  to flush the buffers to hard disk.
4.Then reboot using, init 6  command.
5.If it ignores Filesystem checks and comes up, it is ok to work.
6.After Linux comes up, Again check whether all filesystems are ok leaving /.
7.How to check?
8.Again vi /etc/fstab,change  0  0  to  1  2 for  /dev/mapper/VolGroup-lv_root.
9.do  sync
10.init 6

Now, your linux ios ready for working in runlevel 5.
++++++++++++++++++++++++++++++++++++++++++++++++++++

While checking hostname on linux:
1.Make sure that /etc/hosts will have last  entry of IP as the latest entry.
<IP> <FQDN> <HostName>.

2.vi /etc/sysconfig/network.
Makure Sure,
NETWORK=yes
HOSTNAME=RHEL62X64

3."Sync"
4.init 6 -> reboots to runlevel 5.

++++++++++++++++++++++++++++++++++++++++++++++++++++


++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Linux: Convert File Types ( MIME)

Working on difference between .txt files :

vimdiff     httpserver_directory.txt Entire_productsxml.txt       

Commands used for Comparision:

1.vimdiff     httpserver_directory.txt  Entire_productsxml.txt   

 not  working as  MIME types are different. One is xml  and the other is text file.

2.I needed  iconv  command here  to conver the MIME types   from  text/xml   to ascii/xml
a. Do these files have  same character sets?

No.
Hint from google: http://www.google.co.in/url?sa=t&rct=j&q=iconv%3A%20conversion%20from%20%60text%2Fxml%27%20and%20to%20%60text%2Fplain%27%20are%20not%20supported%20%3F&source=web&cd=6&cad=rja&ved=0CEEQFjAF&url=http%3A%2F%2Funix.stackexchange.com%2Fquestions%2F11602%2Fhow-can-i-test-the-encoding-of-a-text-file-is-it-valid-and-what-is-it&ei=xvRjUK3_LoqHrAeD6IHYAQ&usg=AFQjCNELrZ1L4ptxCXQckmAXG67VBHdboQ
 file1: text/plain; charset=utf-8 file2: text/plain; charset=iso-8859-1

b.First see the character sets  of each file :
Command :

file -i *

 [root@blr-elorhel4x86 ndtrack]# file -i *

Entire_productsxml.txt:   text/plain; charset=us-ascii

Entire_productsxml.txt:   application/x-empty

httpserver_directory.txt:

httpsever_ouionly.txt:    text/plain; charset=us-ascii

ndtrack.ini:              text/plain; charset=utf-8

ndtrack.sh:               application/x-shellscript

run.sh:                   application/x-shellscript

c.To convert from one  format  to other format:
Command: I will use it later, because I need to  some   text parsing.

iconv -f FROM-ENCODING -t TO-ENCODING file.txt

d.How  am I doing text parsing?

I am using perl  command line to wipe off beginning spaces in the line to act on to file:

Re-learn : perl -nle '$_ =~ s/^(\w+)$/$&/g ; print  $_' Entire_productsxml.txt   

Beginning spaces in the line are not replaced. Simple, but I need to remember it.



Wednesday, 19 September 2012

Linux:cpio command



You may encounter  .cpio file as  the installer file for many of the oracle products.

This is the command to   extract that file:

1.First,  list  the contents of the file without extracting.

cpio  -itv  < rtd_2.2.1.1_OC4J_unix.cpio

2.Second, extract  .cpio file into a clean directory  to  see the files, you have extracted.

cpio -idmv < rtd_2.2.1.1_OC4J_unix.cpio


Make it a practice , while extracting  any cpio file.

Monday, 17 September 2012

RHEL: How to check the Linux distribution Information

Here is the command to check the Linux Standard base distribution.

The following command will list the LSB Profiles which are currently supported on this platform.

example$ lsb_release -v
LSB Version: core-3.0-ia32:core-3.0-noarch:graphics-3.0-ia32:graphics-3.0-noarch
 
Reference : http://refspecs.linuxbase.org/LSB_3.1.1/LSB-Core-generic/LSB-Core-generic/lsbrelease.html  

Friday, 8 June 2012

What is a zombie process?




On Unix and Unix-like computer operating systems, a zombie process or defunct process is a process that has completed execution but still has an entry in the process table.
When a process finishes execution, it will have an exit status to report to its parent process. Because of this last little bit of information, the process will remain in the operating system’s process table as a zombie process, indicating that it is not to be scheduled for further execution, but that it cannot be completely removed (and its process ID cannot be reused) until it has been determined that the exit status is no longer needed.
When a child exits, the parent process will receive a SIGCHLD signal to indicate that one of its children has finished executing; the parent process will typically call the wait() system call at this point. That call will provide the parent with the child’s exit status, and will cause the child to be reaped, or removed from the process table.
It’s possible that the parent process is intentionally leaving the process in a zombie state to ensure that future children that it may create will not receive the same pid. Or perhaps the parent is occupied, and will reap the child process momentarily.
To remove zombies from a system, the SIGCHLD signal can be sent to the parent manually, using the kill command (“kill -s SIGCHLD <ppid>“). If the parent process still refuses to reap the zombie, the next step would be to remove the parent process. When a process loses its parent, init process (pid 1) becomes its new parent. Init periodically executes the wait system call to reap any zombies with init as parent.

To find zombie process: Use top or ps command

A zombie process is not the same as an orphan process. An orphan process is a process that is still executing, but whose parent has died. They do not become zombie processes; instead, they are adopted by init (process ID 1), which waits on its children.
Zombies can be identified in the output from the Unix ps command by the presence of a "Z" in the "STAT" column. Zombies that exist for more than a short period of time typically indicate a bug in the parent program, or just an uncommon decision to reap children (see example). If the parent program is no longer running, zombie processes typically indicate a bug in the operating system. As with other leaks, the presence of a few zombies is not worrisome in itself, but may indicate a problem that would grow serious under heavier loads. Since there is no memory allocated to zombie processes except for the process table entry itself, the primary concern with many zombies is not running out of memory, but rather running out of process ID numbers.
Tweets by @sriramperumalla