LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Simple Bash Script that gets date (https://www.linuxquestions.org/questions/programming-9/simple-bash-script-that-gets-date-813933/)

supanatral 06-13-2010 05:31 PM

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?

TB0ne 06-13-2010 05:37 PM

Quote:

Originally Posted by supanatral (Post 4002491)
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.

supanatral 06-13-2010 05:57 PM

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.

penguiniator 06-13-2010 07:36 PM

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".


All times are GMT -5. The time now is 05:36 AM.