The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
error reading sections error at install doelman SUN Solaris 2 02-05-2007 12:21 PM
Error Message chapmana UNIX for Dummies Questions & Answers 5 11-29-2006 11:41 AM
error message dsmv UNIX for Advanced & Expert Users 4 03-01-2006 04:15 AM
Error message ghuber SUN Solaris 0 11-13-2005 04:20 PM
error message alisev UNIX for Dummies Questions & Answers 3 01-08-2002 05:01 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-21-2003
whegra's Avatar
whegra whegra is offline
Registered User
  
 

Join Date: Sep 2002
Posts: 19
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 (permalink)  
Old 11-21-2003
vbshuru vbshuru is offline
Registered User
  
 

Join Date: Nov 2003
Posts: 7
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 (permalink)  
Old 11-21-2003
linuxpenguin's Avatar
linuxpenguin linuxpenguin is offline Forum Advisor  
Registered User
  
 

Join Date: May 2002
Location: India
Posts: 295
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 (permalink)  
Old 11-24-2003
tikual tikual is offline
Registered User
  
 

Join Date: Nov 2003
Location: HK
Posts: 53
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:24 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0