Tuesday, February 28, 2006

changing the owner of files dirs

chown file/dir user:group -R

-R for recursive to all the files and subdirs in that perticular dir

Thursday, February 23, 2006

The whole Idea of Blogging

I just found an article on blogging.
The only one line that cought my eye was,

tail -f /dev/mind > blog

Thats explins everything, Right :)
Actually I thought the whole article was useless with out that one line.

Finding Linux version

cat /etc/redhat-release

or use following commands:
uname -a
uname -X

Restarting solaris machine

On solaris, dont just type reboot. That will make the machine hang in init 1 (single user mode)
instead, type the following:

>shutdown -y -g0 -i6

Using NFS on Solaris

NFS on solaris
To start the NFS services:
$ su -
$ cd /usr/lib/nfs
$ ./mountd
$ ./nfsd

# mountd: RPC server that answers requests for NFS access information and file system mount requests
# nfsd: The daemon that handles client file system requests

Sharing A File System

The following example will share a file system /software so that others may be able to mount it:

# share /software

If I want to check all file systems being shared from my system:

# share
- /software rw ""

How to NFS A File System

Now, from another machine, I want to NFS the file system that is being shared above:

# mount -F nfs alex:/software /mnt/software

Using SCP to copy files

# scp source target

# scp joeshmoe@miles.shadlen.org:matlab/mfile.m matlab/

# scp example.m joeshmoe@miles.shadlen.org:unfinished/silly.m
------------------------------------------------------------------------------------------------------------------------
Copy directory ``/usr/local/share'' and its contents from your Linux file space to your own workstation:

#scp -r username@hostname.sl.valista.com:/usr/local/share .

(``.'' means copy the files to the current directory on your workstation. A new directory ``share'' will be created there containing copies of the files and directories in the server's ``share'').

Finging Files with Find

# find path operators

where path is the directory in which find will begin to search and operators tell find which files you are interested in.

Example:

To find a file with specific name,

# find . –name “*ab*” –print

Where the starting point is current directory. (This will find all files under the current directory that has “ab” somewhere in the name.)

find can be used to find files using a lot of other attributes:

# find . -mtime +2 -print
finds files that have been modified for more than 2 days.

# find . -atime -5 -print
finds files that have been accessed for less than 5 days.

# find . –type f –print
Find the file by type
f- Plain file
l- symbolic link
d- directory

# find . –size 1234c –print
finds the file with exactly 1234 bytes

# find . –size +10000c –size -32000c –print
finds the all files in current directory that are grater than 10000bytes, but less than 32000bytes.

# find . –perm -100 -print
find the files with permission 100 (--x------)
---------------------------------------------------------------------------------------------------------------------------
Another useful command to use with this is -exec

find . -name *.jar -exec ls -l {} \;

Find all the jars under the current directory and execute ls -l on each

All about compression on Unix/Linux

Often you would want to compress or uncompress files when you want to move it from one machine to another. This reduces the time it takes to copy the file over the network. I have added below most of the compression methods I am familiar with and will be adding more as I learn of them...please feel free to add in your own replies!

Using tar files

Tar files dont actually compress anything. They just bundle up files into one Tape ARchive. Which is why you generally see that tar files also zipped with gzip.

To create a tar file:
#tar -cvf .tar
Note: The extension needs to be specified. The target can be a wildcard or a directory.

To unroll a tar file:
#tar -xvf
Note: You might want to run tar with the -tvf switch to see what the file contains before extracting.

To create a zipped tar file (using gzip):
#tar -zcvf .tar.gz

To untar and to uncompress a tar file in one command (valid for gzipped files):
#tar -zxvf
----------------------------------------------------------------------------------------------------------------------
Oh and by the way, to confirm that the file you are copying is correctly copied to the target machine, u can you the "sum" command which prints out the checksum for the file.

#sum

The checksum should be identical with the source machine.

PS: If you are using Windows, I dont think you will have a checksum utility (??). I would suggest you install cygwin which provides windows versions of all the common Unix commands.

\\fileserver\public\software\windows\X-Servers\setup.exe


or

http://www.cygwin.com/

Mounting Remote File Share

On Linux you can mount remote file share under your file system and then you can access them as they are in your local file system.

File can be shared using different types (NFS, Samba etc.)

Before you mount any remote file share you should complete the following steps.

1) Create a mount point on your local file system.
eg:
#mkdir /mnt/fileshare
2) Find out the remote file share type ( NFS, SMB etc)
3) Remote file share name (Server name and share name)
eg:
Server name: public.valista.com ShareName: public Type:samba

Then you can use the mount command to mount the remote file share.

# mount -t filesystemtype -o options

For more information about mount command
# man mount

Now if you would like to mount public.valista.com/public under /mnt/fileshare

#mount //public.valista.com/public /mnt/fileshare -t smbfs -o defaults,umask=0022

If you want to this mount point permanent edit the file /etc/fstab adding the following line

//public.valista.com/public /mnt/fileshare smbfs defaults,umask=0022 0 0

Now if you type
#ls -l /mnt/fileshare

You can see the shared files on public.valista.com/public file share

******************************************************
If you would like to browse remote samba share on your file browser. Type the command

#nautilus smb://fileserver.valista.com/public

Using jdk1.3.1_xx in fedora core 4

to make the same production environment in the client side we may need to setup the environment similar to legacy systems that our clients have.
In the case of Using jdk1.3.1_xx in fedora core 4 it gives the issue of

Error occurred during initialization of VM Unable to load native library: /usr/local/jre1.3.1_06/lib/i386/libjava.so: symbol __libc_wait, version GLIBC_2.0 not defined in file libc.so.6 with link time referenceE


This arise because I tried to use versions available in the public server of 1.3.1_XX with fedora.

Solution :
jdk 1.3.1_XX is not recommended other than UNIX versions RH 7.2 or below kernel versions
The fixed rpm one is available on the sun Java site that is 1.3.1_16
This version of the jdk(The rpm) OK with the fedora core.

Setting up Multiple X Sessions on a Single Monitor

If you need to run multiple X servers concurrently and let us switch back and forth between them as required. So, Control-Alt-F7 is 1st X server and Control-Alt-F8 is 2nd so on.
First we have to test our second session.

Testing the Second Session

The first step is to test the second session manually. Simply log to a console window (Control-Alt-F1 for example) and type the following:

startx -- :1 vt8

This will start an X server on virtual terminal 8 and the DISPLAY environment variable will be :1.0 instead of :0.0.

The :1 is the display name and vt8 is the virtual terminal number. Since vt7 is the default terminal for X, and I running consoles on vt1-vt6, I chose vt8 for the second X session. Be sure that it isn't already being used for a console. Console VTs are started by /etc/inittab.

Making the Change Automatic

Typically, X is started when init changes to runlevel 5. If you look at /etc/inittab, you will see a record that looks like:

x:5:once:/etc/X11/prefdm -nodaemon

This in turn will run the appropriate display manager. By default, this is gdm or kdm and the choice is dependent on the value of the DESKTOP variable defined in /etc/sysconfig/desktop. Even though desktop is "GNOME", you need to use the xdm display manager since GNOME doesn't support multiple displays. You can override this default by having the following two records in /etc/sysconfig/desktop:

DESKTOP="GNOME"
DISPLAYMANAGER="XDM"

Now, when you switch to runlevel 5 (which is the default at boot time), you will be using the XDM window manager instead of kdm or gdm. The next step is configure xdm to start the second session. This is done by simply adding another record to the /etc/X11/xdm/Xservers file:

:0 local /usr/X11R6/bin/X :0 vt7
:1 local /usr/X11R6/bin/X :1 vt8


Verifying Your Changes

You don't need to reboot for this to take effect. Simply log out of your X session, switch to a lower run-level, and then switch back to run-level 5:

* init 3
* init 5


Then you will see two X sessions when you press
Control-Alt-F7 is 1st X server and Control-Alt-F8 is 2nd
Frist we have to test our second session.

Enabling Java Plugin for FireFox

If you come across an issue where left panel of weblogic console is not show here is the solution.

Assumption
You need to install JDK in you machine and java home is reffered as $JAVA_HOME

Type the following commands
cd ~/
cd .mozilla/plugin Note: If the plugin directory is not available create it manually
ln -s $JAVA_HOME/jre/plugin/i386/ns610-gcc32/libjavaplugin_oji.so

Now restart the browser!

Changing file permission the easy way

You change a file's permissions using the Unix command "chmod" (for "change mode").
The chmod command supports a handy shortcut for setting permissions: You express the permissions
you want as a three-digit number, like "644" or "755", with the first digit giving
the owner's permissions, the second digit giving the group permissions, and the last digit
giving the "everybody else" permissions. The numbers themselves are arrived at by simple addition,
using the following formula:

4 = read permission
2 = write permission
1 = execute permission

SNMP trap monitoring and trap generating

Find where the snmptrapd is installed. ( I found it is /usr/sbin)
Give the following command as the su -
snmptrapd -f -Le
If a SNMP trap is generated you will see it in the console.

To generate a SNMP trap manually ( With this you can verify that snmptrapd is working!!)

There is a handy tool (Look in http://www.ncomtech.com/software/TrapGen) to generate traps. The trapgen for linux is available at smb://fileserver/public/software/linux.
Extract the tool and give the command ./trapgen -f input.txt or ./trapgen -d as the su -
This would generate a SNMP trap and if the snmprapd is running u can see the trap logged there.

tar -xvf does not extract all directories ( solaris )

Sometimes the tar -xvf does not extract all the directories in the archive, and gives the directory checksome error, there is a workaround for that.

Uncompress the .tar.gz in your local machine(linux or windows) and make a .zip archive of it.
scp the .zip archive to solaris machine and uncompress using the following command.
jar -xvf

This will untar all the directories.
------------------------------------------------------------------------------------------------------------------------------------
The reason why tar didn't work is because the standard Solaris /usr/bin/tar can't unpack files which contain very long directory paths. (Can't remember what the limit is).

The permanent way to fix this is to get the GNU tar package for the correct Solaris version and hardware architechture (SPARC or x86) from http://www.sunfreeware.com (pick your nearest mirror).

You'll need to use pkgadd to install the package:

As root:

# pkgadd -d

Finding the disk used space

Here's a handy command sequence which you can run anywhere, anytime, so see which directories contain the most amount of data. It's a really useful way to focus your attention on the biggest users of disk space. It's best run as root, so you have access to everyone's files:

# du -k / | sort -rn | less

* 'du -k / ' means "Show me disk usage (in kilobytes) for all directories mounted on /"
* 'sort -rn' means "Sort in reverse numeric order (largest first)"
* 'less' is a handy favourite pager.

This will give you a list of directory sizes followed by the directory name. The top ones are where you should focus your attention.

Starting up Oracle DB

Often when your DB machine reboots, the DB might not be in an open state and would need to be restarted. This is a very common set of commands that we often forget.
I have added it below for convenience:

>sqlplus /nolog
>connect /as sysdba
>startup

Then at the command prompt:

>lsnrctl start

That should get the DB up and running.

To make sure that your TNS is working from the machine that you want to establish connection, type the following:

>tnsping

it should return OK.

If you want to check as to what the existing TNS names on your machine, look in the following file:

$ORACLE_HOME/network/admin/tnsnames.ora

How to drop a deleted datafile from Oracle

The symptom error is :
ERROR at line 1:
ORA-01157: cannot identify/lock data file 1 - see DBWR trace file
ORA-01110: data file 1: 'E:\ORACLE\ORADATA\CESCATI\SYSTEM01.DBF'

a. Execute "connect internal". If it complains about the ORACLE_SID not being set, then check to make sure that the ORACLE_SID environment variable is properly set. With the default setup, you could issue a command like "setenv ORACLE_SID eqs" from the csh prompt. On Windows 2000 use the environment variable modification tool under Control Panel -> System. If you have this problem on , Win2000 you should probably redo the entire Oracle installation. On UNIX you will have to run as the account that own oracle.

b. Execute "shutdown abort" to make sure the database is shutdown.

c. Execute "startup nomount". (This is the most primitive way of starting the database.)

d. Execute "alter database mount" (This should mount the database, and server manager should reply with the string "Statement Processed")

e. Execute "alter database datafile offline drop" where is the name of the operating system file that you have deleted or otherwise butchered. It should be surrounded by single quotes ( ' ).

f. If the last statement executed, you should be in the clear. Execute "shutdown immediate" to shutdown the database.

g. Exit server manager.

NOTE: To find out the datafile name , use the v$datafile view (Name column)

Time/Date in oracle

To work with timestamps in oracle, use the to_timestamp function.

A time stamp looks like this : 07-NOV-05 03:50:23.553750

delete from sessn where last_used < to_timestamp('14-Dec-04');

Locating unicode chars in DB

This is an interesting one from a customer:

If you suspect that a field in an Oracle DB is having wierd unicode non-english chars, how do you confirm it? Sometimes these chars will be translated as valid English chars and cause all the more confusion. The answer is to use the asciistr function. This function returns all the chars as ascii strings...and unicode chars as escaped hexadecimal values.

E.g: select dep_id, asciistr(ALIAS) from gp_dependent where asciistr(ALIAS) like '%\%';

Its quite useful, note the opposite of the above is the unistr function. This one takes hexadecimal values in a string an converts into a Unicode text string.

Redirecting SQLplus output to text file

You could try spooling the output, but here is an easier option:

test.sql should contain your sql statements.

sqlplus -s scott/tiger <> test.lst
@test
exit
STOP

Creating tablespaces using sqlplus

Create regular tablespaces:

CREATE TABLESPACE sj_data
DATAFILE '/u01/app/oracle/oradata/street/sj_data.dbf'
SIZE 10M reuse
AUTOEXTEND ON NEXT 10M

CREATE TABLESPACE sj_default
DATAFILE '/u01/app/oracle/oradata/street/sj_default.dbf'
SIZE 10M reuse
AUTOEXTEND ON NEXT 10M

CREATE TABLESPACE sj_index
DATAFILE '/u01/app/oracle/oradata/street/sj_index.dbf'
SIZE 10M reuse
AUTOEXTEND ON NEXT 10M

Finally, create the TEMPORARY tablespace:

create temporary tablespace sj_temp
tempfile '/u01/app/oracle/oradata/street/sj_temp.dbf'
size 10M reuse
AUTOEXTEND ON NEXT 10M

Monday, February 13, 2006

how to add a user (UNIX) and use as a ctl+alt+F9(X:1)

su -
adduser robocop
passwd robocop

login :robocop
passwd : robocop

export DISPLAY=:1
X :1 &
gnome-session &