Showing posts with label commands. Show all posts
Showing posts with label commands. Show all posts

Saturday, 7 May 2016

SSH - Black Magic


Remote port forwarding - Public connections to my laptop on any network:
------------------------------------------------------------------------
ssh -R ${remote}:${local} remote

Initiated by the remote machine.
Example:
1.) Run this on your Mac
ssh -R *:2020:localhost:22  -i awskey.pem ec2-user@ec2-xx-xx-xxx-xxx.us-west-2.compute.amazonaws.com

2.) Then on AWS machine to access your Mac:
ssh macuser@localhost -p 2020


Local port forwarding:
-------------------------------------------------
ssh -L ${local}:${remote} remote

Initiated by the local machine.

3.) Dynamic port forwarding, SOCKS 5 proxy using '-D' flag


Original link:
https://vimeo.com/54505525

Monday, 4 February 2013

Using multi-dimensional associative arrays in AWK

Examples:

cat /tmp/33 | awk -F'[\\^\\[\\]]' '{c[$5,$6]+=1}END{for( i in c) {split(i,sep,SUBSEP); print sep[1],sep[2], c[i] ;}}' 

Reading:

Thursday, 31 January 2013

How to find the process which has the file handle open ?

A lot of times you need to find which Process (PID) has the handle to a particular file.
In linux doing this easy using the following command:

$ ls -ld1 /proc/*/fd/* | grep <file-name-filter>

Enjoy !!

Saturday, 7 July 2012

Java Heap dumps and Thread dumps

THREAD DUMP
To take the thread dump of the running java process with process id = PID, use: "kill -3 PID".


The thread dump is written to the system out of the VM on which you executed the kill -3. If you are redirecting the console output of the JVM to a file, the thread dump will be in that file. If the JVM is running in an open console, then the thread dump will be displayed in its console.


You could alternatively use jstack (Included with JDK) to take a thread dump and write the output wherever you want

jstack PID > outfile



HEAP DUMP


You can use jdk utility 'jmap' to take the heap dump.


And use the jdk tool 'jhat' to analyse java heaps.


http://www.startux.de/java/45-java-heap-dump

Monday, 16 April 2012

Change grub boot order

Edit the file: "/boot/grub/menu.lst" from linux and set the "default 0" to the appropriate number you want to startup by default.

If you can't find the above file, you need to edit the file "/boot/grub/grub.cfg".

Sunday, 15 April 2012

Using Strace in linux

The following article explains the usage of strace command for troubleshooting in linux:
http://www.hokstad.com/5-simple-ways-to-troubleshoot-using-strace.html

strace is a tool for tracing system calls and signals. It intercepts and records the system calls made by a running process. strace can print a record of each system call, its arguments, and its return value. You can use strace on programs for which you do not have the source since using strace does not require recompilation. It is often useful in instances where a program freezes or otherwise fails to work and offers few clues as to the problem.


Strace Output: Each line starts with a system call name, is followed by its arguments in parenthesis and then has the return value at the end of the line. Errors (which typically have a return value of -1) have the symbolic error name (such as ENOENT in the first line in the example above) as well as a more informative error string appended.



Thursday, 12 April 2012

SCP and SSH without password

To setup the password-less logging from one box 'Source' to another box 'Dest'.
You need to generate the 'Source' user's public/private key pair, and then append the public key of this user to 'Dest' user's ".ssh/authorized_keys" file.
Important thing to note is that destination and source users can be different. However, the ".ssh" folder inside 'Dest' user's home directory needs to have unix permissions '700' for this to work (Because otherwise anyone can write their public key into this folder and gain access to the destination user's account).

The following article explains the setup of password less ssh or scp setup between two systems.
It provides the troubleshooting for common problems as well.

http://homepage.mac.com/kelleherk/iblog/C1901548470/E20061128145420/index.html

Monday, 9 April 2012

Find all files recursively in the current directory and process them one by one

Finding all files in the current directory, and execute a command on each file:


find ./ -mtime +1 -exec rm -vf {} \;


the command executed on each file is in italics in the above line, and '{}' is replaced by the file name during the command execution.

Check the memory used by a unix process


To see the memory used by the process, ps can be used with flags -AH
ps -AH v | grep 3408
where 3408 is the PID of process.

Check the column RSS (resident set size). It is the non-swapped physical memory that a task has used (in kiloBytes). (alias rssize) rsz).

Java Heap analysis using jdk tools

To take a heap dump of a java process using the jdk tools, use jmap:
jmap -dump:format=b,file=heap.bin <pid>
where pid is the process id of the java process.


After taking the heap dump, you can use the jhat (Java Heap Analyzer tool) provided by jdk to analyse te heap dump:
jhat -port 7777

Saturday, 31 March 2012

Setting up HTTP proxy in the linux shell


You can set the http_proxy environment variable using the command specific to your shell (e.g. set or export). 

To make this change persistent, add the command to the appropriate profile file for the shell. For example, in bash, add a line like the following to your .bash_profile or .bashrc file:

http_proxy=http://username:password@hostname:port;  
export http_proxy

Remote file copying in shell

You can use "scp" command to copy files between systems. This utility is based on "ssh" protocol.
Usage:
scp /home/* username@destinationMachine:/destination_path


The above command copied all files in home folder to destinationMachine's path.

Finding the open ports on a system

You can find the opened/used ports of the system using the netstat command.

netstat -an


Adding the additional switch "-b" to the above lists the process PID using each port.
If you want to search for any particular string in the output of netstat you can use the "find" command on windows system as follows:

netstat -an | find "97.107"