Archive

Posts Tagged ‘script’

Making Date Calculation

January 17th, 2010 No comments

You’re doing a script and you need to know what was the date 35 days ago or what will the date be in 21 days. This is where¬† the “date” command can help you doing that kind of calculation. In this little article we will present some examples to help us making some data calculation. I would like to point out, that all of these date calculation take in consideration the leap year.

DISPLAY CURRENT DATE
# date
Sun Jan 17 11:52:40 EST 2010

DISPLAY DATE OF 35 DAYS AGO
# date --date="35 days ago"
Sun Dec 13 11:53:51 EST 2009

DISPLAY DATE OF 2 MONTHS AGO
# date --date="2 months ago"
Tue Nov 17 11:53:53 EST 2009

DISPLAY DATE OF 1 YEAR AGO
# date --date="1 year ago"
Sat Jan 17 11:53:56 EST 2009

DISPLAY DATE 1 HOUR AGO
# date --date="1 hour ago"
Sun Jan 17 10:55:00 EST 2010

DISPLAY DATE THAT WILL BE IN 35 DAYS
# date --date="35 days"
Sun Feb 21 11:56:26 EST 2010

DISPLAY DATE THAT WILL BE IN 1 MONTH
# date --date="1 month"
Wed Feb 17 11:56:32 EST 2010

DISPLAY DATE THAT WILL BE NEXT FRIDAY
# date --date="this friday"
Fri Jan 22 00:00:00 EST 2010

DISPLAY NEXT DAY DATE
# date --date="next day"
Mon Jan 18 11:57:18 EST 2010

CONVERT DATE TO EPOCH TIME
# date -d "20100118" +%s
1263790800

CONVERT EPOCH TIME TO DATE
# date -d @1263790800 "+%Y-%m-%d %T"
2010-01-18 00:00:00
Categories: General

Automated DVD Backup

May 31st, 2009 1 comment

Today I would like to share with you, a little script that I use every week. I have four rewritable DVD that I use in rotation to backup important directories of my server at home. All I have to do is to leave one of these DVD+RW in the dvd drive and a backup of my important directories will be taken at regular interval. I have schedule a cron job that run tree times a week, to backup to DVD directories that are important to me. This is by no way a replacement of a full system backup like Mondo rescue, Storix or Acronis, but they represent to me the directories that are subject to change more often. I must specify that the command used in this script require using a DVD+RW to work.

Read more…

Categories: Scripting