Wednesday, February 4, 2009

Fedora 10 Codecs with MPlayer

If you just need MP3 support, you might want to start here. Otherwise, I recommend using RPMFusion.org's MPLayer package with the codecs found at http://www.mplayerhq.hu.

First, install RPM Fusion's free and nonfree YUM repositories. For detailed information about installing RPM Fusion, see: http://rpmfusion.org/Configuration

su -c "rpm -Uvh http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm"

su -c "rpm -Uvh http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm"

Next, install MPlayer from RPMFusion.org.

su -c "yum install mplayer gnome-mplayer gnome-mplayer-common mencoder"

Now, visit the MPlayer Codecs Directory and download the latest 'All' tarball.

wget http://www.mplayerhq.hu/MPlayer/releases/codecs/all-20071007.tar.bz2

Next, prepare the codecs folder. MPlayer from RPMFusion.org will use /usr/lib/codecs.

su -c "mkdir -p /usr/lib/codecs"

Other media players like Xine and avifile might use /usr/lib/win32, so create a symlink.

su -c "ln -s /usr/lib/codecs /usr/lib/win32"
ls -l /usr/lib/win32
lrwxrwxrwx 1 root root 15 2008-05-24 08:02 /usr/lib/win32 -> /usr/lib/codecs

Finally, extract the contents of the tarball and copy all files to /usr/lib/codecs.

tar -xjvf all-20071007.tar.bz2
su -c "cp -a all-20071007/* /usr/lib/codecs/"

See the MPlayer(1) man page for /usr/bin/mplayer usage.

man 1 mplayer

Compile Apache on Fedora


Below is a walk-through for compiling Apache 2.2 on Fedora 9. First, download and unpack the source tarball from Apache.org. As of August 2008, the latest version of Apache is 2.2.9 (httpd-2.2.9.tar.gz)

tar -xzvf httpd-2.2.9.tar.gz
cd httpd-2.2.9

Next, configure the source for build. You can provide configure with --help to see the large list of options. The example below enables mod_rewrite, mod_cache, mod_mem_cache and mod_ssl as shared modules in /opt/apache2/modules. Change --prefix to adjust your install PREFIX and adjust the configure options to suit your needs.

./configure --prefix=/opt/apache2 --enable-rewrite=shared --enable-cache=shared --enable-mem-cache=shared --enable-module=so

Now, build and install Apache.

make
sudo make install

Your Apache configuration will be in /opt/apache2/conf and you can control Apache with /opt/apache2/bin/apachectl. Refer to the Apache documentation for more details.

Tuesday, February 3, 2009

How to Connect to a VNC Server Using SSH

Need to connect to a VNC server behind a firewall that only allows SSH traffic? With SSH access to the VNC server, you can tunnel the VNC traffic through an SSH connection. This will encrypt your VNC traffic through an SSH tunnel.

To begin, SSH to the VNC server and forward the local client's 5904 TCP port to the VNC server's port 5901.

client$ ssh user@vncserver.mydomain.com -L 5904:*:5901

Next, In a new window, direct vncviewer to your localhost 5904 port and the traffic will be forwarded to your VNC server's port 5901.

client$ vncviewer localhost:5904

If you get any errors, be sure that your client's firewall is not blocking localhost's port 5904.

client$ su -c "iptables -L"

10 Tips for Writing Efficient Bash Scripts

Bash is the default command line interface for many Linux distributions and a powerful scripting language. Here are some suggestions that will keep your Bash scripts efficient and lean. Feel free to comment with your own suggestions.

  1. Avoid Full Paths to Bash Builtins

    Bash has many builtins that can be used instead of calling external commands. You should leverage the builtin commands whenever possible since it avoids calling a subcommand from the system.

    Since Bash has builtins for some commands found in /bin and /usr/bin (such as echo), avoid using the full path for these commands and the builtin will be used.

    # avoid this
    /bin/echo "hello"

    Use the Bash builtin instead:

    echo "hello"

    Other bash builtins include: test, read, declare, eval, let pushd and popd. See the Bash man page for a full listing of builtins.

  2. Avoid External Commands for Integer Math

    Bash also provides builtins that can be used for integer arithmetic. Only use /usr/bin/bc if you need to do floating point arithmetic. Integer calculations can be made with these Bash builtins:

    four=$(( 2 + 2 ))
    four=$[ 2 + 2 ]
    let four="2 + 2"

  3. Avoid using Cat

    Tools like Grep, Awk and Sed will take files as arguments. There is rarely a need to use /bin/cat. For instance, the following is unnecessary:

    # avoid this
    cat /etc/hosts | grep localhost

    Instead, use Grep's native ability to read files:

    grep localhost /etc/hosts

  4. Avoid Piping Grep to Awk

    If using Awk, you can often eliminate the need for grep. Try not to pipe Grep to Awk:

    # avoid this
    grep error /var/log/messages | awk '{ print $4 }'

    Use Awk's native ability to parse text and save yourself a command.

    awk '/error/ { print $4 }' /var/log/messages

  5. Avoid Piping Sed to Sed

    Sed can take more than one command in a single execution. Avoid piping sed to sed.

    # avoid this
    sed 's/hello/goodbye/g' filename | sed 's/monday/friday/g'

    Instead, use sed -e or delimit the sed expressions with a semicolon (;)

    sed -e 's/hello/goodbye/g' -e 's/monday/friday/g' filename
    sed -e 's/hello/goodbye/g; s/monday/friday/g' filename

  6. Use Double Brackets for Compound and Regex Tests

    The [ or test builtins can be used to test expressions, but the [[ builtin operator additionally provides compound commands and regular expression matching.

    if [[ expression1 || expression2 ]]; then do_something; fi
    if [[ string =~ regex ]]; then do_something; fi

  7. Use Functions for Repetitive Tasks

    Break your script up into pieces and use functions to conduct repetitive tasks. Functions can be declared like so:

    function_name() {
    do_something
    return $?
    }

    Make your functions usable by more than one shell script by sourcing a functions file from the various scripts. You can source another file in Bash using the . builtin.

    #!/bin/bash
    . /path/to/shared_functions

    See the Bash man page, or my article on Bash functions for more information.

  8. Use Arrays Instead of Multiple Variables

    Bash arrays are very powerful. Avoid using unnecessary variables:

    # avoid this
    color1='Blue'
    color2='Red'
    echo $color1
    echo $color2

    Instead, use Bash arrays.

    colors=('Blue' 'Red')
    echo ${colors[0]}
    echo ${colors[1]}

    Check out my article on Bash arrays for more details.

  9. Use /bin/mktemp to Create Temp Files

    Need a temporary file? Use /bin/mktemp to create temporary files or folders.

    tempfile=$(/bin/mktemp)
    tempdir=$(/bin/mktemp -d)

  10. Use /bin/egrep or /bin/sed for Regex Pattern Matching

    Think you need Perl? Check out Sed or Egrep (grep -e) for regex pattern matching.

    # grep for localhost or 127.0.0.1 in /etc/hosts
    egrep 'localhost|127\.0\.0\.1' /etc/hosts

    # print pattern localhost.* in /etc/hosts
    sed -n 's/localhost.*/&/p' /etc/hosts

how-to-safely-uninstall-linux-when-dual-boot-installed-with-windows-xp

When asked to most of the users “How will you uninstall Linux when it is Dual Boot installed with Windows XP?” The common answers we got was “Start windows XP and format Linux Partition“. Well they were half correct, you do have to format the linux partition but what about the grub loader? The grub loader will still be showing you the option to boot Linux during the start up and by mistake if anybody goes for booting linux, the system will not find any linux on your machine and it will restart. so what can you do in this situation?

There is a simple procedure to uninstall or delete linux completely and safely by following a step by step procedure illustrated below and it is tested by me .

Requirements:


You need a windows 98 startup disk or windows XP installation CD.

How to do it:

1. Reboot your laptop with windows 98 start up disc or Windows XP CD and type the command “fixmbr”.

2. Above command will repair ur bootloader and rewrite ntldr which will replace grub loader of Linux and now you can see only Windows XP in the boot menu.

3. Now Boot up in Windows xp.

4. Go to Start > Control Panel > Administrative Tools > Computer Management

5. Go to Disk Management under “Storage”

6. Select your Hard Disk and then the linux partition.

7. Delete the linux partition this will delete linux and grub.

8. Thats it done now boot your laptop or desktop normally it will be booted by default in windows xp.

If you have any problem in the procedure given above leave a comment here…