Removing day before yesterday's date


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing day before yesterday's date
# 1  
Old 12-09-2009
Removing day before yesterday's date

Hi

i am having a backup folder wherein i will be having the files ftp ed to remote server, i need to keep only the data of last two days and remove the old log files.

how can i achieve this ?

i have tried...
Code:
#!/bin/bash
D=`date +'%d'`
oldday=`expr $D - 2`
rm /sent/data-$oldday*
echo $oldday

it works ok...but when it comes to first and second day of every month ...i will be facing a problem....
# 2  
Old 12-09-2009
Try the following...

Code:
find /sent -mtime 2 -exec rm {} \;

# 3  
Old 12-09-2009
I tried changing the value in mtime 2 to 1 since i have already deleted all the old files manually....it does not deleted anything. it has to delete 9th data....

Last edited by aemunathan; 12-10-2009 at 12:04 AM..
# 4  
Old 12-10-2009
What gives the command :
Code:
date -d 'now -2 days' '+%d%m%y'

# 5  
Old 12-12-2009
hi

its not supported.....
Code:
root@srv1 # date -d 'now -2 days' '+%d%m%y'
date: illegal option -- d
usage:  date [-u] mmddHHMM[[cc]yy][.SS]
        date [-u] [+format]
        date -a [-]sss[.fff]

# 6  
Old 12-12-2009
Rather than fight any problems with scripting, on the SCO boxes I administer I create several directories in backup and move the data through them then off the system. Something like:
directories are /backup/current, /backup/1do, /backup/2do
using a cron job in the middle of the night:
rm /backup/2do/*
mv /backup/1do/* /backup/2do
mv /backup/current/* /backup/1do

On the ones where I keep a week's worth of backup the directories are weekday names. As a safety measure I check for the date of the backups in each directory weekly along with a check that the nightly burn was accomplished each night.
# 7  
Old 12-12-2009
Code:
#!/bin/ksh


days_ago()
{
  perl -e  '
	# take 86400 * # of days from right now in epoch seconds
		 $yestertime = time - (86400 * $ARGV[0]);
		 $month = (localtime $yestertime)[4] + 1;
	# day of the month
		 $day = (localtime $yestertime)[3];
	# year
		 $year = (localtime $yestertime)[5] + 1900;
	# touch -t date format  YYYMMDD0000
		 printf( "%4d%02d%02d0000\n", $year, $month, $day);  '  $1
}

#usage
# 2 days ago
touch -t $(days_ago 2) dummy
find . -type f ! -newer dummy -exec ls -l  {} \;

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to compare two files of todays date and yesterday's date

hi all, How to compare two files whether they are same are not...? like i had my input files as 20141201_file.txt and 20141130_file2.txt how to compare the above files based on date .. like todays file and yesterdays file...? (4 Replies)
Discussion started by: hemanthsaikumar
4 Replies

2. Shell Programming and Scripting

How to append date to filename, but base it on yesterday's date?

Hello, I'd like to write a monthly archive script that archives some logs. But I'd like to do it based on yesterday's date. In other words, I'd like to schedule the script to run on the 1st day of each month, but have the archive filename include the previous month instead. Here's what I... (5 Replies)
Discussion started by: nbsparks
5 Replies

3. Shell Programming and Scripting

How to get tomorrow,yesterday date from date Command

Hi I want to get tomorrow and yesterday date from date command. My shell is KSH and server is AIX. I tried several options, but unable to do. Please help on this. Regards Rajesh (5 Replies)
Discussion started by: rajeshmepco
5 Replies

4. Shell Programming and Scripting

Day before yesterday's date

Hello All, I am writing a script in Sun Solaris I want the date for "day before yesterday", i got the yesterday's date by this command TZ=GMT+24 date +%b" "%d. Please suggest me some code to get the date for day before yesterday (6 Replies)
Discussion started by: anand2308
6 Replies

5. Shell Programming and Scripting

[Solved] Replace yesterday date with today's date except from the first line

Hello, I have a file like this: 2012112920121130 12345620121130msABowwiqiq 34477420121129amABamauee e7748420121130ehABeheheei in case the content of the file has the date of yesterday within the lines containing pattern AB this should be replaced by the current date. But if I use... (3 Replies)
Discussion started by: Lilu_CK
3 Replies

6. Shell Programming and Scripting

Need help in Shell Script comparing todays date with Yesterday date from Sysdate

Hi, I want to compare today's date(DDMMYYYY) with yesterday(DDMMYYYY) from system date,if (today month = yesterday month) then execute alter query else do nothing. The above requirement i want in Shell script(KSH)... Can any one please help me? Double post, continued here. (0 Replies)
Discussion started by: kumarmsk1331
0 Replies

7. Shell Programming and Scripting

Get yesterday's date in year-month-day format?

Dear All, Actually, i'm doing some reporting job and i need to pass yesterday's date in Year-Month-Day format(e.g. 2009-06-10) to another program for generating 2009-06-10 report. to get today's date, it's easy to just date '+%Y%m%d' , but no idea how can i get this kind of format for... (2 Replies)
Discussion started by: tiger2000
2 Replies

8. Shell Programming and Scripting

Compare date from db2 table to yesterday's Unix system date

I am currently running the following Korn shell script which works fine: #!/usr/bin/ksh count=`db2 -x "select count(*) from schema.tablename"` echo "count" I would like to add a "where" clause to the 2nd line that would allow me to get a record count of all the records from schema.tablename... (9 Replies)
Discussion started by: sasaliasim
9 Replies

9. Shell Programming and Scripting

Yesterday's Day of week

I need o get yesterday's day of week but im not exactly sure. the actual name is what i want. I can do it with numbers but im not sure with words. (3 Replies)
Discussion started by: rcunn87
3 Replies
Login or Register to Ask a Question