The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
file command rprajendran UNIX for Advanced & Expert Users 3 05-13-2008 10:45 AM
rm command not able to remove file jambesh Shell Programming and Scripting 7 12-21-2007 03:37 AM
What is the command to add heading to a file? whatisthis UNIX for Dummies Questions & Answers 3 12-01-2005 11:17 PM
VI command for File Please $Circle$ UNIX for Dummies Questions & Answers 12 09-05-2005 01:23 AM
End of file using more command Enda Martin UNIX for Dummies Questions & Answers 3 06-18-2001 07:49 AM

Closed Thread
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-25-2001
Registered User
 

Join Date: Jan 2001
Posts: 9
Stumble this Post!
Angry for file in ???? - command

using <B>Bourne shell</B> how can I list all files in such a directory that file name don't match a pattern.

e.g:
a dir. /mydir contains these files
[tamer001]-/mydir$ ls
2001-01-23.log
2001-01-23_08-30.log
2001-01-23_15-59.log
2001-01-24_00-00.log
2001-01-24_11-52.log
2001-01-24_18-34.log
2001-01-25.log
2001-01-25_13-30.log

I want to move all files except the files of 25th of the month (which is today files) and rename the files by adding a string to the begining of the file name.

so here what I did:
Code:
#!/usr/bin/sh
dir=/var/dist
cd /mydir

for file in *.log
do
 if [ -f $file ]
  then
    if /usr/bin/mv $file $dir/access_log_$file
    then
        echo "$file : moved to $dir successfuly "
    else
        echo "can not move or rename access_log_$file"
    fi
  fi
done
how can I exclude moving today log files from the dir /mydir ?

please help.

[Edited by tamer on 01-28-2001 at 05:42 PM]
added code tags for readability --oombera

Last edited by oombera; 02-19-2004 at 01:38 PM.
Forum Sponsor
  #2 (permalink)  
Old 01-25-2001
PxT's Avatar
PxT PxT is offline
Registered User
 

Join Date: Oct 2000
Location: Sacramento, CA
Posts: 909
Stumble this Post!
DATE=`/bin/date "+%Y-%m-%d"`
for file in !(${DATE}*.log); do
do
...

done
  #3 (permalink)  
Old 01-26-2001
Registered User
 

Join Date: Jan 2001
Posts: 9
Stumble this Post!
Quote:
Originally posted by PxT
DATE=`/bin/date "+%Y-%m-%d"`
for file in !(${DATE}*.log); do
do
...

done
Thanks for reply.
but is this in Bourne Shell !!

because this error occured after running the script

test.sh: syntax error at line 7: `!' unexpected
Code:
#!/usr/bin/sh

dir=/var/dist
cd /mydir
DATE=`/usr/bin/date "+%Y-%m-%d"`

for file in !(${DATE}*.log); 
do
  if [ -f $file ]
  then
    if /usr/bin/mv $file $dir/access_log_$file 
     then
       echo "$file : moved to $dir successfuly " 
     else
       echo "can not move or rename access_log_$file"
    fi
  fi
done
added code tags for readability --oombera

Last edited by oombera; 02-19-2004 at 01:38 PM.
  #4 (permalink)  
Old 01-26-2001
PxT's Avatar
PxT PxT is offline
Registered User
 

Join Date: Oct 2000
Location: Sacramento, CA
Posts: 909
Stumble this Post!
Sorry, I dont know enough about the Bourne shell to help you. My answer will work in bash or ksh.
  #5 (permalink)  
Old 01-28-2001
Registered User
 

Join Date: Jan 2001
Posts: 9
Stumble this Post!
Angry

OK thanks PxT.

any one can help me.
  #6 (permalink)  
Old 01-28-2001
Neo's Avatar
Neo Neo is offline
Administrator
 

Join Date: Sep 2000
Location: Asia Pacific
Posts: 4,264
Stumble this Post!
Lightbulb

Tamer: Seems like a good exercise to take PxT's script and convert it to the shell script you want. I thought PxT did a great job answering this for you. After all, if you have the script in one shell, it should be minimal work to figure out how to convert it to another. It is good practice for you to do a little 'shell conversion' don't you think? Please post your version when you are finished so others can learn from your work too!
  #7 (permalink)  
Old 01-29-2001
Registered User
 

Join Date: Jan 2001
Posts: 9
Stumble this Post!
Wink

Quote:
Originally posted by Neo
Tamer: Seems like a good exercise to take PxT's script and convert it to the shell script you want. I thought PxT did a great job answering this for you. After all, if you have the script in one shell, it should be minimal work to figure out how to convert it to another. It is good practice for you to do a little 'shell conversion' don't you think? Please post your version when you are finished so others can learn from your work too!

Thanks; but I was spent 2 days to write 200 line of code to logroll my mail server log files, zip them and transfer them to another server for anther purposes; and this was the only problem I faced, anyway I will do it and post it again.
Google The UNIX and Linux Forums
Closed Thread

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:46 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0