Standard input , output and error in Unix and Linux
Standard input , output and error files in Unix and Linux.
UNIX/LINUX treats the keyboard as the Standard Input File and VDU (Visual Display Unit for example putty screen) as the Standard Output File as well as the Standard Error File. However, input can be taken from sources other than the Standard Input and output can be passed to any source other than the Standard Output. Such a process is called Redirection. This may be Input Redirection or Output Redirection.
For setting up putty tool follow this link Best practices/check list while doing DBA tasks
These three streams i.e., the “Standard Input”, the “Standard Output” and the “Standard Error” are denoted by the numbers 0, 1 and 2 respectively.
Streams | Device | Value |
Standard Input | Keyword | 0 |
Standard Output | Terminal Screen | 1 |
Standard Error | Terminal Screen | 2 |
Redirection
Redirection changes the assignments for standard input and standard output. First let us take up Output Redirection.
Output Redirection
When output from a process is redirected to sources other than the standard output, it is called Output Redirection. The Shell command line format for redirecting output to a file is,
$ command > file |
Here file will receive the data output from command. The output from the command is redirected to file instead of the Standard Output, i.e. VDU.(For example putty screen)
Example 1
$ date > today $ $ cat today Sat Sep 09 10:44:49 PST 2023 $ |
Example 2
If you don’t want to copy the o/p in any file ,you can redirect that into /dev/null
$date >/dev/null |
Input Redirection
-
- We can redirect the input for a command using input redirection. The Shell command line that allows input redirection is,
$command < file |
Here file is the source of the data for the command. If file does not exist, the shell will issue an error and abort the operation. Let us assume that we have a file called RDBMS.
Example 1.
$ cat < RDBMS Oracle MS SQL My SQL UDB $ |
Example 2
Connecting to Oracle database and execute SQL script in silent mode.
$sqlplus -s “/as sysdba” <<EOF
@exec_script.sql EOF $ |
Redirecting both Standard Input and Standard Output
The Shell may be used to redirect both the Standard Input and Standard Output for a command. The syntax is,
$ command <source>destination |
Here the command takes its input from the source and redirects the output to destination thus establishing redirection in both ways.
Example
$ cat <RDBMS>list
$ cat < RDBMS |
Example 2
nohup sqlplus db_admin/******@ORDW1 < ORDW1_STG_TAB.sql >ORDW1_STG_table_stats.log &
For more info on the above command go through the below link |
Redirection in crontab
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /u00/app/oracle/scripts/OS/load_average.sh > /u00/app/oracle/scripts/OS/load_average.log
script to find load average on the OS Level Here redirecting output of the load_average.sh to a logfile. |
See also