Table of Contents
How to .....
.gvfs
How to get rid of .gvfs and what it is.
What it is GVFS is a replacement for GnomeVFS, the GNOME Virtual File System
{User_home}/.gvfs is used as a mount point for the Gnome gvfs for user. It stays mounted even when user is logged off.You need to umount it prior to delete it. Use following command to unmount
umount -fl /home/xyz/.gvfs
How to drop all table from database (mysql)
To drop all the table in the mysql database - use the following command. <WRAP prewrap>
mysqldump -u[USERNAME] -p[PASSWORD] --add-drop-table --no-data [DATABASE] | grep ^DROP | mysql -u[USERNAME] -p[PASSWORD] [DATABASE]
</WRAP>
How to list pear using php
First install PEAR_Info
pear install PEAR_Info
Than create file pearinfo.php with following content.
<?php require_once 'PEAR/Info.php'; $info = new PEAR_Info(); $info->display(); ?>
Now browse the file in your favorite browser.
How to list Installed CPAN Modules
#!/usr/bin/perl use ExtUtils::Installed; my $instmod = ExtUtils::Installed->new(); foreach my $module ($instmod->modules()) { my $version = $instmod->version($module) || "???"; print "$module -- $version\n"; }
Watch output of command with refresh
This can me usefull to monitor command with no refresh. like vmstat, iostat
watch -n 3 vmstat -D
Force Change password next login
chage -d 0 <Username>
Setting up Multiple ip using single file
You can add IP range to server using following way.
Range file :
replace “eth0” with your nic name in file name.
CLONENUM_START - change based on range you add to NIC.
in respect of below configuration next CLONENUM_START for eth0 is “6”
- | /etc/sysconfig/network-scripts/ifcfg-eth0-range0
IPADDR_START=192.168.1.25 IPADDR_END=192.168.1.30 CLONENUM_START=0
Setting up Multiple Block of IP to single NIC/server
In normal case if you add diff. block of IP only one block will work.
As gateway for all block might be different.
In that case you need to add following line to config.
- | /etc/sysconfig/network
GATEWAYDEV="eth0"
NOTE : replace eth0 based on your NIC name
Getting Old Version of PHP package from cvs
From : http://php.net
Setting up cvs client. (Recommended)
- | ~/.cvsrc
cvs -z3 update -d -P checkout -P diff -u
Login to cvs server using anonymous login
password : phpfi
cvs -d :pserver:cvsread@cvs.php.net:/repository login
Download source from cvs.
Make sure you replace php_5_2_5 with your version need (e.g. php_4_0_3)
cvs -d :pserver:cvsread@cvs.php.net:/repository checkout -r php_5_2_5 php-src
Now you have clean version of sources on your machine.
In order to generate configure script you need to run following.
./buildconf
To build package use following.
Replace versions with your checkout snap.
makedist <package> <version>
sh makedist php 5.2.5
You just make your own distribution package.
How to test UDP Connection
This is needed in many cases. Many services still use UDP port for Authentication / Certification for software.
You can test connection using nmap.
# nmap -p [port] -sU -P0 [host name | ip address] # nmap -p 234 -sU -P0 xx.xx.xx.xx # nmap -p 543 -sU -P0 xx.xx.xx.xx
Also you can use netcat
nc -zu <ip> <udpport>
ip_conntrack: table full, dropping packet
I found myself with a server under normal load.
but, it no network connections initiated. and log is full of entry as below
ip_conntrack: table full, dropping packet
After searching on google found Redhat site for more details.
It seems server was running iptables, but it was under a very heavy load and also handling a high volume of network connections.
Generally, the ip_conntrack_max is set to the total MB of RAM installed multiplied by 16.
However, this server had 2GB of RAM, but ip_conntrack_max was set to 65536:
# cat /proc/sys/net/ipv4/ip_conntrack_max 65536
I have checked with few other server and all had ip_conntrack_max set to 65536.
I’m not sure seems default value to me.
Now i have found my value using following:
# cat /proc/sys/net/ipv4/netfilter/ip_conntrack_count
and i have adjusted using following. about 8GB ram.
# echo 131072 > /proc/sys/net/ipv4/ip_conntrack_max
But, above change is temporary to set value at boot do following.
- | /etc/sysctl.conf
net.ipv4.ip_conntrack_max=131072
This should be it.
Crontab with own php.ini and send result to mail
If you need to run cron with your own php.ini and send result to mail use following. <WRAP prewrap>
*/1 */2 * * * /usr/local/bin/php --php-ini /srv/www/conf/php.ini /srv/www/public_html/cron.php | /usr/bin/mail -s "Output of crontab" xyz@yahoo.com
</WRAP>
Exit Codes
At some point you feel like there is no exit code documentation and you want find you what should it return.
There is simple practical way to find exit code in linux.
echo $?
which determine what exit code was returned by a command. must be post run this after command.
following is simple example.
ls bcd ls: bcd: No such file or directory echo $? 2
Which as ls return “2” serious trouble. file not found.
If 0 All OK.
You can post run with any command and find out what is the return code. This will help you as quick fix.
In logical programming you must have all the exit codes for best result.
How to use serial console
Here is the simple how to on using serial console.
First find out how many serial device is connected.
dmesg | grep tty
Which should return following results.
serial8250: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A serial8250: ttyS1 at I/O 0x2f8 (irq = 3) is a 16550A 00:0a: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A 00:0b: ttyS1 at I/O 0x2f8 (irq = 3) is a 16550A
On my machine it find only two ports.
so i am using “[01]” for those two ports. if you have more add number like “[012..]”.
Now Initialize those ports.
setserial -g /dev/ttyS[01]
You are all set.
Now connect to serial port using minicom.
minicom -o
This works for me.
How to grab External IP
I needed clean and most frequent access to find outgoing IP of servers.
So based on Environment variable i have developed small script. script to grab visitor IP
which print your external IP.
curl ip.k2patel.in
NOTE :
- I do not track or log any request coming to above domain.
- But in case of any excessive amount of request i might enable logging to block such activity.
Truncate on Linux
Not sure what make truncate command to disappear from linux.
But it is/was really usefull tool. following is alternative way to reduce file size.
Command below will reduce size to 100MB, and it takes argument in bytes. replace according to your need. (replace bs=“”)
dd if=/dev/null of=msyql_slow.txt seek=1 bs=104857600
Removing Patch
To remove applied patch use following command.
patch -R
Preserve Custom nameserver
To preserve custom nameserver while using DHCP you need to modify config file.
add or update following line.
- | /etc/dhcp/dhclient.conf
prepend domain-name-servers 4.2.2.1,8.8.8.8;
Redhat / Fedora
NM looks for /etc/dhclient-<interface>.conf then /etc/dhcp/dhclient-<interface>.conf
and will merge the first found into the dhclient config files it produces.
Enable port below 1024 for all users
NOTE : Please be aware it is not / never advisable.
Now if you want java to use port below 1024 you can use following command.
setcap 'cap_net_bind_service=+ep' /usr/bin/java
NOTE : It is only available on RHEL6/CentOS6 and up
Building Software RAID
One of nice feature about software RAID is you can get good performance using it.
Here is the simple steps to follow to create software raid level 10.
Step 1 : Create Partition Assign type - fd
fdisk /dev/sdf fdisk /dev/sdg fdisk /dev/sdh fdisk /dev/sdi
Step 2 : Create Raid Drive. ( this command will create “/dev/md10” ) <WRAP prewrap>
mdadm --create --level=10 --raid-devices=4 --spare-devices=0 --chunk=128 --layout=f2 /dev/md10 /dev/sdf1 /dev/sdg1 /dev/sdh1 /dev/sdi1
</WRAP>
Step 3: Format Drive ( I am formatting for XFS )
mkfs.xfs /dev/md10
Moving Between Machine create if you don't have it already
<note warning> Do not keep or include UUID in destination System, Simply copy rest of the part leaving UUID behind. </note>
Source System :
mdadm --examine --scan > /etc/mdadm.conf mdadm --stop /dev/md10
Destination System :
Add / Create mdadm
- | /etc/mdadm.conf
ARRAY /dev/md10 level=raid10 num-devices=4 metadata=0.90 devices=/dev/sdg1,/dev/sdh1,/dev/sdi1,/dev/sdj1
Now assemble it on new system.
mdadm --assemble --scan --verbose /dev/md10 /dev/sdg1 /dev/sdh1 /dev/sdi1 /dev/sdj1
Mount /dev/md10 - Enjoy.!!
ramfs on Linux
<note warning>Do not confuse your self with tmpfs and ramfs as both are diff. entity</note>
To create/mount ramfs you can use following command.
Please make sure folder already exists.
mount -t ramfs none /tmp/toall
Reduce default tmpfs size
Default size of /dev/shm is almost 50% of your memory.
In order to reduce it to some optimal value you can update your /etc/fstab.
just add size variable in your option field : comma saperated : will do.
tmpfs /dev/shm tmpfs defaults,size=8g 0 0
Password Hashing Algorithm
Display Hashing Algorithm on server
authconfig --test | grep hashing
Change Algorithm on server
authconfig --passalgo=sha512 --update
Changing encrypted file system password
If you have encrypted partitions you can change password using following commands.
<note warning>Replace sda2 with your drive number</note>
Check which key slot is occupied
cryptsetup luksDump /dev/sda2
Now add key to next free slot
cryptsetup luksAddKey /dev/sda2
Now remove / Disable Previous slot
cryptsetup luksKillSlot /dev/sda2 0
Check for Operation Windigo infection
ssh -G 2>&1 | grep -e illegal -e unknown > /dev/null && echo “System clean” || echo “System infected”
Creating patch for rpm
this can be used as '%patch0 -p1 -b <file_name>'
diff -ru hdf-4.2.12-orig hdf-4.2.12-diff >| ../SOURCES/hdf-4.2.12.example.patch
Configure option for Fedora / Redhat
replace amaya with your application etc…
This is usefull while compiling sources for systems
<WRAP prewrap>
../configure -enable-system-raptor '--build=x86_64-redhat-linux-gnu' '--host=x86_64-redhat-linux-gnu' '--program-prefix=' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--sysconfdir=/etc' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib64' '--libexecdir=/usr/libexec' '--sharedstatedir=/var/lib' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--exec_prefix=/usr' 'build_alias=x86_64-redhat-linux-gnu' 'host_alias=x86_64-redhat-linux-gnu' '--libexecdir=/usr/lib64/amaya' '--localstatedir=/var' '--datadir=/usr/share/amaya' '--sysconfdir=/etc/amaya' '--with-logdir=$(localstatedir)/log/amaya' '--with-pidfile=$(localstatedir)/run/amaya.pid'
</WRAP>
Run single command parallel'y with diff values
<WRAP prewrap>
(echo "http://test.k2patel.in"; echo "http://test.ornl.gov"; echo "http://yahoo.com" ) | parallel 'ab -n 50 -c 50 {}'
</WRAP>
Print yum variable value
import yum import pprint yvar = yum.YumBase() pprint.pprint(yvar.conf.yumvar, width=1)
Disable Predictable interface name in RHEL / CentOS
Pass following during boot kernel command line.
net.ifnames=0