Error Handling -pls advice


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Error Handling -pls advice
# 1  
Old 07-11-2008
Error Handling -pls advice

Dear friends,

I am using the below command in my unix script
-----------------------------------------------
File_Name=`ls $CTRY*$DATE_SUFFIX*zip` --> Command-1

.....
if [ -f $FTP_DIR/$File_Name ]
then
unzip -a $File_Name -d $CTRY_DIR/$CTRY
else
echo "File for $CTRY dated $DATE_SUFFIX does not exist in $FTP_DIR"
fi

But I get the following error message printed on UNIX screen , which I want to get rid off. I think this error message appears owing to failure of ls command in COmmand-1 as stated above

Error message printed on screen is
KE*20080711*zip not found

CAn you please advice how to get rid of this messages to be printed on screen. Instaed can we move such errors to temp files

Regards
Suresh
# 2  
Old 07-11-2008
Hammer & Screwdriver Couple of things at work here.

First, there is the assignment of the filename variable.
Code:
> mfilename=$(ls z52075.*.zip)
> echo $mfilename
z52075.per.files.zip
> mfilename=$(ls z52075.*.zip2)
ls: cannot access z52075.*.zip2: No such file or directory
> mfilename=$(ls z52075.*.zip2 2>/dev/null)
> echo $mfilename

>

Above, the first set the filename which was found from the ls command. See my echo of the variable. I then try to set to a file I know the ls will not find - and you can see the unix error condition returned. Tried agin; and I added the error handling. Note my second echo returns nothing.

Second, you are checking for -f or ordinary file. Is a zip file ordinary? I think I would be doing a -s to see if the file has non-zero length.
# 3  
Old 07-12-2008
Error Handling -pls advice

Thanks for inputs,
Using -f , actually I am checking for presence of the zip file
If present , then only I proceed further
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Advice on how to set up error handling

Hi Folks - I want to add error handling to a portion of a *.ksh, but I'm having difficulty doing so in an easily digestible way. Essentially, I want to echo weather it was successful or unsuccessful after each command. Here is the code I need to add error handling to: perl... (2 Replies)
Discussion started by: SIMMS7400
2 Replies

2. Shell Programming and Scripting

Pls Help: SFTP Error Handling for transfers

I am working on a shell script where after making sftp connection to a remote server the file are being transferred. The problem is how to capture return code for the file which is missing at the remote location. I have tried to capture the return code which return value of "0" even the transfer of... (4 Replies)
Discussion started by: Khan28
4 Replies

3. Shell Programming and Scripting

New advice on error checking

HI All, Whenever I write a shell script I always check if a command got executed successfully, even for the commands like cd, mv, rm and others, and even for the cases when there is ALMOST nothing to stop this commands from executing with success. so I am wondering if it is an overkill. I am... (1 Reply)
Discussion started by: rdogadin
1 Replies

4. Shell Programming and Scripting

Error handling

Hello fellow UNIX gurus :) I have a problem regarding the script below: # Variables used in this shell. power=0 # Stores squared integer total=0 # Sum of all squared integers num=0 # Stores command line arguements # Provides error handling if command line... (5 Replies)
Discussion started by: Learn4Life
5 Replies

5. Shell Programming and Scripting

Error Handling

Below code works for different databases i.e. MYSQL and ORACLE The problem is for MYSQL in Block: if ; $? taking value accordingly but in case of ORACLE $? is always taking this value as zero (0). That is the reason in Oracle it always going in else Block in any case.. :( and in case of ... (4 Replies)
Discussion started by: ambarginni
4 Replies

6. Red Hat

Advice regarding filesystems handling large number of files

Hi All, I have a CentOS operating system installed. I work with really huge number of files which are not only huge in number but some of them really huge in size. Minimum number of files could be 1 million to 2 million in one directory itself. Some of the files are even several Gigabytes in... (2 Replies)
Discussion started by: shoaibjameel123
2 Replies

7. Shell Programming and Scripting

help pls getting EOF error

#!/bin/bash while : do clear echo ""***************************************" echo "* - MAIN - MENU - *" echo "***************************************" echo "* 1. Directory Listing *" echo "* 2. Users Currently Logged In *" echo "* 3. Create a... (2 Replies)
Discussion started by: celtic123
2 Replies

8. Programming

C - advice how to catch some weird error

I have some unstable mistake in my program and out-of-idea how to catch it. I am looking for advice with a way to work it out! I have in a pretty complicated program (but one source file) set of int-counters - 15, if exactly. Lately, on final printout I have inpossible value (I am... (3 Replies)
Discussion started by: alex_5161
3 Replies

9. Shell Programming and Scripting

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... (5 Replies)
Discussion started by: CelvinSaran
5 Replies

10. Programming

Pls give me some advice

hi everyone i have a problem in design as follows: there is a structured file ,for example , field 1, field 2 ....... -------------- -------------- i read it into my memory ,there are some change in the memory maybe add some record or change one field in an existing record. i am going... (1 Reply)
Discussion started by: benbenpig
1 Replies
Login or Register to Ask a Question