LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-13-2010, 05:31 PM   #1
supanatral
LQ Newbie
 
Registered: Mar 2010
Posts: 19

Rep: Reputation: 0
Simple Bash Script that gets date


I have a program on our server called "ExpireQuarantine" and I would like to make it much more automated. The command I need to run is:
Quote:
ExpireQuarantine -d YYYY-MM-DD
I would like to make a bash script that selects the date as 6 months ago but I'm not sure how to do that. Is there a way to do that?
 
Old 06-13-2010, 05:37 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,613

Rep: Reputation: 7962Reputation: 7962Reputation: 7962Reputation: 7962Reputation: 7962Reputation: 7962Reputation: 7962Reputation: 7962Reputation: 7962Reputation: 7962Reputation: 7962
Quote:
Originally Posted by supanatral View Post
I have a program on our server called "ExpireQuarantine" and I would like to make it much more automated. The command I need to run is:


I would like to make a bash script that selects the date as 6 months ago but I'm not sure how to do that. Is there a way to do that?
Yes. There are many bash scripting tutorials on the web that can show you how to get the date, and how to write a script. Should have no problem finding them.

Post what you've written already, and where you're getting stuck, and we can help. But I doubt anyone here is going to write your script for you.
 
Old 06-13-2010, 05:57 PM   #3
supanatral
LQ Newbie
 
Registered: Mar 2010
Posts: 19

Original Poster
Rep: Reputation: 0
All I'm trying to figure out is how I can get the date 6 months ago in the format of: "YYYY-MM-DD"

Anything after that I'm already with doing.
 
Old 06-13-2010, 07:36 PM   #4
penguiniator
Member
 
Registered: Feb 2004
Location: Olympia, WA
Distribution: SolydK
Posts: 442
Blog Entries: 3

Rep: Reputation: 60
You should start with "man date". GNU date has some convenient options. In particular, you may want to look at the --date option and the DATE STRING section of the manual. Note that it accepts relative dates and numbers as well as free-form dates. Experiment with different ways of specifying what you want it to do. You may be surprised at how easy it is to get what you want.

As for how it formats the output, have a look at the quick help displayed with "date --help".
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to increment the date in a file name via bash script tensigh Programming 10 07-23-2010 03:49 AM
Beginner question, Bash-script - date kickarzt Programming 15 03-10-2010 12:18 PM
Date calculations in BASH script Crashman Programming 4 07-03-2004 10:15 AM
Date in a BASH script... soulsniper Linux - Software 7 11-22-2003 06:08 PM
simple date script question Cynthia Blue Programming 3 01-13-2003 03:15 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration