Difference between bytes and bits
Sat, 07/26/2008 - 13:34 — sandipBits are 1s or 0s representing the state of a switch, in binary form.
A byte is a binary word, consisting of 8 bits.
8 bits equals one Byte.
1024 bytes equals one KiloByte (KB)
1024 KiloBytes equals one MegaByte (MB)
1024 MegaBytes equals one GigaByte (GB)
Sometimes people use 1000 instead of 1024, so numbers sometimes get screwy.
A bit is always represented by a small "b", a Byte is always represented by a large "B".
It is common practice to use bits in reference to interface speeds and bytes in reference to memory and storage capacities.
- sandip's blog
- Login or register to post comments
- Read more
Importing existing SSL key and certificate for tomcat
Fri, 07/25/2008 - 16:50 — sandip-
Convert key and cert to a single pkcs12 format.
openssl pkcs12 -export -inkey <pathto>/key.txt -in <pathto>/cert.txt -out cert.pkcs12
keytool -delete -alias tomcat -keystore <pathto>/cacerts
keytool -importkeystore -destkeystore cacerts -srckeystore cert.pkcs12 -srcstoretype PKCS12
keytool -list -keystore <pathto>/cacerts | grep PrivateKeyEntry
keytool -changealias -alias 1 -destalias tomcat -keystore <pathto>/cacerts
Simple captcha for oscommerce contact form
Thu, 07/24/2008 - 21:52 — sandipEmbed the captcha image by calling a php script in "contact_us.php":
<input type="text" name="verify" />
<img src="/image.php" width="60" height="20" alt="Please enter the values from this image" />
Edit contact_us.php file and exactly after the below line:
if (isset($HTTP_GET_VARS['ac tion']) && ($HTTP_GET_VARS['action 039;] == 'send')) {
place the verification code:
// Captcha check
&nbs p; $t = trim($HTTP_POST_VARS['ver ify']);
&nbs p; if ($t == "") {
&nbs p; &nbs p; &nbs p; $captcha_error = "Enter the verification code!";
&nbs p; &nbs p; &nbs p; $error = true;
&nbs p; &nbs p; &nbs p; $messageStack->add('co ntact', $captcha_error);
&nbs p; } else if (trim($_SESSION["thecode& quot;]) == "") {
&nbs p; &nbs p; &nbs p; $captcha_error = "No verification code generated!";
&nbs p; &nbs p; &nbs p; $error = true;
&nbs p; &nbs p; &nbs p; $messageStack->add('co ntact', $captcha_error);
&nbs p; } else if ($_SESSION["thecode" ] != strtoupper($t)) {
&nbs p; &nbs p; &nbs p; $captcha_error = "Invalid verification code!";
&nbs p; &nbs p; &nbs p; $error = true;
&nbs p; &nbs p; &nbs p; $messageStack->add('co ntact', $captcha_error);
&nbs p; }
&nbs p; else
&nbs p; { // End Captcha Check
Support for 32 bit development libraries on 64 bit CentOS
Fri, 07/18/2008 - 09:45 — sandipTo support C/C++ 32 bit development libraries on CentOS-5.2 x86_64 arch the below devel packages are required:
yum install glibc-devel.i386 libstdc++-devel.i386
Below is example output of multilib support for gcc:
$ gcc -print-multi-lib; gcc -print-multi-os-directory; gcc -print-multi-os-directory -m32
.;
32;@m32
../lib64
../lib
Create users in OpenVZ Containers
Fri, 07/11/2008 - 00:35 — sandipHelper script to create users on all OpenVZ VEs simultaneously:
#!/bin/bash
# create_ve_users.sh
# Usage: ./create_ve_users.sh <username> <password> <uid> <group1,group2>
USERNAME=$1
PASSWORD=$2
USERID=$3
GROUP=$4
EXPECTED_ARGS=4
OUT_FILE=.create_users_$$
/>
if [ $# -ne $EXPECTED_ARGS ]
then
echo "Usage: `basename $0` <username> <password> <uid> <group1,group2>"
/> exit 65
fi
VE_LIST=$(/usr/sbin/vzlist -H -o veid)
for VE in ${VE_LIST}
do
&nbs p; vzctl exec $VE \
&nbs p; &nbs p; &nbs p; "echo useradd -u $USERID -G $GROUP -p \''`openssl passwd -1 $PASSWORD`'\' $USERNAME > /tmp/${OUT_FILE} ; \
&nbs p; &nbs p; &nbs p; sh /tmp/${OUT_FILE} ; \
&nbs p; &nbs p; &nbs p; rm -f /tmp/${OUT_FILE}"
done
exit 0
- sandip's blog
- Login or register to post comments
Update OpenVZ containers
Wed, 07/09/2008 - 16:51 — sandipIf you manage several OpenVZ containers, here is a simple bash script to keep the OpenVZ containers upto date.
#!/bin/bash
# vzyum_updates.sh
# updates VEs
VE_LIST=$(/usr/sbin/vzlist -H -o veid | grep -v Warning)
for VE in ${VE_LIST}
do
/usr/bin/vzyum $VE update
done
exit 0
- sandip's blog
- Login or register to post comments
OpenVZ CentOS template cache creation with vzpkgcache
Mon, 07/07/2008 - 23:44 — sandipFollowing the instruction over at OpenVZ Wiki, I've had no problems with the installation and creation of templates prior to CentOS-5.2 on x86_64 systems. However, with the latest set of updates to CentOS-5.2, the vzpkgcache seems to have been broken as sysklogd is no longer being installed by default. Below is how I got it to work:
Note: edit /vz/template/centos/5/x86_64/c
# vzpkgcache -f centos-5-x86_64-minimal
which gives the below error at the end:
sed: can't read /etc/init.d/syslog: No such file or directory
ERROR: Script install-post failed
The solution was to edit "/vz/template/centos/5/x86_64/
# Disable klogd
$VZCTL exec2 $VEID \
&nbs p; "sed -i -e 's/daemon\\ klogd/passed\\ klogd\\ skipped/' \
&nbs p; &nbs p; &nbs p; -e 's/killproc\\ klogd/passed\\ klogd\\ skipped/' \
&nbs p; &nbs p; &nbs p; &nbs p; /etc/init.d/syslog; exit 0"
...
# Disable fsync() in syslog
$VZCTL exec2 $VEID \
&nbs p; "sed -i -e 's@\\\([[:space:]]\\\)\\\ (/var/log/\\\)@\\\1-\\\2@' ; \
&nbs p; &nbs p; &nbs p; /etc/syslog.conf; exit 0"
Reducing logical volume
Thu, 07/03/2008 - 09:56 — sandipI've had to reduce the logical volume that was alloted for mysql data from 8GB to 4GB, which was a breeze with e2fsadm available for lvm1 on RHEL-3 .
Stop the running serivces using the volume:
# service httpd stop
# service mysqld stop
e2fsadm will reduce the filesystem and then the logical volume.
# umount /mnt/lv-mysql
# e2fsadm -L -4G /dev/hdb2-vg00/lv-mysql
# mount /mnt/lv-mysql
Check with df, which should now show the new volume size:
$ df -h /mnt/lv-mysql
Filesystem Size Used Avail Use% Mounted on
/dev/hdb2-vg00/lv-mysql 4.0G 531M 3.3G 14% /mnt/lv-mysql
Start the running serivces using the volume:
# service httpd start
# service mysqld start
Note: e2fsadm is not available in lvm2 and will need to reduce in two steps:
1. Reduce the filesystem residing on the logical volume.
2. Reduce the logical volume.
# resize2fs /dev/vg0/lv0 4G
# lvreduce -L -4G /dev/vg0/lv0
- sandip's blog
- Login or register to post comments
ffmpeg with mp3 encoder support on Ubuntu Dapper
Wed, 07/02/2008 - 00:26 — sandipThe default install of ffmpeg on Ubuntu Dapper does not come with support for encoding mp3. I had to get the source and re-compile with mp3 support using lame as the encoder.
Make sure you have multiverse and universe enabled.
$ sudo apt-get build-dep ffmpeg
$ sudo apt-get install liblame-dev libfaad2-dev libfaac-dev libxvidcore4-dev liba52-0.7.4 liba52-0.7.4-dev libx264-dev
$ apt-get source ffmpeg
$ cd ffmpeg-*/
$ ./configure --enable-gpl --enable-pp --enable-pthreads \
&nbs p; --enable-libogg --enable-a52 --enable-dts \
&nbs p; --enable-dc1394 --enable-libgsm --disable-debug --enable-mp3lame \
&nbs p; --enable-faad --enable-faac --enable-xvid --enable-x264
$ make
$ sudo make install
Password Less SSH LOGIN
Thu, 06/26/2008 - 19:55 — manojThe main idea behind having a Password Less SSH LOGIN is to be more secure over the internet.
The idea comes from encryption. A set of Public and Private Keys are generated.
The public key stays on the serve rand the private key stays with the user. Only they private key can talk to the public key.
The user needs to upload the public key to the server on
~/.ssh folder and name the file as authorized_keys2
To get the keys working make sure the folder permissons are set correct.
chmod 700 ~/.ssh
chmod 644 ~/.ssh/authrozied_keys2
- manoj's blog
- Login or register to post comments
- Read more