Friday, June 27, 2008

Set Terminal Title

If you want the Terminal window title to be set automatically to the remote zone you have logged into, add this to your .bashrc file on the remote machine.


# Terminal settings
PS1="[\u@\h \W]# "

if [ -n "$PS1" ]; then
echo -n -e "\033]0;`hostname`\007"
fi

Saturday, June 14, 2008

TNSNAMES.ORA file

TNSNAMES.ORA is a configuration file that defines databases addresses for establishing connections to the database. It resides in ORACLE HOME\NETWORK\ADMIN directory. Below is the sample entry in TNSNAMES.ORA

<addressname> =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(Host = <hostname>)(Port = <port>))
)
(CONNECT_DATA =
(SERVICE_NAME = <sid>)
)
)

Wednesday, June 11, 2008

Read data from a file in perl

Below is the sample perl script, if you want to read some data from a file and pass it to as a argument in your perl script.

In my case, I have some object ids in a file and for each id I have to run oocheck command.

#!/usr/local/bin/perl

open FILE, "testoids" or die $!;

while ()

{

chomp $_;

systemCmd("oocheck -id $_");

}

close(FILE);

sub systemCmd {

my($cmd) = @_;

print("$cmd\n");

(system($cmd) == 0) || die ("cmd $cmd failed");

}

Friday, June 6, 2008

Linux time command

The time command runs the specified program command with the given arguments. When command finishes, time writes a message to standard output giving timing statistics about this program run.

See below example:

[vishnu@solaris /mnt/usr/vishnu] time myProgram arg1

real 24m10.951s

user 6m2.390s

sys 0m15.705s

[vishnu@solaris /mnt/usr/vishnu]

Above command outputs the time taken by myProgram.

· real - Elapsed time from beginning to end of program

· user - time used by the program itself and any library subroutines it calls

· sys- time used by the system calls invoked by the program (directly or indirectly)

Thursday, May 15, 2008

Forgot to mention subject in mail ???

Forgot to mention subject, while writing an official mail ??

Yes.... It's a concern for all.... A mail without a subject brings a bad impression on us.

To avoid this just follow the simple steps mentioned below and see the result


Steps:
1. Open your outlook

2. Press Alt+F11. This opens the Visual Basic editor and then Press Ctrl+R which in turn open Project-Project 1 (left side)

3. On the Left Pane, one can see "Microsoft Outlook Objects" or "Project1", expand this. Now one can see the "This Outlook Session".

4. Double click on "ThisOutLookSession". It will open up a code pane on the right hand side.

5. Copy and Paste the following code in the right pane. (Code Pane) and save it

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim strSubject As String
strSubject = Item.Subject
If Len(Trim(strSubject)) = 0 Then
Prompt$ = "Subject is Empty. Are you sure you want to send the Mail?"
If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check for Subject") = vbNo Then
Cancel = True
End If
End If
End Sub

6. Now whenever u try to send a mail without subject, which will raise a pop-up to remind you.

Wednesday, April 23, 2008

List only Directory/Files in ls command

ls -l (include both directories and files)

ls -l | grep -v ^d (include only files in listing)

ls -l | grep ^d (include only directories in listing)

Tuesday, April 22, 2008

Read latest file in vi editor

In my daily routine on solaris box, i have to read the latest file in vi. For this i have to run below 2 commands:

ls -ltr
vi filename

I get the latest file name with ls -ltr command (last file in the list) and then vi to open this file.

I was sick of using 2 commands for this simple operation, so i thought of using a single command using combination of commands; following are the commands which I used for this operation:

vi `ls -ltr|tail -1|awk -F" " '{print $9}'` (includes directory listing)
vi `ls -ltr|grep -v ^d|tail -1|awk -F" " '{print $9}'` (ignores directory listing)
or
vi `ls -ltr|tail -1|cut -d":" -f2|cut -d" " -f2` (includes directory listing)
vi `ls -ltr|grep -v ^d|tail -1|cut -d":" -f2|cut -d" " -f2` (ignores directory listing)


Thursday, April 3, 2008

Location of firefox cookies ?

All the firefox cookies are stored in cookies.txt at C:\Documents and Settings\Windows login/user name\Application Data\Mozilla\Firefox\Profiles\profile folder

Monday, March 31, 2008

Testplan plugin in Confluence WIKI

Recently in our organization, we started to use Confluence WIKI for documentation purpose. This wiki has a plugin called TestPlan. I liked this plugin very much as it allows us to maintain our test cases and get the test case execution status.
Below is the screenshot of sample testplan:





Below is the wiki markup for above sample:
{testplan:Release includeJiraLinks=false useFailMacro=false}
^Feature1
//This is comment
Test1
Test2
^Feature2
//This is comment
Test3
Test4
{testplan}

Wednesday, March 26, 2008

vi Examples

s/pat/text/ substitute 1st match of pat with text

s/pat/text/g substitute every match of pat with text

s/pat/text/n substitute the nth occurrence of pat with text

:%!sort or :1,$!sort sort current file

:5,10s/foo/bar/2 change the second occurrence of foo with bar on lines 5-10

:map g 1G map g to really run 1G

3J Join next 2 lines to current one

3,9m$ move lines 3 through 9 to the end of the file

ab w/o without when w/o is typed change to without

:?foo?,/bar/d delete from the reverse match of foo until the next match of bar

:g/{/,/}/< shift all lines between, and including, a "{" and a "}" left

:$-4,$d delete last five lines of buffer

:%s/^\(.*\) \(.*\)$/\2 \1/ swap everything before and after the first space

d'' delete from current position to line of last jump

Perl matches Perl

^Perl matches Perl at beginning of line

Perl$ matches Perl at end of line

^Perl$ matches Perl as the only word on line

^$ matches the empty line

^..*$ matches a line with at least one character

.* matches any string of characters including none

^[ ^I]*$ as above but line can also contain spaces and/or tabs(^I)

[pP]erl matches perl or Perl

[aA][nN] matches an, aN, An, AN

p[aeiou]g second letter is a vowel

i[^aeiou]g second letter is not a vowel

p.g second letter is anything

^....$ matches a line with exactly four characters

^\. matches any line beginning with a dot

^\.[0-9a-z] same with a lowercase letter or digit following

^[^\.] matches any line that does not begin with a dot

;$ matches a line ending with a semicolon

figs* matches fig, figs, figss, figsss etc.

[a-z][a-z]* matches one or more lowercase letters

[a-zA-Z] matches any character

[^0-9a-zA-Z] matches any symbol (not a letter or number)

\&ltthe matches the, theater, then

the\> matches the, breathe

\&ltthe/> matches the

:%s/\<./\u&/g turn the first letter of all words to uppercase

:%s/\<[a-z][!-~]*\>/\u&/g as above

:%s/\<[a-z]/\u&/g as above

:%s/.*/\L&/ turn entire file to lowercase

:%s/<[^>]*>//g remove strings from file that start with a less than sign and end with a greater than sign (html tags)

:1,$s/1$/0/g Replace 1 to 0 from each line of the file, if last character of the line is 1

:1,$s/^1/0/g Replace 1 to 0 from each line of the file, if first character of the line is 1