Date listing in a date range


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Date listing in a date range
# 1  
Old 08-08-2013
Date listing in a date range

Solaris 10
ksh88

Sorry for re-hashing some of this, but I can't find a proper solution in the forums.

Starting with /a/archive containing (on and on date formatted directories)
Code:
20060313           20080518           20100725           20121015
20060314           20080519           20100726           20121107
20060315           20080520           20100727           20121109
20060316           20080521           20100728           20121115
20060317           20080522           20100729           20121130
20060318           20080523           20100730           20121218

Requirement is:

Based on start date: YYYYMMDD and end date in same format
to list out all of the dates including start and end in the whole range..

You can assume that the start and end dates are entered in this format.

The dates are actually directory names, and I need to go into each directory (in reverse date order) and issue a command while checking other certain conditions.

Any help would be appreciated!!
-Greg

Basically I need to wrap the following into a loop and continue processing date directories:
Code:
#!/bin/ksh

START=$1
END=$2
FILES=$3
TOT=0
EXCEED=20
## Get dates in the range??????

cd /a/archive/$DATE_CURR
stage *

## Find the number of active tape drives by user 900
ACTIVE_NUM=$(samcmd n|grep '900'|wc -l)

## Throttle if more than 3 tape drives in use by user 900
if [[ ${ACTIVE_NUM} -gt 3 ]]
then
    echo "Users are busy"
    exit
fi

## Find wait time of drives for user 900
    # Get highest wait time of all drives
##    WAIT=$(samcmd n|grep '900'|awk '{print $5}'|sed -e 's/\://g'|sort|tail -1)
    TIME=$(samcmd n|grep '900'|awk '{print $5}'|sort|tail -1)
##    echo ${TIME}
    HOUR=$(echo ${TIME} | cut -f1 -d:)
##    echo ${HOUR}
    MIN=$(echo ${TIME} | cut -f2 -d:)
##    echo ${MIN}
    WAIT=$(echo "${HOUR} * 60 + ${MIN}"|bc)
##    echo ${WAIT:-444}
    # If wait time exceeds threshold, send email
    if [[ ${WAIT} -gt ${EXCEED} ]]
    then
        MSG="$(printf "At least one tape drive has been waiting for ${WAIT} minu
tes\n\n")

$(samcmd n)"
## WAIT HERE ???

## Get number of files processing
for line in $(samcmd n | grep active | awk '{print $6}')
do
    TOT=$(expr ${TOT} + ${line})
done

##printf "Total number of files: $TOT\n\n"

# Check if limit exceeded, if so, send email recording ending spot and exit
if [[ ${TOT} -gt ${FILES} ]]
then
    echo "Staging Limit Exceeded"
    samcmd n|mailx -s "Staging Limit Exceeded" email1@company.com,email2@company.com
    exit
fi

And the Get dates in the range, is where I get stuck at...

Last edited by moesplace; 08-08-2013 at 06:18 PM.. Reason: Clarification
# 2  
Old 08-08-2013
Need GNU date with -d option.
Code:
START="20080518"
END="20121015"

EPOCS=$(date -d "$START" +%s)
EPOCE=$(date -d "$END" +%s)

for (( i=$EPOCS; i<=$EPOCE; i=i+3600*24 ))
do
  date -d @$i +%Y%m%d
done

20080518
20080519
20080520
...
20121012
20121013
20121014

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Date range

Dear all, how can I select in the file below only the files created between Aug 14 2014 and Feb 03 2015? EZA2284I -rw-r--r-- 1 30 8 356954 Aug 15 2014 file1 EZA2284I -rw-rw-r-- 1 30 8 251396 Feb 05 12:53 file2 EZA2284I -rw-rw-r-- 1 30 8 ... (3 Replies)
Discussion started by: simomuc
3 Replies

2. UNIX for Dummies Questions & Answers

Find the count of files by last created date based on the given date range

My unix version is IBM AIX Version 6.1 I tried google my requirement and found the below answer, find . -newermt “2012-06-15 08:13" ! -newermt “2012-06-15 18:20" But newer command is not working in AIX version 6.1 unix I have given my requirement below: Input: atr files: ... (1 Reply)
Discussion started by: yuvaa27
1 Replies

3. AIX

Date not appearing when listing using ls -la

Hi everyone, this strange error suddenly popped up out of no where when I do a directory listing , the date part doesn't appear root@oradb:/backup>ls -la total 58069304 drwxr-xr-x 3 root system 4096 23 ▒▒▒ 21:56 . drwxr-xr-x 44 root system 1536 23 ▒▒▒ 21:47... (4 Replies)
Discussion started by: filosophizer
4 Replies

4. Shell Programming and Scripting

Confused with date - listing

Hello,:) Can anyone help me out in giving a script for my requirement please.. I have a number of files in a directory like somenumber.0100 somenumber.0130 somenumber.0159 somenumber.0300 somenumber.0330 somenumber.0525 . . . here, the number after the dot is the time (hhmm) I... (6 Replies)
Discussion started by: Raghu8985
6 Replies

5. UNIX for Dummies Questions & Answers

Listing based on User and Date

listing based on user. I have files in some folder that come from many user -rwxrwxr-x 1 ratih pbank 4827112 Jun 8 08:37 S92TA-8.sgy -rwxrwxr-x 1 ratih pbank 4724568 Jun 8 08:37 S92TA-6.sgy -rwxrwxr-x 1 ratih pbank 4929656 Jun 8 08:37 S92TA-19.sgy -rwxrwxr-x 1 ratih ... (4 Replies)
Discussion started by: muhnandap
4 Replies

6. UNIX for Dummies Questions & Answers

Listing file name and date

Hello. I want to make an unix script which create a file with the name and the date of creation of the different files that there are in a directory. Can do you please help me? Thank you in advance. (3 Replies)
Discussion started by: Jfka
3 Replies

7. UNIX Desktop Questions & Answers

date range

I have a number of instances wher I need to run reports for the previous month and need to include the last months date range in the sql. I want to create a string which consists of the first and last dates of last month separated with an ' and ' ie for this month (Feb) I want it to say '01/01/10... (3 Replies)
Discussion started by: Niven
3 Replies

8. UNIX for Advanced & Expert Users

Listing tomorrows date

I am writing a script to strip data from a log, strip last month and empty the log for the comming month. It works great at the moment, but during testing I decided to change the date to 12/31 and when I ran it, it did not find tomorrows date. Further testing revealed that no dbl digit month would... (2 Replies)
Discussion started by: theninja
2 Replies

9. Shell Programming and Scripting

Get date range between 2 date input

Hi Experts, I have files name report_20090416 report_20090417 report_20090418 report_20090420 report_20090421 I have 2 input from user From Date: 20090417 To Date: 20090420 and I need to grep only those line in between. Output should be report_20090417 report_20090418... (3 Replies)
Discussion started by: tanit
3 Replies

10. UNIX for Dummies Questions & Answers

long listing of files up to a given date

Hi I would like to a long list of files up to a given date. I've tried: ls -al > filelist but this command gives me all the files. I've also have tried the find command: find . -mtime -10 -type f -print > filelist This gives me information on active file within the past 10 days and... (2 Replies)
Discussion started by: rlh
2 Replies
Login or Register to Ask a Question