Category: Linux

Replace text in many files using perl

Last night, I have several files containing the same text and I wanted that text to be replaced. I used perl one liner to do the job and I thought it may be useful for someone else so here it is:

perl -e “s/text/replacewith/g;” -pi.orig *.txt

This is going to save a backup of the files with .orig extension and do the replace. If you don’t want backup, then remove the .orig from the line.

Also, if you want to replace text in all files in a directory, then use:

perl -e “s/text/replacewith/g;” -pi.orig $(find . -type f)

  • Share/Bookmark

Setup unixODBC on Linux for Oracle and Sybase

I have been working this week on configuring a Linux server to connect to Oracle and Sybase using unixODBC to be used by a System running on PHP.

So, I thought of sharing my /etc/odbc.ini and /etc/odbcinst.ini since I had a bit of hard time writing them. It may help someone who is trying to figure out how to connect using ODBC on Linux.

Packages Required on CentOS

httpd php unixODBC

Manually Install Oracle Instant Client 11.1 RPM Packages and Install Sybase ASE from the TGZ File.

For Oracle you need to copy all the libs to /usr/lib

cp /usr/lib/oracle/11.1/client/lib /usr/lib/

/usr/lib/oracle/11.1/client/lib

/etc/odbcinst.ini Contents:

[Oracle]
Description     = Oracle ODBC Connection
Driver          = /usr/lib/oracle/11.1/client/lib/libsqora.so.11.1
Setup           =
FileUsage =
CPTimeout =
CPReuse         =

[Sybase]
Description = Sybase ODBC Driver
Driver = /opt/sybase/DataAccess/ODBC/lib/libsybdrvodb.so
FileUsage = -1

/etc/odbc.ini Contents:

[Oracle]
Application Attributes = T
Attributes = W
BatchAutocommitMode = IfAllSuccessful
CloseCursor = F
DisableDPM = F
DisableMTS = T
Driver = Oracle
EXECSchemaOpt =
EXECSyntax = T
Failover = T
FailoverDelay = 10
FailoverRetryCount = 10
FetchBufferSize = 64000
ForceWCHAR = F
Lobs = T
Longs = T
MetadataIdDefault = F
QueryTimeout = T
ResultSets = T
ServerName = //serverip:port/dbname
SQLGetData extensions = F
Translation DLL =
Translation Option = 0
UserID =

[Sybase]
Driver = Sybase
Server = serverip
Port = serverport
Database = dbname

PHP Script to Test ODBC Connectivity:

<?php

$query = “select * from table_name”;

$conn = odbc_pconnect(“DSN”, “username”, “password”);

if(!$conn) die(“Connection failed”);

if($result = odbc_exec($conn, $query)) {

echo “Query returned : ” . odbc_num_rows($result) . “rows”;

odbc_result_all($result);

}

?>

  • Share/Bookmark

Simple Webserver in Python

Sometimes I need a simple webserver for serving files for my kickstart installations. I have found a simple solution:

python -m SimpleHTTPServer 80

This creates a simple Webserver on port 80 and its root path is the directory it ran from. For more details about it, visit python docs: http://docs.python.org/library/simplehttpserver.html

  • Share/Bookmark

Dealing with winmail.dat in Linux

Today, I have received an email from a Windows User using Outlook and he was using Rich Mode instead of plain text or html. Thus, when sending attachments, it comes as winmail.dat file. Winmail.dat file is like an archive file contains all the attachments, thus it can be extracted. There is a wonderful tool called ytnef which I used to extract the attachments from the email I got.

A simple how to use:

  1. Save the winmail.dat to your home directory, probably a temp folder in your home directory.
  2. Open the terminal and change the directory to the place where the winmail.dat is saved.
  3. Run the command:
    ytnef -f . winmail.dat
    It will save the files in the current directory.
  • Share/Bookmark

Download RealMedia Files and Convert them to MP3 in Linux

This morning I woke up and one of Fayrooz songs was playing in my head! I thought of Downloading all of them. So, I found a good website (http://www.6rb.com/music/Singers-13/525.html) with many Fayrooz songs ( I can’t say all because I don’t know them all). Anyway, that’s how I downloaded the Songs and converted them to MP3

Read more »

  • Share/Bookmark

Ubuntu DVD Release

The reason that made me look away from Ubuntu was due to the CD release targeting desktop users and leaving developers, and when I install Ubuntu, I have to do tons of Downloads to make my desktop ready! Ubuntu had a DVD release that got almost all the software I require and it will be a minimal download for me. I never knew about it!! So, I downloaded the Ubuntu DVD iso image, and I will be using it on my laptop, My desktop stays multi-booting FreeBSD, Slackware and Fedora.
Link to Ubuntu DVD Release: http://cdimage.ubuntu.com/releases/intrepid/release/

  • Share/Bookmark

Clone Disks using Linux dd

Yesterday, Mohammed my friend asked me on how to clone disks since he remembers me cloning disks using Linux over Network. I thought of writing the way I do it so everyone could benefit from it.

Read more »

  • Share/Bookmark

Choosing a Linux Distro — Mandriva is a good choice

I formated my laptop after experimenting with Mac OSX, I wanted a good distro to be used on my laptop. Keeping in mind that I have a very good experience with Unix like systems, Especially Linux and FreeBSD.
On my desktop, I have been dual booting Slackware Linux and FreeBSD. I used to use Fedora on my laptop before experimenting with Mac.
Since I experiment a lot with my laptop, I wanted a distro that got everything on its DVD, like Slackware or Fedora. For Slackware, I will require to do lots of Customizations which I don’t have time for on my laptop. Fedora is perfect, however, I hate those almost daily updates which are huge in size. Few Months ago, I have tried Mandriva, and I really liked it, however, I had to do some experiments and I formatted on my older laptop. Today, I have installed Mandriva.

The Installation:

It’s really nice, very fast and responsive.. It gave me the option to copy the DVD to the hard drive, it really improves the install time!

Updates:
After a full install, the whole update for my all packages was only about 530MB to download! Unlike Fedora that required 1.2GB of downloads!!

Overall:
Mandriva is a very good Distro, everything comes on the DVD. Giving the option to have a full running system to do your job even without internet connection. Unlike Ubuntu!

  • Share/Bookmark

Change file names case from upper case to lower case

A friend of mine asked me a good question, he copied files from a Windows Partition to his Linux partition, and some of the files had upper case letters. He wanted to convert all file names to lower case, and they were lots of files, thus he didn’t want to change them one by one. He asked me how to do it, and I helped him out.
Its a simple line to convert all files from upper case to lowercase

for i in `ls`; do old=$i; new=`echo $i | tr [:upper:] [:lower:]`; mv $old $new; done;

And all files in the same directory are converted to lower case.

  • Share/Bookmark

Improve Laptop Battery life in Linux

Since I bought my Laptop HP Pavilion DV6353, I couldn’t get more than 2 hours using its battery. When I upgraded to Fedora 10, My battery lasts for only an hour and half. So I decided to increase my battery life. After long time of hours reading and reading about saving power, I came up with a list of stuff that I have done and improved my battery life to almost 3 hours!!

Read more »

  • Share/Bookmark

Keep your Linux Workstation/Server time accurate using “rdate”

Last night, I was using my Laptop until I drained the battery. Today, I plugged in the power and started using it. I found that the time is missed up!! It got yesterdays date and time of my last use! So I decided to sync my Laptop clock to NTP server to keep my time accurate.

rdate uses NTP to get time from network and set it or print it on the workstation/server.

Read more »

  • Share/Bookmark

WordPress Themes