Using md5 checksum to check for integrity of your large uploaded/downloded file

Have you ever downloaded/uploaded a file from/to another computer and wanted to verify the integrity of the file to make sure it is not corrupted. The obvious way is to compare the file size of the original final and the copied file. However there are many ways that this number could mislead you. 

Just to give two examples, in some cases the program you use to download/upload the file can fail to fill in all the data and just pad the file to the correct size.  Hardware errors such as disk and memory issues can cause corruptions too that won't effect the file size. So how do you make sure your file is not corrupted and check the integrity of your downloaded/uploaded file.

On Linux/Unix you can use md5sum.  The way to use it is to simply run :

md5sum [yourfile]

This prints out something like :

16295afa0087ef75f33751cf003da993  [yourfile]

You will need to run the above command on both the origin of the file and it's destination and compare the digital fingerprint of the file printed. For unique files that fingerprint will be the same.

A lot of websites that let users download files ( specially large files which have a higher chance of getting corrupted in transit ) will provide checksums for their files which you can compare against your when you download is done.


Fixing "authentication is required to set the network proxy ..." on Redhat/REL/OEL

Whenever i started  a vncsession i would get an popup window stating :
authentication is required to set the network proxy used for downloading packages.  An
application is attempting to perform an action that requires privileges.
Authentication as the super user is required to perform this action" and asking
for the root password.

I didn't have the root password for this machine and hitting cancel would just bring back the pop-up in a few minutes. After googling here is the best way i found to fix this problem:

From a terminal window run "gnome-session-properties" and un-check "PackageKit
Update Applet"

Finally restart your vncserver and the issue should be gone.




Fixing "Firefox is already running" error in Linux

If you are on Linux and you get the following error when trying to start Firefox, read on for a solution:

Firefox is already running, but is not responding. To open a new window, you must first close the existing Firefox process, or restart your system.


This error usually is not solvable with killing the Firefox process, since you won't find one in the list of the current processes.

So how do we get around it?

First, you need to go to your profile directory.
  • cd  ~/.mozilla/firefox/[your_profile]
Then delete the following two files :
  • rm lock
  • rm .parentlock
You should be able to open Firefox now.

If you have this problem occurring often like me, put the above command in a shell script for more convenience.

How to combine find and zip to compress WebLogic ADR directories

Weblogic Server has an ADR folder containing a sub directory called incident. This directory holds one directory for each incident that happens during an application lifetime.

Each of these individual incident folder can be several Mega Bytes so i use the following to zip them up and delete them. I set it as a cron to run every 5 minutes.

find /MW_HOME/user_projects/domains/my_domain/servers/AdminServer/adr/diag/ofm/apps/myapp/incident  -iname "incdir_*" -type d -exec sh -c 'zip -r {}.zip {}' \; -exec rm -rf {} \;









How to create a Java Thread dump

To create a java thread dump in Linux you must send a QUIT signal to your java process. JVM then catches that and prints the thread dump to standard output. If you are running your program from a script that has it's output directed to a file the thread dump will be written to that file obviously .

So first do we need to find the PID of our java program.

ps -ef | grep java

for example this could return :

lapps     3243  3065 21 Nov12 ?        08:01:50 java -Xms2048m -Xmx10g -XX:MaxPermSize=256m -Djava.awt.headless=true -XX:+UseParallelGC -XX:-UseGCOverheadLimit -classpath .:./test.jar:./lib/:./lib/* mypackage.org.TestApp

Now that we have 3243 as the PID, we simply send a QUIT signal to it.

kill -QUIT 3243

How to export query results from Oracle SQL Developer tool

So you ran a query in Oracle SQL Developer and it returned many rows. You would like to take this data and export it to a excel , CSV,  PDF or HTML file for further processing and easier navigation. You can achieve this by following these steps:


  1. SQL Developer usually return a limited number of rows, to get all rows go to the last returned row and press Ctrl + End. This will fetch all rows.
  2. Now Select all your data by highlighting it.
  3. Right click on your selection and select Export Data and finally choose a file format.
  4. Give your file a name and location and confirm the export operation.


Kill connections to an Oracle Schema


You can kill all connections by running the code below. Just Replace SCHEMA with your schema name.

declare str varchar2(100);
begin
for SES in (select sid,serial# from v$session where username='SCHEMA'  )
loop
str := 'alter system disconnect session '|| '''' || to_char(SES.sid) ||','||to_char(SES.serial#)||'''' || ' ' || 'immediate';
execute immediate str;
end loop;
end;


To kill a single connection, first find the connection by running:

select * from v$session;

Then run:

alter system kill session 'sid,serial#';

where sid and serial# are extracted from your first query of v$session above.

How to run sqlplus


To run sqlplus you need 3 env var set. Set them as follows if they are not set already. ( you can check if they are set by doing "echo $ORACLE_SID" for example to see if your SID is set. )

export ORACLE_HOME=<your Oracle Home>
export PATH=%ORACLE_HOME%\bin;%PATH%
export ORACLE_SID=<your SID>

Then run the following at the command line to start sqlplus.
sqlplus /nolog

This starts sqlplus with no user logged in.

How to export a schema in Oracle 11g

First make sure your ORACLE_SID,  PATH and ORACLE_HOME Env. variables are set. If not set them like below :
export ORACLE_HOME=<your Oracle Home>
export PATH=%ORACLE_HOME%\bin;%PATH%
export ORACLE_SID=<your SID>

Then run the following command from the command line:

expdp system/system_password@sid schemas=Schema_Name dumpfile=Schema_Name.dmp

Convert Timestamp to Date or Date to Timestamp online

This webpage has an applet that does the job and more :
http://www.ewert-technologies.ca/home/html/timestamp_converter.html

If you like a non-applet solution try : http://timestamp-to-date.com/ or the best one out there in my opinion http://www.epochconverter.com/

Get Current Time or Date of an Oracle DB


Note: This is on Oracle DB

To get the server Date:
SELECT sysdate FROM dual;
This will give you the system date in this format, Ex: 18-AUG-09

To get the server TimeZone:
SELECT sessiontimezone FROM dual;
This will give you the system timezone in this format, Ex: Asia/Calcutta

To get the server time:
SELECT systimestamp FROM dual;
This will give you the system time in this format,
Ex: 18-AUG-09 04.49.43.648480000 AM -07:00

How to clear the memory cache in Linux

sudo sh -c "sync; echo 3 > /proc/sys/vm/drop_caches"

How to findout who locks your Oracle DB user


select USERID,
         userhost,
         decode(returncode,01017,'Login Error','Acount Locked') "ISSUE",
         spare1,
         TO_CHAR ( CAST(
                                   ( FROM_TZ(
                                                     CAST(
                                                               TO_DATE(
                                                                              TO_CHAR( ntimestamp# , 'DD/MM/YYYY HH:MI PM'),
                                                                              'DD/MM/YYYY HH:MI PM'
                                                                            )
                                                                AS    TIMESTAMP
                                                             ) ,
                                                      'GMT'
                                                   ) AT LOCAL
                                    )
                                    AS TIMESTAMP)
                                  , 'DD/MM/YYYY HH:MI PM')  "Time",
           sqltext,
           comment$text from SYS.aud$
           where ( returncode=1017 OR returncode=28000 )
           order by ntimestamp# desc ;



How to delete records older than 7 days from sys.aud$

delete from sys.aud$ where trunc(NTIMESTAMP# ) < trunc(sysdate - 7);

you can change the number 7 above to any number of days you like.

Global search and replace in vi or vim

To perform a global search and replace in vi, use the search and replace command in command mode ( press Esc to enter command mode )


:%s/search_string/replacement_string/g