Unix Script for getting date and validating just Hour


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unix Script for getting date and validating just Hour
# 8  
Old 05-15-2009
Quote:
Originally Posted by zulfikarmd
That didn't work. Then I tried following:

:/export/home/zdholkawala $ sh -v GOMAN_HR.sh
#!/bin/bash
HR=`date +%H`;
if [$HR -gt 7];
if [$HR -lt 16]; then
sendevent -E SET_GLOBAL -G GOMAN_HR=0730
else if [$HR -gt 16]; then
sendevent -E SET_GLOBAL -G GOMAN_HR=1630
fi
fi
fi
GOMAN_HR.sh: syntax error at line 11: `fi' unexpected

Even removing last fi doesn't work here. Any help?
try this
Code:
#!/bin/bash
HR=`date +%H`;
if [ $HR -gt 7 -a $HR -lt 16 ];
then
  sendevent -E SET_GLOBAL -G GOMAN_HR=0730
else if [ $HR -gt 16 ]
then
   sendevent -E SET_GLOBAL -G GOMAN_HR=1630
fi

Thanks NT

Last edited by Franklin52; 05-15-2009 at 08:45 AM.. Reason: Adjust indentation
# 9  
Old 05-15-2009
Thanks all for the hints/guidance/help on this. I have it working:

command: /bin/bash -c 'HR=`date +%H`; H7=7; H16=16; if [ "$HR" -ge "$H7" ] && [ "$HR" -lt "$H16" ]; then sendevent -E SET_GLOBAL -G GOMAN_HR="0730"; else if [ "$HR" -ge "$H16" ]; then sendevent -E SET_GLOBAL -G GOMAN_HR="1630"; fi fi'
# 10  
Old 05-15-2009
Quote:
Originally Posted by namishtiwari
try this
Code:
#!/bin/bash
HR=`date +%H`;
if [ $HR -gt 7 -a $HR -lt 16 ];
then
  sendevent -E SET_GLOBAL -G GOMAN_HR=0730
else if [ $HR -gt 16 ]
then
   sendevent -E SET_GLOBAL -G GOMAN_HR=1630
fi

Thanks NT
Thanks Namish I got script running on production. Appreciate your help.Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

UNIX script to replace old date with current date dynamically in multiple files present in a folder

I am trying to work on a script where it is a *(star) delimited file has a multiple lines starts with RTG and 3rd column=TD8 I want to substring the date part and I want to replace with currentdate minus 15 days. Here is an example. iam using AIX server $ cat temp.txt RTG*888*TD8*20180201~... (1 Reply)
Discussion started by: Shankar455
1 Replies

2. Shell Programming and Scripting

Day/Hour diff between two date

Dear All I need to find out day diff between two dates. date -d or date -- day is not working in mine system. Currently i am using below code but it gives me wrong value while month change. IP: Date 1: 20150802 11:30:45 Date 2: 20150728 16:30:45 code used: awk '{t1=$2; t2=$4;... (7 Replies)
Discussion started by: jaydeep_sadaria
7 Replies

3. Shell Programming and Scripting

Validating date in yyyymmdd format using PERL

Hi all, i had a code where in user will enter a date in yyyymmdd format.. i didnt use any validation for the date and now the problem is if a user enters date instead of month after year it is proceeding with the code.. like if the date is 20120426 and if the user enters 20122604 it... (4 Replies)
Discussion started by: smarty86
4 Replies

4. Shell Programming and Scripting

Generate last hour date in YYYYmmddHH

can some one show me how to generate last hour of date for example: 2012010100 -> 2011123123 // check first date of a new year 2008030100 -> 2008022923 // check leap year as well And also no perl code is restricted. This is what i am facing issue now, can someone provides help to me. (4 Replies)
Discussion started by: alvin0618
4 Replies

5. Shell Programming and Scripting

validating user entered date

I need the date validation. I searched in the google but i didn't find my requirements. requirements: 1) user has to enter the date in YYYY/MM/DD format 2) MM validations 3) DD validations. and if the month is april it should allow 30 days only and for May month it should allow 31 days like... (1 Reply)
Discussion started by: KiranKumarKarre
1 Replies

6. Shell Programming and Scripting

Can any one share a unix script for validating the export of a mapping which is in XM

Hi, Can any one share a unix script for validating the export of a mapping which is in XML format. like my requirment is that when ever we are migrating the mappings or wokflows from development to QA we will take the export of that mapping into an XML file.Insted of reviewing the mapping... (1 Reply)
Discussion started by: perlamohan
1 Replies

7. UNIX for Advanced & Expert Users

Can any one share a unix script for validating the export of a mapping which is in XM

Hi, Can any one share a unix script for validating the export of a mapping which is in XML format. like my requirment is that when ever we are migrating the mappings or wokflows from development to QA we will take the export of that mapping into an XML file.Insted of reviewing the mapping... (1 Reply)
Discussion started by: perlamohan
1 Replies

8. Shell Programming and Scripting

Get date and time for past 1 hour from current date

Hi, I need to get the date and time for past 1 hour from the current date. Anyone know how to do so? Thanks (5 Replies)
Discussion started by: spch2o
5 Replies

9. Shell Programming and Scripting

Validating the input date format

I have one script.for that the inputs are fromdate(dd/mon/yyyy) and todate(dd/mon/yyyy). How i can validate the input format?for eg.27/08/2008 is not valid.27/aug/2008 or 27/Aug/2008 are valid. and the todate is optional.so if the todate is not present in the input then i need to assign the... (6 Replies)
Discussion started by: Sharmila_P
6 Replies

10. Shell Programming and Scripting

Validating date in sas

I need some help on sas on unix.... Is there any way to validate date in sas (1 Reply)
Discussion started by: radhika03
1 Replies
Login or Register to Ask a Question