Linux/Unix misc

http://linux.101hacks.com

bash, profile, sourcing, environment inheritance, et. al.

network connection monitoring tcptrack

Use the following to avoid coding paths or using environment variables in scripts:
BASEDIR=$(dirname $0)

Erasing contents of a file with /dev/zero

/dev/null
/dev/zero

Creating a RamDisk


List CPUs and types:
cat /proc/cpuinfo

Filesystem structure

Filesystem Hierarchy Standard (FHS)

chrontab quick reference

LD_LIBRARY_PATH - don't set it, set-uid programs ignore it
List linked files
ldd

Iterate what make install will do:
make -n install <makefile>

Virtual IP configuration: Unix, Linux, Windows

HA failover with keepalived: Linux

HA through award-winning 'Failover': Solaris, Linux

Load balancing/clustering: Window, Linux
Ultra Monkey: load balancing and HA

To kill process where pid is in file:
backtick replaces command with command execution, see bash programming
kill `cat pid.file`

Reboot Solaris:
shutdown -y -i6 -g0

Solaris logs:
dmesg command - kernel message buffer (boot messages)
/etc/syslog.conf to see where logging goes
/var/adm
/usr/adm - symlink to /var/adm
/var/log
/var/cron
/var/adm/messages

Limit process cpu usage:
cpulimit
limit, ulimit, unlimit, nice

Create and assign processes to cpu sets:
psradm, psrinfo, psrset, processor_bind,
processor_info, sysconf, attributes

download remote files:
wget lt;&url>

whoami
/usr/ucb/whoami
or
/usr/bin/id

Patching: HOWTO patch source code: Wikipedia

'sudo su - toor' - root backwards for alternate root access use for alternate shell
/etc/passwd
toor:x:0:0:Super-User:/:/usr/bin/bash

'hash -r' - clears shells remembered locations, use after adding package or updating path

file <filename> - states file contents, i.e., gzipped

Redirect stdout and stderr to file:
<command> %> <filename>

Run in background and continue after exit:
nohup <command> &

grep "str1" someFile | grep "str2"

egrep 'str1.*str2' someFile

if you don't know the order of the strings:

egrep 'str1.*str2|str2.*str1' someFile


kill particular process

ps -ef | egrep -e SomeProcName -e AdditionalText | grep -v grep | awk '{print $2}' | xargs kill

ps aux | egrep -e jboss | grep -v grep | awk '{print $2}' | xargs kill

find . -exec {grep} \;


Traversing directories that you don't own:

You must have read and execute permissions.

Benchmarking Tools

Bonnie - filesystem performance benchmarking tool

Backgrounding:
Start script with 'nohup scriptName &'
Or execute 'disown' to stop signal propagation

Shell job control:

Ctrl-Z - pauses the current shell process and puts it in the background with the next shell job number starting at 1
bg [job number || %n] || '%1 &' - continue the process in the background as if started with '&'
fg [job number || %n] - continue the process in the foreground
jobs -l - list status of background jobs


kill $(pgrep java)

/usr/sbin/lsof -i :8080


Find open files for a process by PID:

ls -l /proc/1234/fd
lsof -p 1234
lsof -P -n -p 1234

-P inhibits conversion of network port numbers to port names (faster)
-n inhibits conversion of network addresses to host names (faster)

find . -print0 | xargs -0 grep "fu.bar"

for jar in *.jar; do echo $jar; unzip -l ${jar} | grep SomeText; done

find . -name target | xargs rm -rf

find . -name target | ls -al

find . -name "*.xml" -print0 | xargs -0 grep 23799


Kill all SqlDeveloper sessions
ps aux | grep sql | awk '{print $2}' | xargs kill -9

Foreground/background jobs
Ctrl-Z bg
http://www.hcidata.info/background-job.htm

Find space hogging files:
sudo su
cd /
find . -size +50000k -exec du -h {} \; > largeFiles
less largeFiles

Monitor TCP traffic:

sudo tcpdump -X -i lo 'port 9042'
sudo tcpdump host
sudo tcpdump port
sudo tcpdump -D to get localhost
sudo tcpdump -i 6.lo port 8500 to watch localhost traffic to port 8500

Keeping process running when exiting SSH:


Usage:

$ screen
$ cd web/daisycentral
$ node server.js &
$ CTRL-A CTRL-D
$ exit

ext3 32K dirs, ext4 64K dirs, set dir_nlink to exceed 64K
Set dir_nlink:
sudo tune2fs -O dir_nlink  /dev/sda7
List settings:
sudo tune2fs -l /dev/sda7
create dir symlinks to exceed 32K

Shortcuts

home dir
cd ~

last dir
cd -

Screen - alternative to nohup

screen -d -R some_session_name

Find all libs in jars:

 find standalone/ -name "*.jar" -exec jar tf {} \; -ls > ~/tmp/all-jboss-libs.txt

Find interface speed


dmesg | grep eth0

Kill multiple pids simultaneously

kill -9 {1234,234,4523}

Screen: allows post no-hup and backgrounding of processes

Mount ISO
mkdir ~/media/<some-mount-point>
sudo mount ~/some.iso ~/media/<some-mount-point> -o loop
Update interfaces without restarting
vi /etc/network/interfaces
sudo /etc/init.d/networking restart
ifdown eth0:1
ifup eth0:1

To dynamically change interface mtu
ifconfig eth0 mtu 65520

To identify Ubuntu release
lsb_release -a

To test service in script
nc -z -w5 <host> <port>

Comments

Popular posts from this blog

Sites, Newsletters, and Blogs

Oracle JDBC ReadTimeout QueryTimeout