Unix Bash Coloured Prompts
| Posted by watashii | Filed under UnixTo display coloured prompts upon user login (on Unix Bash shell, PuTTY client), perform the following modifications:
- Unix login and open the user’s profile in the home directory, eg /home/username/.profile
- In the .profile, add the following entry in a new line to execute the bash shell upon login, eg /usr/bin/bash
- The bash shell will refer to a .bashrc file. If its not there, create it, eg /home/username/.bashrc
- Add following entries in the .bashrc to enable the coloured prompt; showing the username, hostname and working directory:
# Colored Prompts
STARTGREEN='\[\e[0;32m\]';
STARTBLUE='\[\e[1;34m\]';
ENDCOLOR="\[\e[0m\]";
PS1="$STARTGREEN\u@\h$ENDCOLOR:$STARTBLUE\w$ENDCOLOR $ ";
Tags: bash, bashrc, color, profile, prompt
Unix Shell – Check If Directory Is Empty
| Posted by watashii | Filed under Programming, UnixHere is a simple unix shell command to check if a directory, $dir, is empty.
export $dir=/tmp/myfiles/
if [ "$(ls -A $dir)" ];
then
echo "$dir NOT Empty";
else
echo "$dir IS Empty";
fi
Tags: directory, empty, shell, unix
Unix LS Command With Colors… Without the —color Option
| Posted by watashii | Filed under Programming, Unix
Having command line text in colors makes things easier to read. For example the ls command for listing directories and files. In some Unix environments, the ls command may not support the –color option to let us do that (as it requires GNU ls). So how can we workaround this to add color to ls?
Here are my steps to make it happen. Note i’m no Unix guru, and I didn’t have time to perfect it.. but it gets the job done!
BIAR File Command Line Import – Bypassing Import Wizard
| Posted by watashii | Filed under BusinessObjects, Software, UnixThe command line to import the BusinessObjects Enterprise (XIR2 Unix) exported biar file can be done using the following command:
java -jar <BOBJE_HOME>/bobje/java/lib/InstallEntSdkWrapper.jar 'cms_name' 'admininistrator' 'admin_password' 'secEnterprise' <PATH_TO>/MyBiarFile.biar
[InstallEntSdkWrapper.main] Connecting to CMS Development as administrator
[InstallEntSdkWrapper.main] BIAR Imported Successfully
Tags: biar, BusinessObjects, import wizard
How to untar a gz file in Unix
| Posted by watashii | Filed under Unix
For a .gz file,
$ gunzip myfile.gz
For .tar.gz file,
$ gzip -dc myfile.tar.gz | tar xvf -
Tags: unix untar gz file
Exercise Your Idle System Doing Nothing
| Posted by watashii | Filed under Unix
Via Unix/Linux:
cat /dev/zero > /dev/null
or
cp /dev/zero /dev/null
Explaination:
/dev/null is basically a black hole (a special null file), anything written to it goes down the drain. Anything read from it will result in nothing returned. /dev/zero is basically the same as /dev/null when writing to it, however reading it will result in a continuous stream of zeros without EOF.
Tags: null, performance, unix, zero
Upgrading to WordPress 2.7 Coltrane
| Posted by watashii | Filed under Unix, WordPress
I have just gone through the tedious task of upgrading my WP from 2.5 to 2.7. What i’m looking forward to this is the WP Upgrader feature which I can upgrade WP directly via the Admin panel. This means I don’t need to manually move files in/out of my linux web server in the future. Of course i have to manually put 2.7 in the first place to do that!
Upgrade document is available here, below are my steps.
1) Backup all my file contents on web server.
tar -cvf - $WEBHOME/blog_dir | gzip -9 $WEBHOME/backup_dir/my_blog.tar.gz
2) Backup the mysql database. I used WP-DBManager plugin to help me do this. A single click and that’s it!
3) Deactivated all the plugins via admin panel.
4) Delete wp-admin and wp-includes directories on web server.
rm -rf $WEBHOME/blog_dir/wp-admin $WEBHOME/blog_dir/wp-includes
5) Download the new WP and place/replace all the files on web server.
6) Login to the admin panel and accept the database upgrade changes.
7) Activate the required plugins. If using the WordPress.com Stats plugin, I had to ‘transfer’ my old site stats to a new site, even though its the same site.
Tags: backup, coltrane, WordPress
Unix Split, Join & Validate Files
| Posted by watashii | Filed under Programming, UnixProblem

I have a large file.
How can i split it into multiple parts, then join it back together later?
How do i make sure my files don’t corrupt?
I am using Unix.
$ ls -l *.pkg
-rw-rw-r-- 1 watashii watashii 648773362 Nov 28 18:01 largefile.pkg
Splitting the files
The following Unix command splits a large file into 50MB (52,428,800 bytes) pieces. The output is a list of files named xaa, xab etc
$ split -b 52428800 largefile.pkg
$ ls -l x*
-rw-rw-r-- 1 watashii watashii 52428800 Nov 28 18:01 xaa
-rw-rw-r-- 1 watashii watashii 52428800 Nov 28 18:01 xab
...
-rw-rw-r-- 1 watashii watashii 19627762 Nov 28 18:01 xam
Joining the files
To join the files together, we simply use the cat command over each file in ascending order:
$ cat x* > mergedlargefile.pkg
Validating the files
To validate the files, below are some suggestions. File compare it, diff it, run a checksum to compare it.
$ ls -l *.pkg
-rw-rw-r-- 1 watashii watashii 648773362 Nov 28 18:01 largefile.pkg
-rw-rw-r-- 1 watashii watashii 648773362 Nov 28 18:13 mergedlargefile.pkg
$ cmp largefile.pkg mergedlargefile.pkg
$ cksum largefile.pkg
3332922138 648773362 largefile.pkg
$ cksum mergedlargefile.pkg
3332922138 648773362 mergedlargefile.pkg
$ diff largefile.pkg mergedlargefile.pkg
Tags: join, merge, split, unix
SSH Passwordless Authentication
| Posted by watashii | Filed under Software, Unix
This post shows how to use PuTTY (Windows) to login to a remote server (UNIX) over SSH without password.
Tags: authentication, passwordless, putty, ssh, unix
How to Change Default Homepage in Tomcat
| Posted by watashii | Filed under Software, UnixWhen browsing to a Tomcat’s webserver, at the root URL over the default port 8080, it usually shows the default jsp homepage as pictured above.
http://localhost:8080
So how can I update / modify, or remove this page?
You might think changing the jsp page at [$CATALINA_HOME/webapps/ROOT/index.jsp] is all you need to do. This is where i found out its not the case! The page contents are compiled within the ROOT web application servlet. To make Tomcat reference the jsp page instead, we need to remove this servlet from being compiled.
Locate the ROOT web application’s config file at [$CATALINA_HOME/webapps/ROOT/WEB-INF/web.xml], and simply comment out the following code fragment:
<!-- Comment this section so I can change the default index.jsp homepage
<servlet>
<servlet-name>org.apache.jsp.index_jsp</servlet-name>
<servlet-class>org.apache.jsp.index_jsp</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>org.apache.jsp.index_jsp</servlet-name>
<url-pattern>/index.jsp</url-pattern>
</servlet-mapping>
-->
This will disable the index_jsp servlet. Now when you restart the Tomcat web application server, it should compile and load the default [$CATALINA_HOME/webapps/ROOT/index.jsp] page instead.

