Solaris / OpenSolaris This forum is for the discussion of Solaris and OpenSolaris.
General Sun, SunOS and Sparc related questions also go here. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
02-22-2007, 12:16 AM
|
#1
|
|
Member
Registered: Oct 2006
Distribution: usually use arch
Posts: 103
Rep:
|
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.
|
|
|
|
02-22-2007, 01:09 AM
|
#2
|
|
LQ Veteran
Registered: Sep 2003
Location: the Netherlands
Distribution: lfs, debian, rhel
Posts: 8,705
|
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.
|
|
|
|
02-22-2007, 03:35 AM
|
#3
|
|
Member
Registered: Oct 2004
Location: Germany
Distribution: Debian
Posts: 274
Rep:
|
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 
|
|
|
|
02-22-2007, 04:10 AM
|
#4
|
|
Member
Registered: Oct 2006
Distribution: usually use arch
Posts: 103
Original Poster
Rep:
|
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.
|
|
|
|
02-22-2007, 04:13 AM
|
#5
|
|
Moderator
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Ubuntu, OL
Posts: 9,311
|
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.
|
|
|
|
02-22-2007, 04:18 AM
|
#6
|
|
Moderator
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Ubuntu, OL
Posts: 9,311
|
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.
|
|
|
|
02-22-2007, 04:29 AM
|
#7
|
|
Member
Registered: Oct 2006
Distribution: usually use arch
Posts: 103
Original Poster
Rep:
|
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.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 11:56 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|