Thursday, August 31, 2006

Creating a rc3.d Script

One of my task for the day was to automate Jira that,
I have discussed here, By way of starting of Automatically
everytime the server is rebooted.

Previously I would start it by way of

I was told to create a script that could be added
to rc3.d (runlevel 3)

To do this you will need to name your script either with K or S
K - Kill a Process
S - Start a Process

and you will have to copy the script like say in my case,
I wanted the script to start everytime the server reboots

So I had given it

and this was copied to /etc/rc3.d, by doing this it will
create a link to /etc/rc.d/init.d/

Below is the script that starts jira by way of

To Start
/etc/rc.d/init.d/ start

To Stop
/etc/rc.d/init.d/ stop

# Run-level Startup script for the Jira Instance and Listener
# chkconfig: 345 91 19
# description: Startup/Shutdown Jira listener and instance
export JAVA_HOME=/usr/java/jdk1.5.0_06/
# if the executables do not exist -- display error
if [ ! -f $JIRA_HOME/bin/ -o ! -d $JIRA_HOME ]
echo "Jira startup: cannot start"
exit 1
# depending on parameter -- startup, shutdown, restart
# of the instance and listener or usage display

case "$1" in
# Jira listener and instance startup
echo -n "Starting Jira: "
touch /opt/Jira/jira.lock
echo "OK"
# Jira listener and instance shutdown
echo -n "Shutdown Jira: "
rm -f /opt/Jira/jira.lock
echo "OK"
$0 stop
$0 start
echo "Usage: $0 start|stop|restart|reload"
exit 1
exit 0


Tuesday, August 22, 2006

How to install phpMyAdmin (a utility written in PHP for mySQL server adminstration) on Linux.

Written By Rick Nicholas

phpMyAdmin is a utility written in PHP which is intended to aid in the administration of a MySQL server, either locally, or over the WWW. It is maintained through the hard work and dedication of the folks at The phpMyAdmin project , and is currently available in 47 different languages.

Some of its current capabilities include the ability to create and drop databases, create , drop, and alter tables, execute SQL statements, delete, edit, and add fields, manage keys on fields, and manage privileges. In addition, it has the ability to export your data in a number of different formats. phpMyAdmin is an excellent tool and will make the life of any MySQL database administrator much more enjoyable.

This short tutorial assumes you already have Apache, MySQL, and PHP installed correctly and functioning, and will not cover those installations. Also, the machine being used for this example is running Fedora Core 1 , so your mileage may vary depending on your Linux distro of choice and how the above mentioned packages were installed, however, unless you did something strange, you should find most installs similar. Lastly, it assumes you can use a text editor for basic editing tasks.

So lets get started !


First things first, we need to get the latest version of phpMyAdmin, at the time this tutorial was written the latest stable version was 2.5.5-pl1 , and you can get it at;

The phpMyAdmin Home Page

Grab the download, then grab a terminal window and do the following;

Change to the directory where you saved the downloaded file , such as;

$cd mydownloads

Cool, now we need to move the file to the root directory of your Apache webserver, which is usually /usr/local/apache/htdocs , also, root usually owns the Apache directory structure so you'll need to do the rest as root, so;



Now, lets move the file to where we need it;

#mv phpMyAdmin-2.5.5-pl1.tar.gz /usr/local/apache/htdocs

Done, now make the Apache root directory your working directory;

#cd /usr/local/apache/htdocs

Cool, now lets unpack the file;

#tar -zxf phpMyAdmin-2.5.5-pl1.tar.gz

That will take a second, then, when the machine returns the prompt, do a directory listing;


You should see a new directory which has been created called phpMyAdmin-2.5.5-pl1 , assuming you do go ahead and get rid of the original file; #rm phpMyAdmin-2.5.5-pl1.tar.gz

Now, the new directory name is a bit long, and definatley not something you want to type in all the time, so lets make it easier;

#mv phpMyAdmin-2.5.5-pl1 phpmyadmin

Cool, now you've renamed the directory to something a little easier to remember, now make that your working directory;

#cd phpmyadmin

Configuration Now, what we need to do is edit the file so it works with your setup. So using vi, or whatever your favorite editor happens to be, open , find the following lines, and edit them as appropriate for your setup;

$cfg['PmaAbsoluteUri'] = ''; (Default)

$cfg['PmaAbsoluteUri'] = ''; (Edited)
$cfg['Servers'][$i]['user'] = 'root'; (Default)
$cfg['Servers'][$i]['user'] = 'your_MySQL_root_user'; (Edited)
$cfg['Servers'][$i]['password'] = ''; (Default)
$cfg['Servers'][$i]['password'] = 'your_password'; (Edited)

Thats it, save the file and close it.

Now, lets see if it works, open a browser and point it to phpMyAdmin by using your site info such as, or, localhost/phpmyadmin if you are only working locally. If all is well you should see the welcome screen for phpMyAdmin !, if you don't, then check your logs and remember, Google is your friend. If you see a page full of PHP errors, make sure you used the correct username and password when you edited the lines mentioned above.

Now, knowing what this cool program is capable of, its probably not something you want just anyone to be able to access, luckily we can take care of that very easily using Apache 's authentication process, so lets do it !

Still as root make a directory to store the password file we will be creating;

#mkdir /usr/local/apache/passwd

Now, lets create the file and add an allowed user;

#/usr/local/apache/bin/htpasswd -c /usr/local/apache/passwd/authpass myphp

htpasswd will prompt you for the password you would like to assign to this user, once entered, it will create the file authpass and populate it with the information for the user called myphp .

You can use whatever names you like, this is only an example.

Now the final step, change to your Apache configuration directory;

#cd /usr/local/apache/conf

And again using your favorite editor, open the file named httpd.conf and find the following section;

Options FollowSymLinks
AllowOverride None

Directly under this section add the following (assuming you used the names from the example above);

AuthType Basic
AuthName "myphp"
AuthUserFile /usr/local/apache/passwd/authpass
Require user myphp

Thats it, save the file and close it, then restart Apache by issuing the following command

#/usr/local/apache/bin/apachectl restart

Perfect, now fire up your browser again and point it back to your phpMyAdmin site, this time you should be prompted for a username and password before being allowed access to the site. Enter the required information, and you are in business !.

That brings us to the end of this tutorial, hopefully you found this information helpful, and Good Luck !

Saturday, August 19, 2006

Bash Script for downloading and converting .flv files from YouTube to Mpeg

Make sure you have ffmpeg installed to be able to convert your .flv files to .mpg

Heres the script,

[root@localhost youtube]# cat

BASEURL="" ; read -p "YouTube URL? " ORIGURL ; read -p "Desired path/filename? " OUTFILE

wget -c -S -O ${OUTFILE}.flv ${BASEURL}`curl -s ${ORIGURL} | grep player2.swf | cut -f2 -d? | cut -f1 -d\"` && ffmpeg -i ${OUTFILE}.flv -ab 56 -ar 22050 -b 500 -s 320x240 ${OUTFILE}.mpg && exit 0
[root@localhost youtube]#

Heres the Output,

[root@localhost youtube]# sh
YouTube URL?
Desired path/filename? /ram/youtube/b
=> `/ram/youtube/b.flv'
Resolving,,, ...
Connecting to||:80... connected.
HTTP request sent, awaiting response...
HTTP/1.1 303 See Other
Date: Fri, 18 Aug 2006 20:22:36 GMT
Server: Apache
Set-Cookie: VISITOR_INFO1_LIVE=Cz8iYphwJaw; path=/;; expires=Mon, 15-Aug-2016 20:22:36 GMT
Cache-Control: no-cache
Connection: close
Content-Type: text/html; charset=utf-8
Location: [following]
=> `/ram/youtube/b.flv'
Connecting to||:80... connected.
HTTP request sent, awaiting response...
HTTP/1.0 200 OK
Connection: close
Content-Length: 1139071
Last-Modified: Sun, 18 Dec 2005 03:59:00 GMT
ETag: 11617f-43a4de84
Cache-Control: no-cache
Content-Type: video/flv
Date: Fri, 18 Aug 2006 20:23:31 GMT
Server: lighttpd/1.4.8
Length: 1,139,071 (1.1M) [video/flv]

100%[====================================>] 1,139,071 11.63K/s ETA 00:00

02:16:35 (11.36 KB/s) - `/ram/youtube/b.flv' saved [1139071/1139071]

ffmpeg version 0.4.9-pre1, build 4718, Copyright (c) 2000-2004 Fabrice Bellard
built on Dec 16 2005 05:33:18, gcc: 4.0.1 (4.0.1-5mdk for Mandriva Linux release 2006.0)
Input #0, flv, from '/ram/youtube/b.flv':
Duration: N/A, bitrate: N/A
Stream #0.0: Audio: mp3, 22050 Hz, mono
Stream #0.1: Video: flv, 320x240, 6.00 fps
Output #0, mpeg, to '/ram/youtube/b.mpg':
Stream #0.0: Video: mpeg1video, 320x240, 5.00 fps, q=2-31, 500 kb/s
Stream #0.1: Audio: mp2, 22050 Hz, mono, 56 kb/s
Stream mapping:
Stream #0.1 -> #0.0
Stream #0.0 -> #0.1

Wednesday, August 09, 2006

Installing Jira and Perforce Plugin

This is my first assignment after a very long time.

Jira is a Bug Tracking tool similar to bugzilla.

Since we are using Perforce which is similar to CVS .

We are planning to Integrate Jira with Perforce Plugin to be able to track versions.

Heres what I have done to get this running :

Jira Installation and Perforce Plugin Installation:

Jira Installation
1) Check if Java is Installed - ps -ef grep java

2) Export JAVA_Home to where you are Installing Jira
$cd /opt/Jira
$export JAVA_HOME=/usr/java/jdk1.5.0_06/

3) Download atlassian-jira-standard-3.6.3-standalone.tar.gz

4) Untar it in /opt/Jira
$tar -zxvf atlassian-jira-standard-3.6.3-standalone.tar.gz

5) By Default Jira runs on 8080 port you can change it to whatver port you want.
For eg. In our case we have changed it to 8090

Change the below two settings in
1) Server Port "8005"
2) Connector Port "8090" <---- Port Jira Connects

6) Now Start Jira

To Stop Jira

7) Now Point your Browser to

8) This will ask you some some questions to complete Jira Installation and a next will add a Jira Administrator.

To Obtain a Evaluation License Key (Below Link)

Perforce Plugin Installation :

Note - Please make sure you have Installed Perforce command line tool before you Install Perforce Plugin for Jira.
You can find the P4 command Line tool from the below link

1) Download

2) Unzip it in /opt/Jira

3) Copy the below files from /opt/Jira/atlassian-jira-perforce-plugin-1.1.5
- atlassian-jira-perforce-plugin-1.1.5.jar
- p4package-rev13.jar

To - /opt/Jira/atlassian-jira-standard-3.6.3-standalone/atlassian-jira/WEB-INF/lib

4) Edit from /opt/Jira/atlassian-jira-perforce-plugin-1.1.5

Most of the Information regarding p4port , User, Pass were all Hashed in my case as I did not have the Info.

I had also hashed the Logging Entries.

5) Now copy
To - /opt/Jira/atlassian-jira-standard-3.6.3-standalone/atlassian-jira/WEB-INF/classes

6) I have not copied any Licence for Plugins as per there Docs.

7) Restart Jira
TO see if plugin is Installed Login to Jira Web based Under Administration section > System > Plugins

It Should have Installed 7 Modules.

rm command - Argument List too long

Some days back I had problems deleting n no of files in folder.

while using rm command it would say

$rm -f /home/sriram/tmp/*.txt
-bash: /bin/rm: Argument list too long

This is not a limitation of the rm command, but a kernel limitation on the size of the parameters of the command. Since I was performing shell globbing (selecting all the files with extension .txt), this meant that the size of the command line arguments became bigger with the number of the files.

One solution is to to either run rm command inside a loop and delete each individual result, or to use find with the xargs parameter to pass the delete command. I prefer the find solution so I had changed the rm line inside the script to:

find /home/$u/tmp/ -name '*.txt' -print0 xargs -0 rm

this does the trick and solves the problem. One final touch was to not receive warnings if there were no actual files to delete, like:

rm: too few arguments

Try `rm --help' for more information.

For this I have added the -f parameter to rm (-f, –force = ignore nonexistent files, never prompt). Since this was running in a shell script from cron the prompt was not needed also so no problem here. The final line I used to replace the rm one was:

find /home/$u/tmp/ -name '*.txt' -print0 xargs -0 rm -f

You can also do this in the directory:
ls xargs rm

Alternatively you could have used a one line find:

find /home/$u/tmp/ -name ‘*.txt’ -exec rm {} \; -print

Thanks to him