Shell Programming and Scripting

BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Error Handling

👤 Login to reply

    #1  
Old 11-23-2009
CelvinSaran CelvinSaran is offline
Registered User
 
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
Sponsored Links
    #2  
Old 11-23-2009
aigles's Unix or Linux Image
aigles aigles is offline Forum Advisor  
Registered User
 
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.
Sponsored Links
    #3  
Old 11-23-2009
CelvinSaran CelvinSaran is offline
Registered User
 
Thanks for quick reply

what the 2>error.txt for?
y 2??
    #4  
Old 11-23-2009
smurphy_it smurphy_it is offline
Registered User
 
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
Sponsored Links
    #5  
Old 11-23-2009
mkastin mkastin is offline
Registered User
 
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).
Sponsored Links
    #6  
Old 11-23-2009
CelvinSaran CelvinSaran is offline
Registered User
 
Thanks for help guys
U r really great
Sponsored Links
👤 Login to reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Extended Error Handling (EEH) - E142C6D4 okbainf AIX 1 07-06-2009 09:48 AM
SFTP Error Handling deepusunil Shell Programming and Scripting 2 08-06-2008 06:44 AM
Error Handling -pls advice sureshg_sampat Shell Programming and Scripting 2 07-12-2008 01:10 PM
Handling ftp error vivek_damodaran Shell Programming and Scripting 1 06-23-2008 10:37 PM
Error Handling in Korn Shell scripts bhgopi UNIX for Advanced & Expert Users 4 09-06-2005 06:44 PM



All times are GMT -4. The time now is 04:21 PM.

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





Not a Forum Member?
Forgot Password?