Sponsored Content
Top Forums Shell Programming and Scripting Bizzare behavior on redirect of stdout Post 302945340 by edstevens on Thursday 28th of May 2015 12:35:16 PM
Old 05-28-2015
Bizzare behavior on redirect of stdout

Oracle Linux 5.6 64-bit (derivative of RHEL)

Dear Ann Landers,

This is about as bizarre as anything I've ever seen.
I have a little test script I've been working with. When I redirect stdout to a file, no file. Make a copy of the script to another name. Execute it and redirect stdout, and I get the file.

Starting with the file listing, the file eds_scp_test is the file in question:
Code:
2015-05-28 10:58:38

oracle:$ ls -ltr eds*
-rw-r----- 1 oracle oinstall  5054 Aug 25  2014 eds_audit_report_generic.sql
-rwxr-x--- 1 oracle oinstall  4603 Aug 26  2014 eds_audit_report
-rw-r--r-- 1 oracle oinstall  3348 Apr  6 12:42 edstest.sql
-rwxr-x--- 1 oracle oinstall  2076 May 21 12:42 eds_ftp_test
-rw-r--r-- 1 oracle oinstall 16286 May 27 10:53 eds_ftp_test.log
-rwxr-x--- 1 oracle oinstall  1296 May 28 09:19 eds_scp_test


2015-05-28 10:58:42

oracle:$ cat eds_scp_test
#!/bin/sh
#===========================================================
# Purpose: test scp step from stage_refresh
#
#===========================================================
logfile=/u01/app/oracle/dba/eds_scp_test.log
rm $logfile
export NLS_DATE_FORMAT='dd-Mon-yyyy hh24:mi:ss'
echo ===================================================== 
echo Begin job at `date`
echo ===================================================== 
#===========================================================
# -- get backup files from prodserver 
#
echo ===================================================== 
echo deleteing old backup at `date` 
echo ===================================================== 
cd /backup/stgdb
rm *.rman
rm *.backup
rm *.alog

echo ===================================================== 
echo begin scp at `date` 
echo ===================================================== 
#scp -v oracle@prodserver:/u01/backup/prddb/* .                  
#scp -v prodserver:/u01/backup/prddb/* .  
#scp -q -v prodserver:/u01/backup/prddb/c4q7mt9e_1_1.alog  .  
# ------------------------------------------------------------------------
echo ===================================================== 
echo End job at `date` 
echo Log is at $logfile 
echo ===================================================== 
exit

Just execute the file, and everything is as expected:
Code:
2015-05-28 10:58:55

oracle:$ ./eds_scp_test
rm: cannot remove `/u01/app/oracle/dba/eds_scp_test.log': No such file or directory
=====================================================
Begin job at Thu May 28 10:59:39 CDT 2015
=====================================================
=====================================================
deleteing old backup at Thu May 28 10:59:39 CDT 2015
=====================================================
rm: cannot remove `*.rman': No such file or directory
rm: cannot remove `*.backup': No such file or directory
rm: cannot remove `*.alog': No such file or directory
=====================================================
begin scp at Thu May 28 10:59:39 CDT 2015
=====================================================
=====================================================
End job at Thu May 28 10:59:39 CDT 2015
Log is at /u01/app/oracle/dba/eds_scp_test.log
=====================================================

Execute it again, but redirect stdout to a log file (errout will still go to display)
Code:
2015-05-28 10:59:39

oracle:$ ./eds_scp_test > eds_scp_test.log
rm: cannot remove `*.rman': No such file or directory
rm: cannot remove `*.backup': No such file or directory
rm: cannot remove `*.alog': No such file or directory

But where's the log file?
Code:
2015-05-28 10:59:54

oracle:$ ls -ltr eds*
-rw-r----- 1 oracle oinstall  5054 Aug 25  2014 eds_audit_report_generic.sql
-rwxr-x--- 1 oracle oinstall  4603 Aug 26  2014 eds_audit_report
-rw-r--r-- 1 oracle oinstall  3348 Apr  6 12:42 edstest.sql
-rwxr-x--- 1 oracle oinstall  2076 May 21 12:42 eds_ftp_test
-rw-r--r-- 1 oracle oinstall 16286 May 27 10:53 eds_ftp_test.log
-rwxr-x--- 1 oracle oinstall  1296 May 28 09:19 eds_scp_test

Now, make an exact copy of the subject script:
Code:
2015-05-28 10:59:58

oracle:$ cp eds_scp_test eds_echo_test


2015-05-28 11:00:15

oracle:$ ls -ltr eds*
-rw-r----- 1 oracle oinstall  5054 Aug 25  2014 eds_audit_report_generic.sql
-rwxr-x--- 1 oracle oinstall  4603 Aug 26  2014 eds_audit_report
-rw-r--r-- 1 oracle oinstall  3348 Apr  6 12:42 edstest.sql
-rwxr-x--- 1 oracle oinstall  2076 May 21 12:42 eds_ftp_test
-rw-r--r-- 1 oracle oinstall 16286 May 27 10:53 eds_ftp_test.log
-rwxr-x--- 1 oracle oinstall  1296 May 28 09:19 eds_scp_test
-rwxr-x--- 1 oracle oinstall  1296 May 28 11:00 eds_echo_test

And test it
Code:
2015-05-28 11:00:19

oracle:$ ./eds_echo_test > eds_echo_test.log
rm: cannot remove `/u01/app/oracle/dba/eds_scp_test.log': No such file or directory
rm: cannot remove `*.rman': No such file or directory
rm: cannot remove `*.backup': No such file or directory
rm: cannot remove `*.alog': No such file or directory

And this time we get the expected log file:
Code:
2015-05-28 11:00:31

oracle:$ ls -ltr eds*
-rw-r----- 1 oracle oinstall  5054 Aug 25  2014 eds_audit_report_generic.sql
-rwxr-x--- 1 oracle oinstall  4603 Aug 26  2014 eds_audit_report
-rw-r--r-- 1 oracle oinstall  3348 Apr  6 12:42 edstest.sql
-rwxr-x--- 1 oracle oinstall  2076 May 21 12:42 eds_ftp_test
-rw-r--r-- 1 oracle oinstall 16286 May 27 10:53 eds_ftp_test.log
-rwxr-x--- 1 oracle oinstall  1296 May 28 09:19 eds_scp_test
-rwxr-x--- 1 oracle oinstall  1296 May 28 11:00 eds_echo_test
-rw-r--r-- 1 oracle oinstall   656 May 28 11:00 eds_echo_test.log

Sign me -- Perplexed.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Redirect stdout and stderr

How can I redirect and append stdout and stderr to a file when using cron? Here is my crontab file: */5 * * * * /dir/php /dir/process_fns.php >>& /dir/dump.txt Cron gives me an 'unexpected character found in line' when trying to add my crontab file. Regards, Zach Curtis POPULUS (8 Replies)
Discussion started by: zcurtis
8 Replies

2. UNIX for Advanced & Expert Users

problem with redirect stdout to file

Hi all hope you can help as I am going MAD!!! :eek: The below is in a shell script but the redirection in the sed line does not work and outputs to the screen and the $fname_2 does note get created ????? Can any one help ?? #!/bin/ksh cd /app/ for fname in `ls -1 X*` do sed 1d $fname... (3 Replies)
Discussion started by: mlucas
3 Replies

3. Shell Programming and Scripting

How to redirect stderr and stdout to a file

Hi friends I am facing one problem while redirecting the out of the stderr and stdout to a file let example my problem with a simple example I have a file (say test.sh)in which i run 2 command in the background ps -ef & ls & and now i am run this file and redirect the output to a file... (8 Replies)
Discussion started by: sushantnirwan
8 Replies

4. Programming

redirect stdout

hello again! i use dup2 to redirect stdout. I run what i want, now i want undo this redirection. how can i do that? thanx in advance (7 Replies)
Discussion started by: nicos
7 Replies

5. Programming

how to redirect back to stdout

In my program, I am using library provided by other. In the library, the cout/cerr is redirected to a file (the file path is known). After I call some methods in the library, I get one side-effect --> The cout/cerr in my own program is also directed to the file. So how can I to redirect... (5 Replies)
Discussion started by: princelinux
5 Replies

6. UNIX for Dummies Questions & Answers

Redirect stdin stdout to multiple files

Hi, i know how to a) redirect stdout and stderr to one file, b) and write to two files concurrently with same output using tee command Now, i want to do both the above together. I have a script and it should write both stdout and stderr in one file and also write the same content to... (8 Replies)
Discussion started by: ysrini
8 Replies

7. Shell Programming and Scripting

redirect STDOUT to a file in a subshell

Hi, I would like to avoid re-directing line by line to a file. What is the best way to re-direct STDOUT to a file in a subshell? Thanks in advance. Cheers Vj (1 Reply)
Discussion started by: tnvee
1 Replies

8. Shell Programming and Scripting

help with counting processes, bizzare behavior

I have a ksh script (dtksh Version M-12/28/93d on Solaris 10) that is run daily by cron and sometime hangs forever. I need to detect if there is an old copy hung before I start the new run, and if so send an email and exit the script. Here is part of the code: #!/usr/dt/bin/dtksh... (4 Replies)
Discussion started by: 73rdUserID
4 Replies

9. Red Hat

Redirect STDOUT and STDERR of chsh

EDIT: Nevermind, figured it out! Forgot to put backslashes in my perl script to not process literals! Hi everyone. I am trying to have this command pass silently. (no output) chsh -s /bin/sh news Currently it outputs. I've tried.... &> /dev/null 1> /dev/null 2>&1 /dev/null 1>&2... (1 Reply)
Discussion started by: austinharris43
1 Replies

10. Shell Programming and Scripting

Redirect stdout and stderror in child process

I have a problem when i try to create a log file from a daemon process using shell scripting in ubuntu 12. Ultimatly what i want to achieve is run a java/jar file from a script. After scourging the internet i found several solutions to do this, the one i choose is to create a startup script that... (4 Replies)
Discussion started by: Narev
4 Replies
All times are GMT -4. The time now is 02:17 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy