Showing posts with label script. Show all posts
Showing posts with label script. Show all posts
How to find the 10 largest file or directories in Linux
This finds the largest 10 files :
find . -type f -print0 | xargs -0 du -s | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {}
This finds the largest 10 directories:
find . -type d -print0 | xargs -0 du -s | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {}
You can easily change -10 to -n where n is the number of files/directories you are trying to find.
Labels:
admin,
bash,
cut,
du,
Enterpise Linux,
find,
linux,
linux administraion,
script,
shell,
sort,
system admin,
tail,
unix,
xargs
How to take a Java thread dump from a shell/bash script
We already know how to get a Java thread dump manually. But what if we want to take a Java thread dump from a script to help us automate things.
To do this we need to come up with a ps and grep combination that will only return one result. so grep as many times as neccessary and/or use keywords that are only found in your process name so you only get one result.
Remember to add [] somewhere in your first grep so grep doesn't matches itself.
To do this we need to come up with a ps and grep combination that will only return one result. so grep as many times as neccessary and/or use keywords that are only found in your process name so you only get one result.
Remember to add [] somewhere in your first grep so grep doesn't matches itself.
output=$(ps -ef | grep m[y]ProcesseName )Then all you need to do is sending the QUIT signal to $2 which stores the PID of your process.
kill -QUIT $2So just add the above two lines to your script after modifying the first line to fit your needs and you should be good to go.
Labels:
automation,
bash,
Enterpise Linux,
Java,
JVM,
kill,
linux,
script,
shell,
thread dump,
unix
Subscribe to:
Posts (Atom)