Showing posts with label Unix. Show all posts
Showing posts with label Unix. Show all posts

Sunday, July 21, 2019

Sort unix folders by size


Buy Moto series phones: Moto E, Moto G, Moto X or Other phones
Buy eBooks from Flipkart
-----------------------------------------------

du -ks * | sort -n -r

 


Wednesday, July 25, 2018

Column selection in Eclipse


Buy Moto series phones: Moto E, Moto G, Moto X or Other phones
Buy eBooks from Flipkart
-----------------------------------------------

Eclipse also offers column selection functionality similar to popular text editors Notepad++, Sublime Text2.

On a Mac, need to press "cmd + option + A"
On Windows and Linux, you need to press "alt + shift + A"

Please note doing above will take you to block selection mode, and you need to press same keys again to come back to normal mode.

Source: https://stackoverflow.com/questions/1053725/how-do-i-enable-the-column-selection-mode-in-eclipse


Wednesday, July 18, 2018

Validate firewall connectivity using nc


Buy Moto series phones: Moto E, Moto G, Moto X or Other phones
Buy eBooks from Flipkart
-----------------------------------------------

In absence of telnet we can use nc (which version??) to validate connectivity.

nc -w 2 -v 10.0.0.1 < /dev/null; exitCode=$?; echo "Exit code = $exitCode"; if [ $exitCode -ge 1 ]; then echo "No connectivity"; else echo 'SUCCESS!!!'; fi; >> fw_validation.txt



Friday, July 13, 2018

To setup a simple log monitoring script


// TODO


#! /bin/bash
echo "monitoring log files"
if grep SQLSTATE application-cronjob-*-`date +"%Y-%m-%d"`.log ;
then
    echo "sending mail"
    grep -10 SQLSTATE application-cronjob-*-`date +"%Y-%m-%d"`.log | mail -s "errors found in  logs for `date +"%Y-%m-%d"` example@example.com
fi

Wednesday, November 1, 2017

Bash for loop examples


Buy Moto series phones: Moto E, Moto G, Moto X or Other phones
Buy eBooks from Flipkart
-----------------------------------------------

For loop example in bash script:
To get yarn log files for multiple spark jobs, we can use this command.
for i in `cat appid.txt`; do echo $i; yarn logs -applicationId $i > sparkjob_01sep_logs/$i.log; echo "——"; done




For loop with sequence and ssh into multiple servers:
To login into multiple servers and run a command, we can use below command.

for i in `seq 101 125`;do ssh -q machinename$i "hostname;ls -ltr";done



Monday, November 3, 2014

Find out which Java thread is causing the high CPU usage


Buy Moto series phones: Moto E, Moto G, Moto X or Other phones
Buy eBooks from Flipkart
-----------------------------------------------

You see your java application is consuming high CPU but you don't know specifically which thread is consuming CPU out of thousand threads.

The solution is very simple.
1. First we need to find out native thread ID that is using high CPU. Issue top -H command on terminal and it will show all threads and the percentage of the CPU they are consuming. Find out your application thread from the list and note down native thread id which will be shown in the first column named PID.

2. Take thread dump of your application.

3. Thread dump contains native thread ID but in hexadecimal format. So convert the decimal thread ID we have noted in the first step to hexadecimal value and search for this value in the thread dump and you will find the thread's stack trace.

 You can see more detailed explanation in the source link below. It gives an example program and also details how to do this in both Unix and Windows.

----------------------------------------------------------------------------------------------
Source: https://blogs.oracle.com/jiechen/entry/analysis_against_jvm_thread_dump

Monday, May 26, 2014

To get http status code from curl call


Buy Moto series phones: Moto E, Moto G, Moto X or Other phones
Buy eBooks from Flipkart
-----------------------------------------------

We can use below command to get http response code of a URL from bash script.

status_code=$(curl --write-out "\n%{http_code}\n" --silent --output /dev/null --insecure https://www.google.co.in/)

silent - to stop progress information in output
output - we are re-directing normal output to null device
write-out - whatever things we needed can be given here. Here we are printing http status code. It will be printed after completion, i.e., after printing all output.
insecure - this allows connections to SSL sites without certs

References: http://stackoverflow.com/a/2220646/324900

Thursday, April 10, 2014

What is Heartbleed Bug


It is basically a security bug (buffer overread) which is in the Open SSL implementation which is used by a looooooooot of websites on the internet to secure ( :) ) the communication between browser and website.

Jacob on stackexchange explained this issue in detail. Read his answer at superuser.com

Sunday, January 26, 2014

to view only directories in Unix


If you have ever wanted to show a list of subdirectories underneath the current directory while at the terminal prompt, there’s a simple command that can help.
Simply run the following command from the bash terminal prompt, which filters the file listing to only show folders:

ls -l | grep ^d
Since typing that whole command every time you want to show a list of directories might get a little tiring, you can use the alias feature to assign it to something you can more easily remember:
alias lsd="ls -l | grep ^d"
Now when you type “lsd” at the prompt, you will see a list containing only the directories, which can be very useful when you are trying to navigate through a messy set of folders.

Sunday, January 19, 2014

Some useful VI editor commands


J – to join two lines
Deletion
dl – single character, dw – Single word, dd – single line, d$ – to the end of the line
Editing
i – insert mode, A – append to the end of the line, o – insert in next line
Misc
:set list – to see special characters
:%s/str1/str2/g – search and replace

Sunday, January 12, 2014

Some useful variables in Unix


$$ = The PID number of the process executing the shell.
$? = Exit status variable.
$0 = The name of the command you used to call a program.
$1 = The first argument on the command line.
$2 = The second argument on the command line.
$n = The nth argument on the command line.
$* = All the arguments on the command line.
$# The number of command line arguments.

Sunday, January 5, 2014

Read password from shell script


Since you don't want password to be not displayed on terminal you need to disable echo before reading password. Once password is read you need to enable it again.

#————————————————————
#  Read Password
#————————————————————
/usr/ucb/echo -n “Please Enter Password For User ${SUSER}: “
stty -echo
read SPSWD
stty echo
clear

Friday, December 2, 2011

How to do MySQL port forwarding using PuTTY

1. Go to Session: enter site name, port, etc…
2. Window > Behaviour : Window Title can be set here.
3. Connection > Data: User name should be given Auto-login username.
4. Connection > SSH : check Enable Compression.
5. Connection > SSH > Tunnels: enter local port number in Source Port, the port to be forwarded in Destination in the form : and click on Add to create the tunnel.
For MySQL client, this local port will be the port and localhost will be the machine.

Create windows short cut for this.
1. Create a short cut for PuTTY and change its command like below.
C:\Users\user\Desktop\putty.exe -ssh -pw -load
Source: http://www.jfitz.com/tips/putty_config.html

Thursday, July 7, 2011

Find recursively and copy files in Unix

I was trying to do a recursive search in Unix using find command and then copy all those files to a specific folder.

I found below command does that.

find . -name *2011-03-19* -exec cp {} /home/Reddy/logs/ \;

Important thing is, we need to escape the ending semi-colon.

{} is the place holder for putting the search result, i.e., the file name found.

Latest Posts