Saturday, October 16, 2010

windows: which processes have loaded xyz.dll?

Example: find all processes that have loaded msvcrt.dll:
C:\Users\ambars>tasklist /m /fi "modules eq msvcrt.dll"


Image Name                     PID Modules                                     
========================= ======== ============================================
csrss.exe                      748 ntdll.dll, CSRSRV.dll, basesrv.DLL,         
                                   USP10.dll, msvcrt.dll, sxssrv.DLL, sxs.dll, 
                                   RPCRT4.dll, CRYPTBASE.dll                   

wininit.exe                    800 ntdll.dll, kernel32.dll, KERNELBASE.dll,    
                                   USER32.dll, GDI32.dll, LPK.dll, USP10.dll,  
                                   msvcrt.dll, RPCRT4.dll, sechost.dll,        
                    
csrss.exe                      808 ntdll.dll, CSRSRV.dll, basesrv.DLL,              
                                   USP10.dll, msvcrt.dll, sxssrv.DLL, sxs.dll, 
                                   RPCRT4.dll, CRYPTBASE.dll  
[SNIP/]

Thursday, October 14, 2010

vim: how to record and replay macros

To record a macro:
  1. Start recording: press ‘q’
  2. Choose a macro register: press ‘a’ to select ‘a’ as a location to save the macro to. You will see “recording” at the bottom left of the vim window.
  3. Perform editing actions: for example, suppose you want to delete any line containing the string, “Stage:” You can do this by pressing:
    Esc
    /Stage:
    dd
    

  4. Stop recording: press ‘q’
To replay a macro:
  1. Choose a macro register: In our case, we want the macro we just saved to register ‘a’.
  2. Repeat the saved macro: by pressing “@[register_name]” which in our case is:
    @a

  3. Multiple-repeat: press “[count]@[register_name]”, for example:
    8@a

linux: which process is listening on port X?

Discovered a new tool, ss, to view "socket statistics. From the man page:

Name
ss - another utility to investigate sockets

Synopsis
ss [options] [ FILTER ]

Description
ss is used to dump socket statistics. It allows showing information similar to netstat. It can display more TCP information than state than other tools.

[root@g2aqa3br1.qai ~]# ss -t
State      Recv-Q Send-Q      Local Address:Port          Peer Address:Port
ESTAB      0      0               127.0.0.1:56227            127.0.0.1:6802
ESTAB      0      0               127.0.0.1:56228            127.0.0.1:6802
ESTAB      0      0            172.29.8.131:38140          10.230.6.27:ldaps
ESTAB      0      0            172.29.8.131:38142          10.230.6.27:ldaps

reference: http://linux.die.net/man/8/ss


 


[root@g2aqa3br1.qai ~]# netstat -plunt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0      0 ::ffff:172.29.8.131:1098    :::*                        LISTEN      18572/java
tcp        0      0 :::1099                     :::*                        LISTEN      18572/java
tcp        0      0 :::80                       :::*                        LISTEN      26695/httpd
tcp        0      0 :::22                       :::*                        LISTEN      7327/sshd
tcp        0      0 :::443                      :::*                        LISTEN      26695/httpd
udp     2616      0 0.0.0.0:514                 0.0.0.0:*                               6898/syslogd
[root@g2aqa3br1.qai ~]# ps 26695
PID TTY      STAT   TIME COMMAND
26695 ?        SNs    0:00 /opt/ec/apache2/bin/httpd -d /opt/ec/apache2 
-f /opt/ec/broker/conf/httpd.conf -k start -DSSL


reference:
http://www.cyberciti.biz/faq/find-out-which-service-listening-specific-port

Wednesday, October 13, 2010

linux: my usual ~/.bashrc file

This is the typical ~/.bashrc file I use, especially on cygwin/mintty on Windows boxes. It's work-in-progress and keeps evolving.

Note the handy little shell function, tailHelpAlert, that was designed to run on cygwin, on the Windows box where HelpAlert is running. It determines which is the correct (i.e. most recent) HelpAlert log, and then tails it. You don't have to know which build of HelpAlert you're running, or which temp directory the logs are going to right now.

Another handy little utility is the diskhoggers alias which is a cute little bit of nixcraft (works only on RPM-based distros, of course) to determine which packages (i.e. RPMs) are hogging the most disk space. Very handy when you're critically short of HDD real estate and want to remove junk and clutter quickly.

 

# ################
# My Section:
# ################

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
export HISTSIZE=5000
export HISTFILESIZE=2000
export HISTLENGTH=50000

# don't put duplicate lines in the history. See bash(1) for more options
# ... or force ignoredups and ignorespace
export HISTCONTROL=ignoredups:ignorespace


# http://serverfault.com/questions/72456/stop-bash-tab-completion-from-thinking-i-want-to-cd-into-svn-directories

# Stop bash tab completion from thinking I want to cd into .svn directories
export FIGNORE=svn



alias ls='ls -hF --color=tty'                 # classify files in colour
alias dir='ls --color=auto --format=vertical'
alias vdir='ls --color=auto --format=long'
alias ll='ls -l'                              # long list
alias la='ls -A'                              # all but . and ..
alias l='ls -CF'                              #
# shortcut to see which RPMs are taking the most disk space
alias diskhoggers='rpm -qa --qf "%10{SIZE}\t%{NAME}\n" | sort -n'

# shell prompt
export PS1="[\e[2;33m\u@mintty\e[m \e[0;33m\t\e[m \w] \$ "


#function to tail the correct HA logs automatically
function tailHelpAlert
{

# NOTE: correct the following logs path for your system:
g2aLogsDir=/cygdrive/c/Users/ambars/AppData/Local/Temp/CitrixLogs/GoToAssist/

#find out the correct build number
build_dir=`cd $g2aLogsDir; ls -1t | head -n 1`

cd $g2aLogsDir/$build_dir

targetdir=`ls -1t | head -n 1`

cd $targetdir
tail -f GoToAssist*

}