Unix/Linux Go Back    


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

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 11-23-2009   -   Original Discussion by CelvinSaran
CelvinSaran's Unix or Linux Image
CelvinSaran CelvinSaran is offline
Registered User
 
Join Date: Nov 2009
Last Activity: 4 December 2009, 12:02 PM EST
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
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 Unix and Linux 11-23-2009   -   Original Discussion by CelvinSaran
aigles's Unix or Linux Image
aigles aigles is offline Forum Advisor  
Registered User
 
Join Date: Apr 2004
Last Activity: 1 December 2014, 9:03 AM EST
Location: Bordeaux, France
Posts: 1,711
Thanks: 2
Thanked 62 Times in 58 Posts


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 Unix and Linux 11-23-2009   -   Original Discussion by CelvinSaran
CelvinSaran's Unix or Linux Image
CelvinSaran CelvinSaran is offline
Registered User
 
Join Date: Nov 2009
Last Activity: 4 December 2009, 12:02 PM EST
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks for quick reply

what the 2>error.txt for?
y 2??
    #4  
Old Unix and Linux 11-23-2009   -   Original Discussion by CelvinSaran
smurphy_it's Unix or Linux Image
smurphy_it smurphy_it is offline
Registered User
 
Join Date: Nov 2009
Last Activity: 12 April 2017, 10:22 AM EDT
Posts: 25
Thanks: 1
Thanked 2 Times in 2 Posts
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 Unix and Linux 11-23-2009   -   Original Discussion by CelvinSaran
mkastin's Unix or Linux Image
mkastin mkastin is offline
Registered User
 
Join Date: Jun 2009
Last Activity: 3 November 2012, 1:28 AM EDT
Posts: 52
Thanks: 1
Thanked 0 Times in 0 Posts
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 Unix and Linux 11-23-2009   -   Original Discussion by CelvinSaran
CelvinSaran's Unix or Linux Image
CelvinSaran CelvinSaran is offline
Registered User
 
Join Date: Nov 2009
Last Activity: 4 December 2009, 12:02 PM EST
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks for help guys Linux
U r really great
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 10:48 AM
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
Error Handling in Korn Shell scripts bhgopi UNIX for Advanced & Expert Users 4 09-06-2005 07:44 PM



All times are GMT -4. The time now is 04:30 AM.