Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

awk or ksh script ....

Status
Not open for further replies.

aixnag

MIS
Oct 30, 2001
99
SG

Hi,

would like to delete application logfiles from various direcotries which are two,seven,15 days old. I don't want to use #find with -mtime , its bit messy sometimes.

curently am manually using this method.
# touch -t mmddhhmm <testfile>
#find /test ! -newer <testfile> -exec rm {} \;

Every time am changing date for running this task. Any way of automising of these tasks.

any suggesstions??? any scripts ready with you.

thanks in advance.

aixnag
IBM Certified Specialist - P-series AIX 5L Administration
IBM Certified Specialist - AIX V4 HACMP
 
Each time you run the script you could get the current date information in the format needed for the touch command using the following:

# touch -t `date +%m%d%H%M` <testfile>

Sample output from date command w/ arguments:
$ date +%m%d%H%M
06091029

-Hallux
 
Hi,

Am looking for something like this.

say today's date 12th june.
need to touch three files 1. with 2 days old (10th june) 2.with 7 days old (5th june) 3. with 15 days (27th may )from the current date.

thanks in advance.



aixnag
IBM Certified Specialist - P-series AIX 5L Administration
IBM Certified Specialist - AIX V4 HACMP
 
The following would give you two days back:
echo $(($(date +%d)-2))

-Hallux
 
#!/usr/bin/ksh

#
# get_date
#
# function to return day month year relative to today.
# $1 = +n|-n
# $2 = y, display on tty
#
# Ensure TZ variable looks something like:-
# EST-10EDT-11
# NOT like australia/nsw
#

get_date()
{

[[ $# -lt 1 ]] &&
{
message &quot; Usage: get_day -n|+n&quot;
return 1
}

offset=$(print $TZ | sed -e &quot;s/.*$(date +%Z)\([+-]*[0-9][0-9]*\).*/\1/&quot;)

[[ $(expr $1 : ^[+-]) -eq 0 ]] &&
{
message &quot;Invalid argument &quot;
return 1
}

if [ $(expr $1 : ^[-]) -ne 0 ]; then
n=&quot;+&quot;$((${1#-}*24))
else
n=&quot;-&quot;$((${1#+}*24))
fi

offset=$(($offset${n}))
day=$(TZ=XXX$offset date +%d)
mon=$(TZ=XXX$offset date +%m)
year=$(TZ=XXX$offset date +%Y)
hour=$(TZ=XXX$offset date +%H)
min=$(TZ=XXX$offset date +%M)


[[ $# -eq 2 ]] && print &quot;${mon}${day}${hour}${min}&quot;
return 0
}

export TZ=EST-10EDT-11

for d in 2 7 15
do
> $(get_date -${d} y)
done
 

Hi,

The above script served my purpose. Thanks pmurray.



aixnag
IBM Certified Specialist - P-series AIX 5L Administration
IBM Certified Specialist - AIX V4 HACMP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top