Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Redirect Standard Error to /dev/null is not working. Post 302771152 by jimbojames on Tuesday 19th of February 2013 10:36:43 PM
Old 02-19-2013
Redirect Standard Error to /dev/null is not working.

Hello.

When I run a .ksh that contains the command below, and there is no file available in the source location the "FILE_NAME_*.CSV not found" error is still being displayed.

Code:
FILEN=$(ssh ${SOURCE_SERV} "cd ${SOURCE_LOCATION} ;ls ${FILES}") 2> /dev/null

.

This is interfering with the rest of the script, as it is not exiting as required, and is continuing to the next command (See below).

Code:
echo "- Listing available file(s) on ${SOURCE_SERV}${SOURCE_LOCATION}:\n"
		FILEN=$(ssh ${SOURCE_SERV} "cd ${SOURCE_LOCATION} ;ls ${FILES}") 2> /dev/null
		print ${FILEN}
	if [ $? -eq 0 ]; then
	echo "\n- End of Source of files list."
else
        echo "\t\t#####################################\n\t\t#        NO FILES AVAILABLE.        #\n\t\t#####################################\n\n\n- Exiting script"
	exit 0
fi

Can anyone advise what I am doing wrong with the redirection? Basically If there are no files available, I need to echo the warning and exit the script successfully.

Thanks in advance.

---------- Post updated at 02:36 PM ---------- Previous update was at 12:07 PM ----------

Ignore me,

I have fixed it with the following:

Code:
echo "- Listing available file(s) on ${SOURCE_SERV}${SOURCE_LOCATION}:\n"
		FileExists=`ssh ${SOURCE_SERV} "test -f ${SOURCE_LOCATION}/${FILES} && echo 1 || echo 0"`
	if [ ${FileExists} = 0 ]; then
	echo "\t\t#####################################\n\t\t#        NO FILES AVAILABLE.        #\n\t\t#####################################\n\n\n- Exiting script"
	exit 0
else	
	FILEN=$(ssh ${SOURCE_SERV} "cd ${SOURCE_LOCATION} ;ls ${FILES}")
	print ${FILEN}
	echo "\n- End of Source of files list."

Thanks for looking though!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

error piping nohup to /dev/null

Hi, I have a script as follows: #!/bin/sh nohup ./my_program >& /dev/null & However, i get a "Generated or received a file descriptor number that is not valid" whenever I run it. running the command up in prompt is ok though. if i change the first line to #!/bin/csh i get a then:... (4 Replies)
Discussion started by: mochi
4 Replies

2. Shell Programming and Scripting

redirect stderr to dev/null in bash env.

Working in a bash environment, in the following example, how do I direct the error message that putting in an invalid flag (-j for example) would normally produce to dev/null? while getopts "abcd" opt do case "$opt" in i) a etc ;; r) b etc ;; f) c etc ;; v) d... (7 Replies)
Discussion started by: Sniper Pixie
7 Replies

3. UNIX for Dummies Questions & Answers

redirect stderr and/or stdout to /dev/null from command line

Is it possible to redirect errors at the command line when you run the script such as bash scriptname & 2>/dev/null? (1 Reply)
Discussion started by: knc9233
1 Replies

4. Solaris

What is /dev/tty /dev/null and /dev/console

Hi, Anyone can help My solaris 8 system has the following /dev/null , /dev/tty and /dev/console All permission are lrwxrwxrwx Can this be change to a non-world write ?? any impact ?? (12 Replies)
Discussion started by: civic2005
12 Replies

5. Shell Programming and Scripting

How to redirect the import log to /dev/null?

Hi i am running oracle database import through a script and script scans the import log to see if there are any errors. Now the porblem is that when i run the script the import log appears on the screen even if i direct the output of import to /dev/null. imp "'/ as sysdba'"... (5 Replies)
Discussion started by: vinoo128
5 Replies

6. UNIX for Dummies Questions & Answers

Redirect Standard output and standard error into spreadsheet

Hey, I'm completely new at this and I was wondering if there is a way that I would be able to redirect the log files in a directories standard output and standard error into and excel spreadsheet in anyway? Please remember don't use too advanced of terminology as I just started using shell... (6 Replies)
Discussion started by: killaram
6 Replies

7. UNIX for Dummies Questions & Answers

/dev/null 2>&1 Versus /dev/null 2>1

How are these two different? They both prevent output and error from being displayed. I don't see the use of the "&" echo "hello" > /dev/null 2>&1 echo "hello" > /dev/null 2>1 (3 Replies)
Discussion started by: glev2005
3 Replies

8. HP-UX

/dev/Null error

Hi Guru's, I am trying to test the network speed or load by this command. but getting error " Not Connected ". Could you guys please help. ftp> put "|dd if=/dev/zero bs=8k count=1000000" /dev/null Not connected. Please use code tags! (9 Replies)
Discussion started by: sris.sun
9 Replies

9. Shell Programming and Scripting

Redirecting standard out to /dev/null goes to file "/dev/null" instead

I apologize if this question has been answered else where or is too elementary. I ran across a KSH script (long unimportant story) that does this: if ; then CAS_SRC_LOG="/var/log/cas_src.log 2>&1" else CAS_SRC_LOG="/dev/null 2>&1" fithen does this: /usr/bin/echo "heartbeat:... (5 Replies)
Discussion started by: jbmorrisonjr
5 Replies

10. Shell Programming and Scripting

redirect the audio output to /dev/null

I'm using an text-to-speech synthesis in a script, and I need to redirect it's output to /dev/null how can I do that ? And how to redirect the stream to his normal output then (sound card ) ? thankx (2 Replies)
Discussion started by: firelink
2 Replies
All times are GMT -4. The time now is 12:21 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy