1825581 Members
2268 Online
109682 Solutions
New Discussion

Redirecting output

 
SOLVED
Go to solution
Shahul
Esteemed Contributor

Redirecting output


Hi

I am executing a script with ksh -x and redirecting O/P to a log file. But the commands are not getting redirected to log file, Only O/P is coming to file.

eg

#!/bin/ksh
pwd
date

I am executing this script as below

#ksh -x /home/user1/test.ksh > test.log

When I cat this log file the output of pwd and date are coming to logfile, but not commands. Can someone give me a hint to solve this?

TIA
Shahul
2 REPLIES 2
Ramkumar Devanathan
Honored Contributor
Solution

Re: Redirecting output

Shahul,

# ksh -x /home/user1/test.ksh > test.log 2>&1

- ramd.
HPE Software Rocks!
Ramkumar Devanathan
Honored Contributor

Re: Redirecting output

To explain a bit more -

2>&1 redirects stderr (device id 2) to stdout (device id 1).

the normal redirection '>' redirects only stdout to the file which is why you got only the output to the file.

so, redirect stderr to stdout and thereafter redirect stdout to the file.

- ramd.
HPE Software Rocks!