Showing posts with label UNIX. Show all posts
Showing posts with label UNIX. Show all posts

Tuesday, December 1, 2009

How to see the path of a process that's listening on specific port

From time to time you can have multiple instances of Apache installed on your server. As ps aux only shows the entire path, if you started the process using full path convention; you need to check /proc presudo file system to gather path information for the process. I generally use the below one liner to fetch this info :

[root@VM1 bin]# ls -altr /proc/`netstat -natp | grep 80 |  awk '{print $7}' | awk -F/ '{print $1}'`/exe
lrwxrwxrwx 1 root root 0 Nov 30 13:03 /proc/25316/exe -> /apache_test/bin/httpd

It uses netstat to gather process ID for specific port (also lsof can be used) then checks the /proc/$PROCESS_ID/exe soft link to see where the process resides. 



Sunday, August 23, 2009

Tip of the Day : SSHD - How to connect a server using SSH and without entering login credentials

From time to time you will need to connect your servers remotely and execute commands there using scheduled jobs. As the nature of these scheduled jobs/scripts, they have no capability of user interaction like entering user/pass information. (I'm talking about simple shell scripts, you can also use Perl's use Net::SSH::Perl for entering user/pass info) For these scenarios we have the below trick of generating RSA/DSA key pairs and putting it into the authorized_keys file:
[root@server-a ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):   --- leave empty
Enter same passphrase again:   --- leave empty

Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.

The key fingerprint is:
35:ee:f1:53:f6:d7:85:4b:65:c3:68:f0:b6:59:f5:50 root@server-a

[root@server-a ~]# scp .ssh/id_dsa.pub server-b:/root/.ssh/id_dsa_lr.pub

[root@server-b ~]# cd /root/.ssh/
[root@server-b ~]# cat id_dsa_lr.pub >> authorized_keys
[root@servera ~]# ssh server-b

Last login: Mon Sep  3 12:29:09 2007 from X.X.X.X

[root@server-b ~]#
This example gives server-a the ability of connecting server-b via SSH and without entering any user/pass information.
NOTE : You can also use this trick to connect your Windows boxes using Cygwin SSHD. I will give details on Cygwin on a future article.

Friday, August 21, 2009

Tip of the day : Linux - Output a specific line

head -150 file_name.txt | tail -1
Shows the 150th line inside the file

Thursday, August 20, 2009

Tip of the day : Linux - How to keep commands running in the background after logging out

Yes I know this is the 2nd tip of the day but this one is simple. Today a colleague of mine come to me with this scenario :
I'm starting a ping on console. Then I'm exiting console, and would like to return my ping session. How can I do this ?
Normally in order to send a command to background and redirect STDOUT & STDERR to a logfile we use :
ping localhost >> /var/log/neco.test 2>&1 &
[2] 27783
Even if you send a process to the background when you logout/exit from a shell session Linux shell sends a HUP signal and kills that process. So we need to detach this process from shell. At this point the command nohup helps us. nohup detach the process from shell and attach to initd which is the mother process of all :) So we modify our command as below to reach our target :
nohup ping localhost >> /var/log/neco.test 2>&1 &
[1] 27786
After this command we can exit the shell and check the status of the STDOUT from the log file :
tail -f /var/log/neco.test
64 bytes from necoPC (127.0.0.1): icmp_seq=105 ttl=64 time=0.023 ms
64 bytes from necoPC (127.0.0.1): icmp_seq=106 ttl=64 time=0.022 ms
64 bytes from necoPC (127.0.0.1): icmp_seq=107 ttl=64 time=0.019 ms
In order to kill the process we need to use kill command with process id.

Tuesday, August 18, 2009

RHCE – Day 1

Before starting this series, I want to tell you a boring story about myself. The story begins at 2000 when I was a high school student making web design/programming to earn my pocket money:) These days I recognised a web page called Brainbench which makes online exams for certification. I passed their exam to get ceritified for HTML 4.0

From that point on, I really understood the necessity of certification because the preparation process gives you much more then the paper you earn at the end. After that, my next step was MCSE 2000. I remember that I was studying the exam on my Intel Pentium 133 running Win2k like a turtle. The preparation phase was funny but in the end as an high school student I didn’t have enough money to pay for the exam fees, so unfortunately I didn’t have a chance to be MCSE at that age :(

And then comes the collage years. This time I have a new target : Networking and Cisco Certifications. And now I have enough money coming from the scholarships ;-) After 3 years of self paced and computer based preparation and with the help of Boson Netsim and Dynamips I passed all the exams (In total 5) that are necessary for CCNA & CCNP + 1 for CCIP (QoS Exam)

After graduating from school I applied a job in a big telco vendor. They were so suprised to see a new graduate with CCNA, CCNP.  As there were a lot of paper certified people around, they want to verify this. After a very long technical interview they got convinced and hired me. 

Certification has great importance in my life. I found certification as a great tool to advance expertise about technical areas. Currently I have IWA HTML 4.0, CCNA, CCNP, CCIP, MCTS Windows Server 2008 Active Directory: Configuration, MCTS Windows Server 2008 Network Infrastructure: Configuration, MCTS Windows Server Virtualization Hyper-V and MCITP : Windows 2008 Server Admin. All of these certification tacks helped me build knowledge on varios technologies in a very proper way. But will I stop ? Of course not :) Next step is RHCE (RedHat Certified Engineer)

Why RHCE ?

- As a network and system admin the middleware I was working on is mostly UNIX based (Redhat, Solaris, Secureplatform etc..) I have enough hands on and expertise but I don’t have a real proof.
- My interview with Google reminded me the importance of Linux again.
- RHCE is lab based not one of these paper certifications.
- One of the most recognised certification by the industry.

Enough pep talk let’s begin. First the preparation materials :

1. RHEL 5 Unleashed by Tommy Fox
2. RHCE Red Hat Certified Engineer Linux Study Guide (Exam RH302), Fifth Edition byMichael Jang 
3. Slides from RH033, RH133, RH253 Classes

and the tools :

1. VmWare Workstation/Server for my laptop prep.
2. Vmware ESXi for the lab. (maybe also Hyper-V with RH Integration tools)

and of course RHEL5 iso from RHN and a new wallpaper for motivation :D

http://spinix.deviantart.com/art/LINUX-CCCP-84492543

Installation Methods

CD/DVD-ROM :
Classical method for installing
Hard Disk : Requires an HD partition(xt2/3,vfat) accessible by the installer.
Network Install : NFS, FTP or HTTP based using PXE/Boot.iso
Kickstart : Unattended method of installation

NOTE : Boot.iso file can be located under RHELInstall CD1 / DVD ./images folder. 

In order to choose for an installation method use “linux askmethod” at the boot prompt

  image

image 

image 

image 

Install Phases :

- Select Language
- Select Keyboard Layout
- Installation number. (This allows us to use additional components like virtualization)
- Partition layout and RAID

IMPORTANT NOTE : If /boot or /boot/efi is a RAID. It must be RAID1.

- GRUB (Boot loader) config
- Network Config
- Packages to be installed

After Install those 2 files are created :

1. /root/install.log   --   Install Log File
2. /root/anaconda-ks.cfg   --   Sample Kickstart File based on the parameters used during the installation. I will examine this file in a future session.

Yes I know this was a less technical more personal session but next days  I will enrich the content and add more notes about my preparation track. Hope to see you in the next part of the RHCE series.