Need suggestions about a datecheck script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need suggestions about a datecheck script
# 1  
Old 05-09-2008
Need suggestions about a datecheck script

I'm currently running a script that checks to see if a laptop is on the network, and if it is it backs up, if not it retries it later.

Anyway, our backup scheduling has changed. I need to check if today's date is the Thursday after the first Wednesday of every month. This is made slightly more difficult by the fact that the first Thursday doesn't always follow the first Wednesday (in cases where the 1st day of the month happens to be Thursday).

Is there an easy way to do this?
# 2  
Old 05-09-2008
What you said == first occurrence of Thursday in a month, regardless of Wednesday.
Code:
#!/bin/ksh
is_first_thursday()
{
    retval=0
    typeset -i day=$(date +%d)
    if [[ $day -lt 8 ]];  then 
           if [[ "`date +%A`" = "Thursday" ]] ; then
                 retval=1
           fi
    fi 
    echo $retval
}

usage:
Code:
ok=$(is_first_thursday)
if [[ $ok - eq 1 ]] ; then
    # do stuff because it is first thursday
fi

# 3  
Old 05-09-2008
Thanks for the quick reply Jim!!

What I was looking for is the First Thursday after the First Wednesday of every month. There must be a previous Wednesday in the month.


I'm trying to explain it this way because, for example, May 2008:

1st Thursday = Day 1
1st Wednesday = Day 7
1st Thursday after the first Wednesday = Day 8.

So a simple "First Thursday" is not the same thing as the "First Thursday after the First Wednesday".

I appreciate your all your help mate!

Last edited by tsmurray; 05-09-2008 at 12:20 PM..
# 4  
Old 05-09-2008
Computer

edited for review

Last edited by tsmurray; 05-09-2008 at 02:45 PM..
# 5  
Old 05-10-2008
Using ksh93 ..
Code:
$ printf "%(%D)T\n" "first wednesday may 2008"
05/07/08
$ printf "%(%D)T\n" "$(printf "%(%D)T\n" "first wednesday may 2008") + 1 day"
05/08/08
$

# 6  
Old 05-14-2008
Data didn't work

Thanks for the reply fpmurphy, but it doesn't seem to work in my version of ksh.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Distributing script projects, suggestions/ideas?

Heyas If you recall, not too long ago, i was asking about the GNU Autotools. The feedback on that was almost unisense, and me figured that it turned my (back then) +98% SHELL project into a +73% GROFF project... :( Felt a bit overhelmed, specialy since i didnt actualy use or need the true... (0 Replies)
Discussion started by: sea
0 Replies

2. Shell Programming and Scripting

Suggestions on this script please

i=1 out="" j=`expr 2 * $1` while do out="$out"#"" echo $out ((i=i+1)) done while do print ${out%?} ((i=i+1)) done This script is throwing an error: gurnish:/home/fnb/gurnish/saurabh/scripts> while1 3 expr: 0402-050 Syntax error. # (6 Replies)
Discussion started by: targetshell
6 Replies

3. Shell Programming and Scripting

WPAR monitoring shell script suggestions needed

Hi All, This is for WPAR monitoring shell script, earlier opened thread was closed, had to open a new thread, as suggested I have used script as below, But am trying to get the output in below format, need suggestions with it. Below is the lswpar output, required output format. ... (7 Replies)
Discussion started by: aix_admin_007
7 Replies

4. Shell Programming and Scripting

Unix Script -- Suggestions to list and kill PID's sequentially

Hi, I'm trying to write a script where i'm trying to grep the PID and the associated file and list them. Then execute the KILL command sequentially on the listed PID's for ".tra" files ==================================================== ps -aux | grep mine adm 27739 0.2 0.8 1131588... (12 Replies)
Discussion started by: murali1687
12 Replies

5. Shell Programming and Scripting

Need Suggestions to improve Perl script for checking malformed braces/brackets

Hi all, I've written a Perl script below that check and report for malformed braces. I have a UNIX ksh version and it took a couple of minutes to run on a 10000+ lines. With the Perl version it only took about 20 seconds so that is enough incentive for me to go Perl not to mention that I need... (1 Reply)
Discussion started by: newbie_01
1 Replies

6. Shell Programming and Scripting

Script that accepts user input - Suggestions

Hi, I have a series of BASH shell scripts that process data. All of the scripts are controlled by a "master" script, where users specify their processing parameters. The sub-scripts, and the order they are called, depend on the values of these user-specified processing parameters. This method... (1 Reply)
Discussion started by: msb65
1 Replies

7. Shell Programming and Scripting

Suggestions/cleanup Bash script

Hello, beginner bash scripter here.. I was able to write a script and it works just fine. I'm just wondering if someone could chime in or any suggestions to make it cleaner or tighter so to speak. I have a disk to disk backup solution which uses 250GB disks. When one gets full I just po in a new... (7 Replies)
Discussion started by: woodson2
7 Replies

8. Shell Programming and Scripting

syntex error script any suggestions

a script with prompts user and returns the value of there home directory and full name #!/bin/bash echo "please enter your login ID" read login_id while $login_id -ne `grep $login_id /etc/passwd | cut -f1 -d:` is they anything wrong with it (5 Replies)
Discussion started by: kim187
5 Replies

9. Shell Programming and Scripting

Performance problem with my script ...suggestions pls

Hi , I have included my script below, pls read thro this req. I want my script to run for every hour , the problem is I CANNOT USE CRONTAB which is prohibited inside the company. My script does what it is supposed to do (to determine the memory and then send a email if it crosses a certain... (2 Replies)
Discussion started by: vivsiv
2 Replies

10. UNIX for Dummies Questions & Answers

How can i proceed on this (datecheck)

Hi, I want to bundle if statements The script which i created is if ]; then if ]; then now=`TZ=CST+24 date +%Y-%m-%d` nows=`TZ=CST+24 date +%Y-%m-%d` ; else ]; then now=`TZ=CST+48 date +%Y-%m-%d` nows=`TZ=CST+48 date +%Y-%m-%d` ; fi now=`TZ=CST+24 date +%Y-%m-%d` nows=`date... (2 Replies)
Discussion started by: gopskrish
2 Replies
Login or Register to Ask a Question