LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris
User Name
Password
Solaris / OpenSolaris This forum is for the discussion of Solaris and OpenSolaris.
General Sun, SunOS and Sparc related questions also go here.

Notices

Reply
 
Search this Thread
Old 02-22-2007, 01:16 AM   #1
farkus888
Member
 
Registered: Oct 2006
Distribution: usually use arch
Posts: 103

Rep: Reputation: 15
getting dates in a script


I need to get the dates of the previous 7 days inside a script. this is on a solaris 5.8 machine and the date needs to be in the form yyyymmdd. questions welcome... I'll try to get right back to you because this is for work.
 
Old 02-22-2007, 02:09 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Hi,

Here are some tips/links.

This could be the best/easiest solution to start with (tested on sun box):

Yesterdays date:
DATE_STAMP=`TZ=CST+24 date +%Y%m%d`

Two days ago:
DATE_STAMP=`TZ=CST+48 date +%Y%m%d`

Also take a look here (www.unix.com) for some interesting links concerning date/time.

Hope this gets you going again.
 
Old 02-22-2007, 04:35 AM   #3
doc.nice
Member
 
Registered: Oct 2004
Location: Germany
Distribution: Debian
Posts: 274

Rep: Reputation: 34
for bash, you can use this:
Code:
#!/bin/bash
BACK=0
while [ $BACK -lt 7 ]; do
  BACK=$(($BACK + 1))
  date -d "-$BACK days" "+%Y%m%d"
done
date -d shows the date given in the argument, not "now". But date is powerful, it understands "-7 days", "+1 week" and so on
 
Old 02-22-2007, 05:10 AM   #4
farkus888
Member
 
Registered: Oct 2006
Distribution: usually use arch
Posts: 103

Original Poster
Rep: Reputation: 15
the shell situation here is frustrating to put it mildly. everyone here uses bash, all of our scripts are to be written in sh, and all of our machines default to csh. and there are no exceptions to ever be made to any of the rules. looks like the modifying TZ will work though, thanks for everyones input.
 
Old 02-22-2007, 05:13 AM   #5
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,522

Rep: Reputation: 365Reputation: 365Reputation: 365Reputation: 365
replying to doc.nice:

That's not a bash feature, but a GNU date one, so you'll need to install it on Solaris should you want to use it.
 
Old 02-22-2007, 05:18 AM   #6
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,522

Rep: Reputation: 365Reputation: 365Reputation: 365Reputation: 365
Quote:
Originally Posted by farkus888
the shell situation here is frustrating to put it mildly. everyone here uses bash
That is a common situation, especially from users with a Linux background.
Quote:
, all of our scripts are to be written in sh
Thas is a big mistake, shell scripts should be written in a POSIX compliant shell, /bin/sh is a legacy one, not compliant.
Better use ksh or perhaps /usr/xpg4/bin/sh
Quote:
and all of our machines default to csh.
What do you mean defaults ? When you create a new account, the shell has to be csh ? That's a quite obsolete policy.
 
Old 02-22-2007, 05:29 AM   #7
farkus888
Member
 
Registered: Oct 2006
Distribution: usually use arch
Posts: 103

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by jlliagre
That is a common situation, especially from users with a Linux background.

Thas is a big mistake, shell scripts should be written in a POSIX compliant shell, /bin/sh is a legacy one, not compliant.
Better use ksh or perhaps /usr/xpg4/bin/sh

What do you mean defaults ? When you create a new account, the shell has to be csh ? That's a quite obsolete policy.
like I said, its frustrating to deal with but those are the rules here and I get the ruler across the knuckles every time I question it.
 
  


Reply

Tags
bash, closed, date, script, scripting, solaris, solution


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
Difference between two dates Uday123 Programming 5 02-23-2009 07:26 AM
dumping mysql db script with dates markehb Linux - Software 2 04-23-2006 11:11 PM
f-spot dates viniosity Linux - Software 1 08-07-2005 08:43 PM
File dates. vexer Programming 5 04-28-2004 01:14 AM
need to manipulate dates clsonnt Programming 5 08-19-2003 11:07 AM


All times are GMT -5. The time now is 02:56 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration