LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-29-2008, 11:09 PM   #1
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Rep: Reputation: 30
check date


I would like to write a script as below , can advise what can i do .

if today is 1st-5th then

then do xxx

if today is 6th-10th

then do yyy

if today is 11th-15th
then do zzz

end.

can advise how to write this script ? thx
 
Old 12-29-2008, 11:13 PM   #2
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Original Poster
Rep: Reputation: 30
write script

I would like to write a script as below , can advise what can i do .

if this month is Jan , May , July and today is last day of month ( 28th, 29th , 30th or 31th )

then do xxx

if this month is Feb , Mar , Aug and today is last day of month ( 28th, 29th , 30th or 31th )

then do yyy

end.



can advise how to write this script ? thx
 
Old 12-30-2008, 12:16 AM   #3
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,063

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
Code:
date +%m
gives you the month

Code:
date +%d
gives you the day

The rest is just to compare using if...then...else. If you need some specific help, ask again and be more concrete. I assume you are using bash as your shell. This guide is pretty good if you need to learn a bit: http://tldp.org/LDP/abs/html/

Last edited by i92guboj; 12-30-2008 at 12:18 AM.
 
Old 12-30-2008, 01:04 AM   #4
ZAMO
Member
 
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 593

Rep: Reputation: 30
You can write a simple script like this one.

Code:
$cat test.sh
#!/bin/bash
if [ `date +%d` -lt  6 ]
then 
echo -e "Date is `date +%d`"
fi
if [ `date +%d` -lt 11 ] && [  `date +%d` -gt  5 ]
then 
echo -e "Date is `date +%d`"
fi
if [ `date +%d` -lt  16 ] && [ `date +%d` -gt 10 ]
then 
echo -e "Date is `date +%d`"
fi
if [ `date +%d` -lt  31 ] && [ `date +%d` -gt 25 ]
then 
echo -e "Date is `date +%d`"
fi
say today's date is
Code:
$ date
Mon Dec 29 12:04:40 CST 2008
The output will be
Code:
$ sh test.sh
Date is 30
You can execute whatever you want in place of echo .

Cheers
 
Old 12-30-2008, 08:08 AM   #5
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by ZAMO View Post
You can write a simple script like this one.

Code:
$cat test.sh
#!/bin/bash
if [ `date +%d` -lt  6 ]
then 
echo -e "Date is `date +%d`"
fi
if [ `date +%d` -lt 11 ] && [  `date +%d` -gt  5 ]
then 
echo -e "Date is `date +%d`"
fi
if [ `date +%d` -lt  16 ] && [ `date +%d` -gt 10 ]
then 
echo -e "Date is `date +%d`"
fi
if [ `date +%d` -lt  31 ] && [ `date +%d` -gt 25 ]
then 
echo -e "Date is `date +%d`"
fi
say today's date is
Code:
$ date
Mon Dec 29 12:04:40 CST 2008
The output will be
Code:
$ sh test.sh
Date is 30
You can execute whatever you want in place of echo .

Cheers
thx reply ,

it works , I would like to have one more condition , as below

if today is 1st-5th then

then do xxx

if today is 6th-10th

then do yyy

if today is 11th-31th but NOT the end of the month

then do zzz

end.


can advise how to change the script ?
thx
 
Old 12-30-2008, 08:12 AM   #6
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
You have two threads with the same basic question. Much better to keep it all in one thread.

I will merge them

Last edited by pixellany; 12-30-2008 at 08:15 AM.
 
Old 12-30-2008, 08:17 AM   #7
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
This is almost the same question as your other recent thread: http://www.linuxquestions.org/questi...k-date-693766/

Merged
 
  


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
check date to run the command ust Linux - Server 4 06-06-2008 05:10 AM
how to check the password expiry date of a user? binary_0011 Other *NIX 1 06-04-2008 02:37 AM
how to check the date for the user ID created? dwarf007 Linux - Security 1 08-22-2007 05:00 AM
How to check User ID creation Date? dwarf007 Linux - Security 1 08-22-2007 03:18 AM
Check for invalid date Blackout_08 Programming 3 06-07-2006 09:28 PM


All times are GMT -5. The time now is 03:51 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration