- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- seript help !! cron job
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
Forums
Discussions
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
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
07-09-2002 10:30 PM
07-09-2002 10:30 PM
I have been getting good tips owe to every body, Thanks again...
I want to sort files and mv that sorted files into designated directory.
Files are sorted to created date(not day but month)
cronjob must end of month
ie.)
files created Jan 2002,Feb 2002, Mar 2002...
mv JAN2002,FEB2002,MAR2002,...
designamed directory)
what am I suppose to do?
help me please
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2002 11:10 PM
07-09-2002 11:10 PM
Re: seript help !! cron job
Tough one. Without using some complicated date functions and calculations I use a procedure like this to do these sorts of moves;
1. List all files and grep -v those not from this year; ls -ltr | grep -v " 199" | grep -v " 200"
This will take out all files from years 199* and 200* but leave files from this year.
2. Now, to find the files for the month you want you can do; ls -ltr | grep " Jan "
This will list all files from Jan this year (but by time modified - for created use ls -lctr)
3. Now you can pipe this into a script and process;
To move Jan 2002 files;
for i in $(ls -ltr |grep -v " 199" | grep -v " 200" | grep " Jan "| awk '{print $9}')
do
echo moving $i to
mv $i
done
And you can change Jan to Feb then Mar etc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2002 11:11 PM
07-09-2002 11:11 PM
Re: seript help !! cron job
To help you on the way
look at
http://www.introcomp.co.uk/examples/copybus5.html
To sort a directory by date
#Parameter = directory
cd $1
year=$(date '+%Y')
ll -tr|while read a b c d e f g h i
do
h1=$(echo $h|grep -v ":")
if [ "$h1" = "" ]
then
h=$year
fi
echo $f" "$h" "$PWD"/"$i
done
If you still cannot make your script please log the request for more help
Steve Steel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2002 02:34 AM
07-10-2002 02:34 AM
Re: seript help !! cron job
Use the '-M' option of 'sort'. This compares as months. For instance, the American month names are compared such that JAN < FEB < ... < DEC.
Have a look at the man pages for 'sort' for more information.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2002 10:42 PM
07-10-2002 10:42 PM
Re: seript help !! cron job
Feb has 28th, and each of month has 30, 31 respectively..
who could give the answer..?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2002 11:59 PM
07-10-2002 11:59 PM
Re: seript help !! cron job
If you want to run the script always on the last day of the month the most easiest way :
enter for each month one line into a cron.
This alows you to define on which day of the month it should be running
example for FEB and MAR:
#Min Hour Day Month WeekDay script
0 23 28 2 script.sh
0 23 29 2 script.sh
0 23 31 3 script.sh
To be honest i have no better idea on how to handle years having Feb 29 it depends on your script if my idea is useable for you. Just running it on the 28 and 29 of feb will get you all files of feb moved to the correct dir
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2002 12:15 AM
07-11-2002 12:15 AM
Re: seript help !! cron job
you could run the script every day and check within the script if it is the last day of the month with:
#!/bin/sh
day=$(TZ=MET-24 date +%d) # will look at the next day
if [[ $day -ne 1 ]]
then
exit 0 # not the last day of month
fi
# start here with your code
(In my example i used timezone MET, you have to change this for your timezone)
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2002 12:33 AM
07-11-2002 12:33 AM
Re: seript help !! cron job
could you make clear that
TZ=MET-24 date +%d?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2002 01:27 AM