What does 2>&1 mean?
Sometimes I call my SQL script via shell script which generally have this kind of statement in it,
$SCRIPTDIR/run_me.sh 2>&1 > $LOGDIR/log_me.log
What above statement does for me is, it runs run_me.sh script from my script folder and logs the detail in files called log_me.log in my log folder. Over here what I am interested in is what is 2>&1. Well firstly let me define three data streams in linux i.e. STDIN, STDOUT, and STDERR,
STDIN : Standard input usually comes from the keyboard or from another program
STDOUT : The program usually prints to standard output
STDERR : The program sometimes prints to standard error
In Linux/Unix, The built-in numberings for them are 0, 1, and 2, in that order.
The command above is redirecting standard error into standard output (you have to put an & in front of the destination when you do this) and redirecting standard output into my log file, which is a place I want to dump anything my scripts writes out.
So effectively, all output from this command should be logged into my log file. So in case of any issue I can always look at the log to find out the trouble area.
--------------------------------------------------------------------------------------------
Sometimes there will be cases where a directory is filled with lots of files e.g. dump directory with lots of trace file. In such case when I tried following,
/bin/rm *.trc
I got following error message:
bash: /bin/rm: Argument list too long
Solution:
find . -name "*.trc"| xargs /bin/rm.
Depending on the number of files, after a while all files will be erased.
Showing posts with label OS. Show all posts
Showing posts with label OS. Show all posts
Wednesday, June 3, 2009
Wednesday, July 30, 2008
Tip#17 How to find out 32/64 Bit
Find out whether OS is 32 bit or 64 bit
Linux : getconf LONG_BIT
Solaris : /usr/bin/isainfo -kv
AIX : getconf -a | grep KERN
HPUX : /usr/bin/getconf KERNEL_BITS
Windows : Start>All Programs>accessories> System Tools>System Information> System summary
Find out whether Oracle Software is 32 bit or 64 bit.
Method # 1
cd $ORACLE_HOME/bin/
file oracle
Method # 2
sqlplus / as sysdba (Look for "Connected to:")
Method # 3
If the two directories $ORACLE_HOME/lib32 and $ORACLE_HOME/lib are existing then it is 64 bit else 32 bit
Linux : getconf LONG_BIT
Solaris : /usr/bin/isainfo -kv
AIX : getconf -a | grep KERN
HPUX : /usr/bin/getconf KERNEL_BITS
Windows : Start>All Programs>accessories> System Tools>System Information> System summary
Find out whether Oracle Software is 32 bit or 64 bit.
Method # 1
cd $ORACLE_HOME/bin/
file oracle
Method # 2
sqlplus / as sysdba (Look for "Connected to:")
Method # 3
If the two directories $ORACLE_HOME/lib32 and $ORACLE_HOME/lib are existing then it is 64 bit else 32 bit
Tuesday, April 1, 2008
Tip#9 Some OS utilities (Unix)
NOHUP :
nohup (no hangups) is a UNIX command that allows you to execute a command in the background while you are logged into UNIX. The background process will continue to run until completion, even if you log off. For long running processes, this is a nice way to execute them. In my case, it allows me to log into a client server remotely, execute a process interactively with nohup, and then disconnect. Another benefit of nohup is that by default, a log of all activity is recorded in the current directory in the file nohup.out . e.g.
nohup sqlplus user/pwd @sqlscript &
Note : & at the end is for running the process in the background
SKILL:
Sometime I have a situations where I find that a process is consuming a lot of CPU and memory, but I don't want to kill it and I just wished if I could just 'pause' the process and that's where SKILL really helps me. e.g Process ID 1234 is taking too much resources and I need to somehow get other 'important' things done I will execute following command,
skill -STOP 1234
Once I have finished other 'important' things done I can free the process with following command
skill -CONT 1234
The nice feature is you can pass not just PID but also User, Terminal ID OR Command which makes it more powerful then I initially thought. e.g. You can 'pause' all RMAN commands on DB server with
skill -STOP rman
SNICE:
The command snice is similar to skill but Instead of stopping a process it makes its priority a lower one. e.g. for the same heavy process 1234 I could decrease the priority by using something like this,
snice +4 -p 1234
Note: +4 means we are increasing the Nice Value and effectively the higher the number, the lower the priority.
This utility is quite useful in reducing priorities.
nohup (no hangups) is a UNIX command that allows you to execute a command in the background while you are logged into UNIX. The background process will continue to run until completion, even if you log off. For long running processes, this is a nice way to execute them. In my case, it allows me to log into a client server remotely, execute a process interactively with nohup, and then disconnect. Another benefit of nohup is that by default, a log of all activity is recorded in the current directory in the file nohup.out . e.g.
nohup sqlplus user/pwd @sqlscript &
Note : & at the end is for running the process in the background
SKILL:
Sometime I have a situations where I find that a process is consuming a lot of CPU and memory, but I don't want to kill it and I just wished if I could just 'pause' the process and that's where SKILL really helps me. e.g Process ID 1234 is taking too much resources and I need to somehow get other 'important' things done I will execute following command,
skill -STOP 1234
Once I have finished other 'important' things done I can free the process with following command
skill -CONT 1234
The nice feature is you can pass not just PID but also User, Terminal ID OR Command which makes it more powerful then I initially thought. e.g. You can 'pause' all RMAN commands on DB server with
skill -STOP rman
SNICE:
The command snice is similar to skill but Instead of stopping a process it makes its priority a lower one. e.g. for the same heavy process 1234 I could decrease the priority by using something like this,
snice +4 -p 1234
Note: +4 means we are increasing the Nice Value and effectively the higher the number, the lower the priority.
This utility is quite useful in reducing priorities.
Monday, September 17, 2007
Tip#7 SQL*Plus Command Line History
Thanks to Howard Rogers( Link ) , I got a very useful utility to have command line history for SQL*Plus on Linux. This small utility makes life so much easier for me especially as most of the time I do work on Linux platform. All you have to do is
1. Download a rpm (Link)
2. As root user, Install it -> rpm -ivh rlwrap-0.18-1.i386.rpm
3. Create alias for SQL*Plus in the user profile (Bash -> .bash_profile , Ksh -> .profile )
alias sqlplus='rlwrap sqlplus'
This will make sure that every time you login and run sql*Plus, "rlwrap" captures all SQL*Plus commands which you can just recall with up/down arrow key. Other nice feature is search capability of this utility, you can press Ctrl+R and type in key word to search for in your historical SQLs.
I really find this utility very helpful, hope it helps you too!!!
Subscribe to:
Posts (Atom)