Conditional Date Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Conditional Date Script
# 1  
Old 06-21-2007
Conditional Date Script

I am learning Unix for the first time. I am playing around with my default profile file to add some script in the KSH. The time format is GMT and I am in eastern time zone. I am trying to script some greetings based upon the time of day using the IF/ELIF conditions. I am getting errors. I have tried researching to see what I am doing wrong but am getting nowhere. I am sure there is someone out there that can show me the way. Here is the script I am trying to run:

if [ \( `date +%R` < 16:00 \) -a \( `date +%R` > 2:00 \) ]
echo "Good Morning"
elif [ \( `date +%R` > 15:59 \) -a \( `date +%R` < 22:00 \) ]
echo "Good Afternoon"
else
echo "Good Evening"
fi

I appreciate any help anyone can give me here to get this to work.
Thanks....
# 2  
Old 06-21-2007
something to start with:
Code:
#!/bin/ksh

hour=$(date +%H)
echo "hour->[${hour}]"

case ${hour} in
 @(0[0-9]|1[1-2]) )  echo "Good Morning" ;;
 @(1[3-7]) )         echo "Good Afternoon" ;;
              *)     echo "Good Evening" ;;
esac


Last edited by vgersh99; 06-21-2007 at 10:02 AM..
# 3  
Old 06-21-2007
Code:
TZ='EST5EDT4'

will then change from GMT to EST(EDT). Which I think may be another problem. What system are you on? because the TZ variable set this way works but may not correctly set daylight time - eg. Linux has this issue.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Conditional Script

Hi, I have a script file which has some simple commands. I want these commands to be executed based on the input. Ia m good with IF statement also. At the end it has to be based on incoming value. Example CASE 1 : Execute some commands where Input value as 1 CASE 2 : Execute... (5 Replies)
Discussion started by: vrupatel
5 Replies

2. Shell Programming and Scripting

Help with conditional clauses for script output

Hello. I am new this site as well as new to shell scripting and this is my first form... Please help me with the following shell script. I am executing a shell script to run every 15 min (scheduled in cronjob) and it gives an output in an output file which is e-mailed. CONCCOUNT=`cat... (1 Reply)
Discussion started by: Jamessteevens
1 Replies

3. Shell Programming and Scripting

Smarter conditional script with Table

Hi, currently I have a script with conditional checking. But it's not flexible to use, because i must create a more conditional script if there are more keyword (see table) required. Question is: Can I create a more smarter script that will be more flexible? I appreciate any help anyone can give... (8 Replies)
Discussion started by: jazzyzha
8 Replies

4. Shell Programming and Scripting

Conditional Execution of a Script.

I have a unix shell script Test.sh more Test.sh echo "Calling dbquery1.sh...." ./dbquery1.sh echo "Calling dbquery2.sh...." ./dbquery2.sh more dbquery1.sh sqlplus -s user1/password1@DB_SID @/tmp/storedprocedures/Hello.rcp I run Test.sh However, I do not want dbquery2.sh to be... (3 Replies)
Discussion started by: mohtashims
3 Replies

5. Shell Programming and Scripting

Conditional search and delete using SED / Shell script

Hi, I want to perform a conditional search and remove my search string. Input string: "abcdaabcadgfaarstab" Character to search: "a" Condition: Remove all "a" in the input string except if it is "aa" Output string: "bcdaabcdgfaarstb" Can you please help me in this? (5 Replies)
Discussion started by: dominiclajs
5 Replies

6. Shell Programming and Scripting

Help on shell script conditional execution when CPU Idle > 60%

I need a shell script that will monitor a few conditions and not execute until the these conditions are met. The problem I'm having is that I can not perform a database snapshot (backup) of a sybaseIQ database unless the CPU Status Idle % is above 60% or the snapshot (backup) fails. If... (2 Replies)
Discussion started by: pancona99
2 Replies

7. Shell Programming and Scripting

unix script for conditional execution

Below is my shell script. I am trying to execute two different BTEQ scripts depending on the day of the week. So on a saturday I will execute a certain BTEQ script and on other weekdays I will run the other script. #!/bin/ksh dt=`date +"%a"` if then bteq > final_output <<- EOF .run... (3 Replies)
Discussion started by: Mihirjani
3 Replies

8. Shell Programming and Scripting

Confusion over a small conditional script

Hi, I was going through a file containing hundreds of lines of codes having conditional statement written as: log() { echo $@ } num=$(/usr/bin/rsh <one_machine> -l root 'ls -d /home/user/db* 2> /dev/null' | wc -w) (( num > 0 )) && log "db info:" so,if here the return value(stored in... (2 Replies)
Discussion started by: amit4g
2 Replies

9. Shell Programming and Scripting

Conditional File Movement script scheduled using CRON job

Hi All, i am trying to automate a process and have to create a unix script like wise. I have a scenario in which i need to automate a file movement. Below are the steps i need to automate. 1. Check whether a file (Not Fixed name-Pattern search of file say 'E*.dat') is present in a... (2 Replies)
Discussion started by: imu
2 Replies

10. Shell Programming and Scripting

creating a script using the case conditional

hello, i am a newbie who is just starting to use liunx, and I need to accept a string from the terminal and use case to echo a suitable message if the string doesn't have at least 10 characters. Also, how would I do the same thing using expr? (3 Replies)
Discussion started by: soccerstr1
3 Replies
Login or Register to Ask a Question