Reading an Error message


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Reading an Error message
# 1  
Old 11-21-2003
Reading an Error message

I have a script that reads a file then moves all the files that are listed within that file.

So read file A then copy all files that are listed within.

I have the script append a log everytime a file is moved.

My issue is that it's appending the log even though the file was not found.

here's part of my script

Code:
 cat /path/to/file/$file1 | while read a
do
  var1=`echo "$a"`
  mv /path/to/data/'$var1' /path/to/new/location
echo "Moved File" $var1 >> /path/to/file/logs/filesmoved$year$month$day.txt
done < /path/to/file/$file1

I see error msg mv: cannot access /path/to/data/$var1: No such file or directory (error 2)

how do I get my script to read that error msg. or does it put it to a variable by default?

Once I find that out I can make a test condition before writing to the log.

Thanks
# 2  
Old 11-21-2003
cat /path/to/file/$file1 | while read a
do
var1=`echo "$a"`
mv /path/to/data/'$var1' /path/to/new/location

if [ $? -eq 0 ]
then
echo "Moved File" $var1 > /path/to/file/logs/filesmoved$year$month$day.txt
fi

done < /path/to/file/$file1
# 3  
Old 11-21-2003
very simple

mv /path/to/data/'$var1' /path/to/new/location 2>/dev/null

However, it is always a good practice to log all kind of messages in your log. This can help you find if anything is messed up.

I guess you must be knowing about redirection, but still since this question is related to that let me explain what exactly the 2>/dev/null do

well 2 stands for the file descriptor, standard errors. so any errors that are directed to standard error are written in file descriptor 2. by doing 2> you are asking to redirect the standard errors. /dev/null is a null device. so 2>/dev/null is instructing to direct standard errors to a null device instead of the console or your error log

other standard file descriptors are
0 standard output
1 standard input

one more remark i feel "done < /path/to/file/$file1" is redundant, you may discard it as well since you are already doing a "cat < /path/to/file/$file1"


let me make this a bit more straight, (if i havent misinterpreted what you intend to do)

cat /path/to/file/$file1 | while read a
do
mv /path/to/data/"$a" /path/to/new/location 2>/dev/null
echo "Moved File" $a" >>/path/to/file/logs/filesmoved$year$month$day.txt 2>/dev/null
done
# 4  
Old 11-24-2003
Try to change your script as follows:

while read a
do
var1=`echo "$a"`
mv /path/to/data/"$var1" /path/to/new/location #Use double quote
echo "Moved File" $var1 >> /path/to/file/logs/filesmoved$year$month$day.txt
done < /path/to/file/$file1 # No need to cat file in first line if you have this line.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. SCO

Error: msgcnt 1 vxfs: mesg 016: vx_ilisterr - / file system error reading

Hello... i got an error in my SCO OpenServer 6. the error is: msgcnt 1 vxfs: mesg 016: vx_ilisterr - / file system error reading inode 373 Can anyone help me? (1 Reply)
Discussion started by: AndryMB
1 Replies

2. UNIX for Advanced & Expert Users

ssh error: Error reading response length from authentication socket

Hi - I am getting the error `Error reading response length from authentication socket' when I ssh from my cluster to another cluster, and then back to my cluster. It doesn't seem to affect anything, but it's just annoying that it always pops up and tends to confuse new users of the cluster. I... (1 Reply)
Discussion started by: cpp6f
1 Replies

3. UNIX for Dummies Questions & Answers

Error Message

I am getting a error message when I try to assign this? Can someone help I am new to unix? $ First-name=james ksh:First-Name=james not found (1 Reply)
Discussion started by: vthokiefan
1 Replies

4. Linux

error message

Hello I got this message error on my box with linux red hat 2887a374 WsServer E WSVR0009E: Error occurred during startup Do you know what does that mean ! Thanks in advance (1 Reply)
Discussion started by: lo-lp-kl
1 Replies

5. Solaris

error reading sections error at install

Hi, I'm trying to install Solaris 10 on my Ultra 10 but it won't boot. I tried an original cd and a downloaded one. I got the following error: "error reading sectors" (yes, i checked the md5 sums) For the complete error see the following shot: ... (2 Replies)
Discussion started by: doelman
2 Replies

6. UNIX for Dummies Questions & Answers

Error Message

I keep getting an error message in a script im writing, this line is allways pointed out. if and this is the message i keep getting. line 32: [: 8: unary operator expected Whats wrong with it? Please Help. (5 Replies)
Discussion started by: chapmana
5 Replies

7. UNIX for Advanced & Expert Users

Error message

Hi, My Solaris 5.8 system keeps getting this error at boot - "Can't set vol root to /vol" then /usr/sbin/vold: can't set vol root to /vol: Resource temporarily unavailiable Any idea what is wrong, and how do I fix it? (1 Reply)
Discussion started by: ghuber
1 Replies

8. Solaris

Error message

Hi, My Solaris 5.8 system keeps getting this error at boot - "Can't set vol root to /vol" then /usr/sbin/vold: can't set vol root to /vol: Resource temporarily unavailiable Any idea what is wrong, and how do I fix it? (0 Replies)
Discussion started by: ghuber
0 Replies

9. AIX

Error Message with ls

When I try to list a directory that I have been using rsync to copy, I now am getting the following message. root # ls -alt /directory ls: /directory: Value too large to be stored in data type. total 0 I can change directory and list the contents of directories within /directory, but I... (2 Replies)
Discussion started by: sallender
2 Replies

10. UNIX for Advanced & Expert Users

Error message

I'm getting an error - symbol referencing errors. No output written to, etc Can anybody tell me why this is? (2 Replies)
Discussion started by: Dan Rooney
2 Replies
Login or Register to Ask a Question