- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- script question
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2002 06:05 AM
01-25-2002 06:05 AM
I am running a following script to look for 3 days old file (file has a time stamp with it) and mv it to JAN directory, now what I want is that when the Feb starts, script will create dir by the name FEB and start mv the feb files to FEB dir and so on, any suggestion, Thanks in advance.
filename=" "
cd /log/moe
for filename in `find . \( -name 'MoeL*' -o -name 'MoeP*.log' -o -name 'moe_s*' -o
-name 'moe.log*' \) -mtime +3 -print`
do
mv $filename /archive/logbackup/$filename
done
cd /archive
file=`find /archive/logbackup -type f -print|wc -l`
if [ $file -eq 0 ]
then
exit
else
compress *
mv *.Z /archive/moe/log/JAN/
cd /archive/logbackup
rm *
fi
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2002 06:12 AM
01-25-2002 06:12 AM
SolutionSomething along these lines:
======================================
month=`date "+%b" | tr [a-z] [A-Z]`
test -d /archive/moe/log/${month} || mkdir -p /archive/moe/log/${month}
filename=" "
cd /log/moe
for filename in `find . \( -name 'MoeL*' -o -name 'MoeP*.log' -o -name 'moe_s*' -o
-name 'moe.log*' \) -mtime +3 -print`
do
mv $filename /archive/logbackup/$filename
done
cd /archive
file=`find /archive/logbackup -type f -print|wc -l`
if [ $file -eq 0 ]
then
exit
else
compress *
mv *.Z /archive/moe/log/${month}/
cd /archive/logbackup
rm *
fi
========================================
I'm assuming on Feb 1st, you don't mind those files from Jan 31st, say, ending up in the FEB directory.
Rgds, Robin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2002 06:18 AM
01-25-2002 06:18 AM
Re: script question
If you want to use the month as of the time the script runs then do something like this:
.
.
.
compress *
MONTH=`date +%b | tr "[:lower:]" "[:upper:]"`
if [ ! -d /archive/moe/log/${MONTH} ]
then
mkdir /archive/moe/log/${MONTH}
fi
mv *.Z /archive/moe/log/${MONTH}
Darrell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2002 06:36 AM
01-25-2002 06:36 AM
Re: script question
what about this:
month=`date +%b|awk '{sub("\.","",$1);print toupper($1)}'`
[ ! -d /archive/moe/log/$month ] && mkdir /archive/moe/log/$month
cd /log/moe
find . \( -name 'MoeL*' -o -name 'MoeP*.log' -o -name 'moe_s*' -o -name 'moe.log*' \) -mtime +3 -print |
while read filename
do
mv $filename /archive/moe/log/$month
compress /archive/moe/log/$month
done
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2002 06:40 AM
01-25-2002 06:40 AM
Re: script question
Line:
compress /archive/moe/log/$month
should be:
compress /archive/moe/log/$month/$filename
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2002 08:02 AM
01-25-2002 08:02 AM
Re: script question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2002 08:37 AM
01-25-2002 08:37 AM
Re: script question
If it is Feb day 01 mv to Jan
else
mv to Feb.
This is not the exact syntax of course but with all the excellecent examples for using the date command in the other posts. I am sure you get they syntax from those examples.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2002 12:53 PM
01-25-2002 12:53 PM
Re: script question
You can change your criteria for setting the target directory. Instead of baseing it on the current date you can use the name of the file itself.
Here's a snippet of code to get you going. This assumes the files are named *log.yy-mm-dd and you want to use mm to determine which directory to place the file in.
for i in `ls *log*`
do
month=`echo $i | awk -F. '{print $NF}' | cut -c4-5`
case $month
in
01) MONTH=JAN;;
02) MONTH=FEB;;
.
.
.
12) MONTH=DEC;;
esac
compress $i
if [ ! -d ${MONTH} ]
then
mkdir ${MONTH}
fi
mv $i.Z ${MONTH}
done
Darrell