FTP shell script error caturing

Hello All,
Can anyone let me know how to capure errors in shell scripting?
n even the error considerations?
Like --

  • File not found
    what other errors can occure in that n how those could be captured?

Im_new

assuming sh, ksh, bash or zsh......

script.sh >stdout 2>stderr

Thanks Porter,
It worked.. really thanks.
Now as to proceed, i've to send mail if error is any there, so what can i do is will write another script to check the size of this file, if it's not empty, then only will send mail.. how do u think, does it seems to be ok?
Or is it possible to do anything better like caturing out & mailing the people in the same script?

Regards,
Im_new

With reference to the error capturing again, i have writen a script in which the errors are captured in std.errr file.

ftp_run {

---------
--------
}

ftp_run > $logfile 2> std.errr

Now i want to check whether this file is empty or nor , is yes, for the time i want to echoed the below ststement.

I knw how to check it , so i'm writing the code after the above code as

if (stat -c %s std.errr -lt 1]
then echo "empty file"
fi

but it's throwing -bash: [0: command not found error.
Can anyone help me out?

Regards,
Im_new

With refernce to above one, I'm not getting the errors in, std.err

can anyone tell me the reson? n solution for getting the error into a file?

thanks in advance

regards,
Im new

you get in wrong syntax. see statement below.

The if statement
The if statement uses the exit status of the given command

    if test
    then
        commands     \(if condition is true\)
    else
        commands     \(if condition is false\)
    fi

if statements may be nested:

    if ...
    then ...
    else if ...
    ...
    fi
    fi

Test on numbers :

\(\(number1 == number2\)\)
\(\(number1 != number2\)\)
\(\(number1   number2\)\)
\(\(number1 >  number2\)\)
\(\(number1 = number2\)\)
\(\(number1 >= number2\)\)
    Warning : 5 different possible syntaxes \(not absolutely identical\) :
        if \(\(x == y\)\)
        if test $x -eq $y
        if let "$x == $y"
        if [ $x -eq $y ]
        if [[ $x -eq $y ]]

Test on strings: (pattern may contain special chars)

[[string  =  pattern]]
[[string  != pattern]]
[[string1   string2]]
[[string1 >  string2]]
[[ -z string]]                  true if length is zero
[[ -n string]]                  true if length is not zero
    Warning : 3 different possible syntaxes :
        if [[ $str1 = $str2 ]]
        if [ "$str1" = "$str2" ]
        if test "$str1" = "$str2"

Test on objects : files, directories, links ...

examples :
        [[ -f $myfile ]]            \# is $myfile a regular file?
        [[ -x /usr/users/judyt ]]   \# is this file executable?
\+---------------\+---------------------------------------------------\+
| Test          | Returns true if object...                         |
\+---------------\+---------------------------------------------------\+
| -a object     | exist; any type of object                         |
| -f object     | is a regular file or a symbolic link              |
| -d object     | is a directory                                    |
| -c object     | is a character special file                       |
| -b object     | is a block special file                           |
| -p object     | is a named pipe                                   |
| -S object     | is a socket                                       |
| -L object     | is a symbolic \(soft\) link with another object     |
| -k object     | object's "sticky bit" is set                      |
| -s object     | object isn't empty                                |
| -r object     | I may read this object                            |
| -w object     | I may write to \(modify\) this object               |
| -x object     | object is an executable file                      |
|               |        or a directory I can search                |
| -O object     | I ownn this object                                |
| -G object     | the group to which I belong owns object           |
| -u object     | object's set-user-id bit is set                   |
| -g object     | object's set-group-id bit is set                  |
| obj1 -nt obj2 | obj1 is newer than obj2                           |
| obj1 -ot obj2 | obj1 is older than obj2                           |
| obj1 -ef obj2 | obj1 is another name for obj2 \(equivalent\)        |
\+---------------\+---------------------------------------------------\+

Hi eXedon,

Probabaly, I've asked the question in a wrong way.
Thanks for the suggestion. The problem abt this has been solved.

Now my problem is, apart from this, if any sort of error occures in the script , then it need to be captured in the file, probaly as stated by Porter in the very first reply

But As i'm using this in some program, I can pass the arguments/parameters as these log & error file..
so, i want to ask is there any way to defne error file in script only?

Thanks in advance.

Im_new