UNIX Random Tips - sorry Linux Tips is what I really meant
Test logrotate
logrotate -f /etc/logrotate.conf
Establish ssh tunnel to vncserver
ssh -L 5901:vncserver:5901 server
vncviewer localhost:5901 should result in tunneled connection to vncserver
Push ssh into background and do not execute remote command:
ssh -Nf vncserver 5901:vncserver:5901
Kill vncserver with: vncserver -kill :1
Check if a service is SELinux aware
Service status - service --status-all
chkconfig --list
Useful man pages
Check if service is libwrapped with TCP Wrappers
Remount a filesystem that has locks
SSH Tunneling Example
Reverse SSH Tunnel Example
Determine disk used versus available on Linux:
df -Pkl |grep -v shm|awk ' { avail += $2/1024/1024 } END { printf("%d Gb total avail", avail)}'
Sort user accounts are on server - getent passwd |sort -t ":" -k 3 -g
Speedier sftp transfer at the expense of security:
sftp -oCipher=blowfish-cbc host:/path
Format a swap partition:
mkswap /dev/sda5
in fstab add /dev/sda5 swap swap defaults 0 0
swapon -a
Create a large 2GB file for test purposes:
dd if=/dev/zero of=largefile bs=1M count=2048
Rsync example:
client initiated
rsync -av -e ssh server1:/usr/local/cvsroot/ /usr/local/cvsroot >> /tmp/cvs_rsync_log
server initiated
rsync -av -e ssh /usr/local/cvsroot/ server1:/usr/local/cvsroot >> /tmp/cvs_rsync_log
Pattern replace for multiple files example:
to replace pattern server with pattern server-tst in all files containing .properties in the current directory and below:
for i in `find . -name *.properties*`$i | sed -e 's/server/server-tst/' > $i.1 | mv -f $i.1 $i; done
Mail Attachments:
mutt -s "Subject" -a picture.jpg user@mydomain.com
Count Files in a Directory recursively:
find YOURDIR -type f ¦ wc -l
Install Kernel Source and headers on Ubuntu:
use sudo passwd to give root a password and enable shell login
su -
apt-get install build-essential linux-headers-`uname -r`
remove comments and blank lines with:
grep -v "^#" /etc/squid/squid.conf | sed -e '/^$/d'change uid example:
lgroupmod -g 712 groupnameusermod -u 712 -U username
Create users with specific uid and groupid:
To create an oracle user (only required on an Oracle server):
groupadd -g 502 oinstall ; useradd –m -u 500 -g oinstall oracle ; echo "password" |passwd --stdin oracle
To create a standard user:
groupadd -g 701 [groupname] ; useradd -m -u 701 -g [groupname] [username] ; echo "password"|passwd --stdin [username]
CHANGE UID's and ownership of files on entire fs:
find / -mount -user UID -print | xargs chown newownerThis variation changes the group ownership:
find / -mount -group GID -print | xargs chgrp newgroup
Find files modified more than x days ago:
find / -mount -mtime +3
Find faulty permissions
find / \( -nouser -o -nogroup \) # files and directories with no matching user or group in passwd
find / -type f -perm 002 #files writable by other group
find / -type d -perm -2 #directories writable by other
Fixing Duplicate RPM's:
rpm -qa --queryformat "%{NAME}-%{VERSION}-%{ARCH} \\n" | grep <packagename> | sortthen remove the one not needed - may need to fix the packagename a little for it to work....
rpm -e bluez-libs-2.10-i386
rpm -e bluez-libs-2.10-x86_64
may needs to be changes to:
rpm -e bluez-libs-2.10-2.i386
rpm -e bluez-libs-2.10-2.x86_64
Install megaraid driver from SRPM example:
Install megaraid driverdownload driver from
http://www-304.ibm.com/jct01004c/systems/support/supportsite.wss/license?filename=system_
x/lsi_dd_megasas_00.00.03.06_rhel4_32-64.tgz&root=/systems/support/&brandind=5000008
sftp the drivers over to server and extract them with tar zxvf *.tgz
go to SRPM folder and install with rpm -ivh *.rpm
cd to /usr/src/redhat
export BUILD_KERNEL="2.6.9-55.ELsmp" #2.6.9-55.ELsmp is result of uname -r
rpmbuild -bb SPECS/megaraid_sas.spec
rpm -ivh /RPMS/x86_64/lsi-megaraid_sas-smp-00.00.03.06_2.6.9_55.EL-0.x86_64.rpm
rpm -ivh /RPMS/x86_64/lsi-megaraid_sas-smp-debuginfo-00.00.03.06_2.6.9_55.EL-0.x86_64.rpm
Copy or Cut and Paste in VIM
Cut and Paste:- Place the cursor at the beginning of the block you want to CUT.
- Mark it with md
- Go to the end of the block.
- Cut it with d'd
- Go to the new location that you want to PASTE the text.
- Enter P (shift-p).
Copy and Paste:
- Place the cursor at the beginning of the block you want to COPY.
- Mark it with my
- Go to the end of the block.
- Copy it with y'y
- Go to the new location that you want to paste the text.
- Press P (shift-p).
Replace one character with another for an entire file:
cat <filename> | tr \" \' > <outfilename> # will replace all " with ' in <filename> and output to <outfilename>Finding Services on my network i.e. Servers running MySQL:
nmap -sV -p 3306 192.168.1-254 > MySQLhosts.outnmap options
-sS #synchronous scan TCP
-sU #UDP scan
-sR #RPC/portmap
-A #OS and version detection
-v #verbose
-P0 #suppress pretest ping
-p #port
will locate all servers running mysql on default port 3306 on the class C 192.168.1.x network
Just open the MySQLhosts.out file to find hosts that are not in closed state
Find files that are filling up disk space:
cd to dir that is filling updu -sk * | sort -nr | more
list files and directories in order of space they occupy
Updating Kernel parameters on Linux:
Edit /etc/sysctl.conf for example:kernel.shmmax = 2147483648
kernel.shmmni = 4096
kernel.shmall = 2097152
kernel.shmmin = 1
kernel.shmseg = 10
kernel.sem = 250 32000 100 128
fs.file-max = 104032
net.ipv4.ip_local_port_range = 1024 65000
net.ipv4.tcp_fin_timeout = 15
net.core.rmem_default = 1048576
net.core.rmem_max = 16777216
net.core.wmem_default = 262144
net.core.wmem_max = 16777216
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 65536 16777216
Run
sysctl -p # this loads the parameters from changes made to sysctl.conf
ipcs -l # lists the parameters
Set date and time:
date MMDDhhmm.ss
Crontab:
* * * * * command to be executed
- - - - -
| | | | |
| | | | +----- day of week (0 - 6) (Sunday=0)
| | | +------- month (1 - 12)
| | +--------- day of month (1 - 31)
| +----------- hour (0 - 23)
+------------- min (0 - 59)
Changing linux prompt in profile
What is my ip? /sbin/ifconfig or /sbin/ip addr
What is my mac? /sbin/ip maddr
No comments:
Post a Comment