Error Handling

Tags
shell scripts

Login to Reply

 
Thread Tools Search this Thread
# 1  
Old 11-23-2009
Error Handling

Helo Experts,
I need a help in handling errors in shell script, wants my errors displayed in text file instead of command window..
My shell script is here;

cd /cygdrive/s/Files
for FILES in ./*.*
do
temp=`basename $FILES`

if cp $FILES /cygdrive/r/CopyFile1/$FILES; then
echo "copy successful"
echo "$temp ">> /cygdrive/r/LogFiles/logfiles.rtf

else
echo "copy failed"
fi
done

By doin if..else i can manage to output copy successful or failes..but i receive error thrown during cp $FILES /cygdrive/r/CopyFile1/$FILES.
That error is displayed in command wondow ( im using cygwin).
Anyone can guide me on how can i handle that error where the error should be in text file (error.txt) and my output only shows copy failed or successful

your help is much appreciated
# 2  
Old 11-23-2009
Code:
cd /cygdrive/s/Files
for FILES in ./*.*
do
   temp=`basename $FILES`

   if cp $FILES /cygdrive/r/CopyFile1/$FILES 2>error.txt ; then
      echo "copy successful"
      echo "$temp ">> /cygdrive/r/LogFiles/logfiles.rtf

   else
      echo "copy failed"
   fi
done

Jean-Pierre.
# 3  
Old 11-23-2009
Thanks for quick reply

what the 2>error.txt for?
y 2??
# 4  
Old 11-23-2009
STD redirection

0 = Standard Input
1 = Standard Output
2 = Standard Error

the 2>error.txt would redirect all output from standard errors, into a file called error.txt
# 5  
Old 11-23-2009
There are three standard sources of input and output for a program. Standard input usually comes from the keyboard if it’s an interactive program, or from another program if it’s processing the other program’s output. The program usually prints to standard output, and sometimes prints to standard error. These three file descriptors called STDIN (0), STDOUT (1), and STDERR (2).
# 6  
Old 11-23-2009
Thanks for help guys Smilie
U r really great
Login to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Similar Threads More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Advice on how to set up error handling SIMMS7400 UNIX for Beginners Questions & Answers 2 10-20-2017 07:06 PM
Error handling for file Rizzu155 Shell Programming and Scripting 1 01-08-2013 09:47 AM
Error handling Learn4Life Shell Programming and Scripting 5 08-10-2012 02:05 AM
Perl file handling error Beginer123 Shell Programming and Scripting 8 06-07-2012 04:50 AM
Expect Script Error Handling thaller Shell Programming and Scripting 3 02-17-2012 10:02 AM
Error Handling ambarginni Shell Programming and Scripting 4 02-16-2012 02:03 AM
PERL error handling OTChancy Shell Programming and Scripting 1 08-31-2011 12:45 PM
Help needed with error handling stunnerz_84 Shell Programming and Scripting 6 02-16-2011 05:19 PM
Help with Error Handling on Script rrb2009 Shell Programming and Scripting 3 01-13-2011 01:16 PM
FTP error handling - critical viki250 Solaris 8 11-01-2010 12:32 PM
Perl Error Handling Problem mrlayance Infrastructure Monitoring 4 05-27-2010 09:06 AM
Finger and error handling beatblaster666 Shell Programming and Scripting 2 04-22-2010 11:29 PM
SFTP Error Handling deepusunil Shell Programming and Scripting 2 08-06-2008 07:44 AM
Error Handling -pls advice sureshg_sampat Shell Programming and Scripting 2 07-12-2008 02:10 PM
Handling ftp error vivek_damodaran Shell Programming and Scripting 1 06-23-2008 11:37 PM
All times are GMT -4. The time now is 02:13 AM.

Unix & Linux Forums Content Copyright 1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password





Not a Forum Member?
Forgot Password?