FTP shell script error caturing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting FTP shell script error caturing
# 1  
Old 11-29-2007
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
# 2  
Old 11-29-2007
assuming sh, ksh, bash or zsh......

Code:
script.sh >stdout 2>stderr

# 3  
Old 11-29-2007
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
# 4  
Old 12-27-2007
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
# 5  
Old 01-14-2008
With refernce to above one, I'm not getting the errors in, std.err
Quote:

ftp_run {

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

ftp_run > $logfile 2> std.errr

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

thanks in advance

regards,
Im new
# 6  
Old 01-14-2008
Quote:
if (stat -c %s std.errr -lt 1]
then echo "empty file"
fi
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) |
+---------------+---------------------------------------------------+
# 7  
Old 01-15-2008
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

Quote:
script.sh >stdout 2>stderr

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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need a Shell Script for FTP

Hello Brothers, I am new in shell script.I need a shell script that will run in Linux Server. Script will connect to windows FTP server before connection script will check the connection from linux server to windows server, if connection is ok then show a message and get specific file and... (34 Replies)
Discussion started by: maruf
34 Replies

2. Shell Programming and Scripting

Help with Shell script for FTP

#!/usr/bin/ksh export filename=/grid/PowerCenter/inbound/AT/filelist.txt export SOURCE_DIR=/grid/PowerCenter/inbound/AT export ICOMS_FTP_TGT_DIR1=/dw/input/ATU/ICOM_SERV1 export ICOMS_FTP_TGT_DIR2=/dw/input/AT/ICOM_SERV2 export FILE_MASK="ATRPU_RP_ATU" echo "start" ftp_data_file() { ... (15 Replies)
Discussion started by: vsmeruga
15 Replies

3. UNIX for Dummies Questions & Answers

FTP shell script

Hi I am new in UNIX field. I don't know if I am posting in right forum or not. And I have also found out that there are so many posts about ftp shell scripting. I have tried those but actually having some problem. Well, my script should do the following..... It finds files( the filename ended... (3 Replies)
Discussion started by: abhishek_510
3 Replies

4. Shell Programming and Scripting

Use ftp is a shell script

Hi, What i would like to do is to use a shell script connect to a remote computer and download files from a specific directory. I wrote the following script. #!/bin/sh HOST='IP' USER='yourid' PASSWD='yourpw' FILE='*.txt' REMOTEPATH=/incoming/MSC/ ftp $HOST <<END_SCRIPT user $USER... (3 Replies)
Discussion started by: chriss_58
3 Replies

5. Shell Programming and Scripting

FTP using shell script

Hi All, I want to make a ftp call using a separate file where the ftp commands will reside. Please find below the details: I have 2 files Sample1.sh and Properties Properties --------- <username> <password> .... other ftp commands Sample1.sh ---------- ftp -v <servername> <... (1 Reply)
Discussion started by: pickpeters
1 Replies

6. UNIX for Advanced & Expert Users

FTP in shell script

HI ALL i am writing a shell script in which i have to use FTP command like. FTP <ip address> cd xyz mget* bye but i am not able to perform any command from shell script. once the control goes to FTP, i again have to type all the things. i just want my shell script to take care of the... (8 Replies)
Discussion started by: infyanurag
8 Replies

7. Shell Programming and Scripting

FTP via shell script

Hi, I need to upload a file via ftp. I have given : ftp -n $HOST <<END quote user $USER quote pass $PASSWD prompt off put bus.txt quit END Its throwing a syntax error at "<<" symbol. What should be done for this ?? (2 Replies)
Discussion started by: risshanth
2 Replies

8. UNIX for Dummies Questions & Answers

Shell script for ftp

Hi ,, I am wrting a shell script to ftp a file from remote server but its giving some problem to me.can you help me in debugging this. #!/usr/bin/ksh HOST="some ip" user="user_name" passwd="password" ftp -n $HOST >>END_SCRIPT USER $user $passwd binary prompt get... (3 Replies)
Discussion started by: namishtiwari
3 Replies

9. Shell Programming and Scripting

ftp in shell script

Hi, I have to ftp to a remote machine. i have got the Ip, username and password and the file path.. I need to get the file name with out user intervention in my script.. is there any way to do this.. please help esham (2 Replies)
Discussion started by: esham
2 Replies

10. Shell Programming and Scripting

using ftp in a shell script.

I am trying to ftp some files from a certain directory, but i got an invalid command. does anybody know why i got this error? ftp -v -i -n <<SCRIPT open servername user username password cd /server/logs for file in MCWAS* do put ${file} /home/test/${file} done bye SCRIPT (2 Replies)
Discussion started by: caesarkim
2 Replies
Login or Register to Ask a Question