Redirecting standard error issues.

Hello Friends,

Good Day.

I am trying to redirect a standard error to the bit bucket(/dev/null) but it is not working. Though, it is working fine in redirecting the standard output.

Below is the output of my script without any redirection:

[tibco@auktltar DailyCheckScript]$ ./CheckVSSLocks.sh
----------------------------------------------------------------
*************************VSS2 Locks*****************************
----------------------------------------------------------------
Domain                     Status
The Vss2 log files are not found for ICCIR2Test01
The Vss2 log files are not found for ICCIR2Test02
The Vss2 log files are not found for ICCIR2Test04
The Vss2 log files are not found for ICCIR2Test06
The Vss2 log files are not found for ICCIR2Test07
The Vss2 log files are not found for ICCIR2Test08
The Vss2 log files are not found for ICCIR2Test09
The Vss2 log files are not found for ICCIR2Test10
The Vss2 log files are not found for ICCIR2Test11
The Vss2 log files are not found for ICCIR2Test12
The Vss2 log files are not found for ICCIR2Test13
The Vss2 log files are not found for ICCIR2TEST14
The Vss2 log files are not found for ICCIR2Test15
The Vss2 log files are not found for ICCIR2TEST16
The Vss2 log files are not found for ICCIR2Tiest15
The Vss2 log files are not found for ICCIRSTDEV03
cat: Vss2logs.txt: No such file or directory
rm: cannot remove `Vss2log*': No such file or directory

Here is the output with redirection:

[tibco@auktltar DailyCheckScript]$ ./CheckVSSLocks.sh 2>&1 >/dev/null
cat: Vss2logs.txt: No such file or directory
rm: cannot remove `Vss2log*': No such file or directory

Can you please let me know what exactly is the issue and how it can be sorted out?

Thanks,
Chandan Singh

i think its working. its showing.. u what is the error.

Hi,

Thanks for your prompt response.

Is it possible to redirect it? I am going to add this script to the crontab.

So, bit worrying if it causes any problem during its schedule execution.

./CheckVSSLocks.sh 2> /dev/null > &1

i think this is what u were asking.. check this.

cat yourfile 1> somefile 2> /dev/null

if the above command works for u then u dnt have to worry about .. putting it in crontab. u can put in cron widut worrying.

Sorry, no luck.

Now it is giving me syntax error. I am using Linux .

[tibco@auktltar DailyCheckScript]$ ./CheckVSSLocks.sh 2 >/dev/null > &1
-bash: syntax error near unexpected token `&'

Wrong:

 ./CheckVSSLocks.sh 2 >/dev/null > &1

should be:

 ./CheckVSSLocks.sh 2 >/dev/null

Can you explain what you're trying to achieve?

  • Redirect the output and the errors to one file?
  • Redirect the output and the errors to separate files?
  • Redirect the output to a file and the errors to /dev/null?
CheckVSSLocks.sh 1>fil.txt 2>/dev/null

is this working for u

chandan Singh,

may I ask, why are you using "&1" at the end of the command. for shell this makes no sense and causes the error message you see.

If you are trying to mix both stderr and stdout to single file then try using

./CheckVSSLocks.sh 2&>1 /dev/null --> this will wipe all output from script to /dev/null

and if you want your stderr and stdout separated, try

./CheckVSSLocks.sh 2 >/dev/null 1> somefile

Hi,

This script will be executed by a cron job every hour during the day. It will check the application logs in some directory and redirect(I will hardcoded this in the script) them to a logfile.
The log file will then send as an attachement to the concern persons.

I just wanted to make sure, if there is no files in the directory then it shouln't throw the errors. Instead, the errors should be redirected to /dev/null.

I am using "&1" at the end of the command for the silent running of the script as I dont need anything to be displayed on the screen.

Plese let me know if you need any other informations.

&1
or
> &1
really makes me uncomfortable.

can you please tell what this really means

This is incorrect, that should be:

./CheckVSSLocks.sh >/dev/null 2>&1 

Okay.

what about

./CheckVSSLocks.sh 2&>1 > /dev/null 

Hi busyboy, do you mean:

./CheckVSSLocks.sh 2>&1 > /dev/null

that will not work either. It will only redirect stdout to /dev/null.

This is working perfectly..

Thanks for your inputs.

---------- Post updated at 06:09 PM ---------- Previous update was at 06:02 PM ----------

Hi Guys,

Thanks all for your inputs.

I used ./CheckVSSLocks.sh >/dev/null 2>&1 and it is giving me the desired result.:slight_smile: