Showing posts with label Tips. Show all posts
Showing posts with label Tips. 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. 



Thursday, August 27, 2009

Tip of the Day : Software - Free IMAP/SMTP/POP3 Solution For Windows

Today, my colleague asked me for an e-mail solution that we can use for a demo that includes SCOM notification functionality. As we don't have Exchange server for the demo, I googled and found the below solution :

http://www.hmailserver.com


The software is open-source and free. The setup is pretty straight forward. Just couple of Next's and Finishes. You can use SQL Compact, MYSQL or MSSQL as the back-end DB. The configuration is also very easy. Just setup your domain and accounts then you are ready to go.

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.

Tip of the day : Networking - How to Find the Files to Backed Up in an UCS Archive on F5 Big IP LTM Load Balancer

Apart from the articles I decided to publish small tips on my website. Sometimes those kind of tips can be more useful then big documents. Todays tip is based on the F5 Big IP LTM Load Balancer. One of my favorite network device :) I used this command on 9.x should also be working on 10.

Files to be included inside UCS :
grep save.*.file /usr/libdata/configsync/cs.dat
Directories to be included inside UCS :
grep save.*.dir /usr/libdata/configsync/cs.dat
Excluded files from UCS :
grep save.*.ignore /usr/libdata/configsync/cs.dat
For more details check the F5 article on : https://support.f5.com/kb/en-us/solutions/public/4000/400/sol4422.html

Wednesday, August 19, 2009

Putting Digg Icon on your Blogger.com/Blogspot.com Posts

Under Layout->Edit Templates click Expand Widget Templates and replace the below code :



 <div class='post-header-line-1'/>
with this :

 <div class='post-header-line-1'>
<div style='float:right; margin-left:10px;'>
<script type='text/javascript'>
digg_url = '<data:post.url/>';
</script>
<script src='http://digg.com/tools/diggthis.js'
type='text/javascript'>
</script>
</div>
</div>
and Save Template