- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Checking for a certain time and date variable ...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2001 08:33 AM
07-09-2001 08:33 AM
Checking for a certain time and date variable within a script
Thanks - Mark
TIME=`date +%H`
DAY=`date +%a`
if [ "${diff_t}" -ge "${CRITICAL_T}" -a "${diff_t}" -le `expr "${CRITICAL_T}" + "${RUN_F}"` -o $IS_FIRST
-eq 0 ]
then
echo "---> Info for session $session `date +%c`" >>$CRITICAL_FILE
#Check for day and time
if [[ $TIME -gt 08 && $TIME -lt 17 && $DAY != Sat && $DAY != Sun ]];
then
echo "Info for session $session, \"CRITICAL\"" |mail mark_page
else
:
fi
onstat -g ses $session >> $CRITICAL_FILE
onstat -u |grep " $session " >> $CRITICAL_FILE
onstat -g ntt |grep " $session " >> $CRITICAL_FILE
onstat -g ses |grep "$session " |read a1 b1 c1 d1 f1 g1 h1
if [ "$d1" -gt 0 ]; then
ps -fea | grep " $d1 " >>$CRITICAL_FILE
fi
echo "---> END\n\n" >>$CRITICAL_FILE
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2001 08:53 AM
07-09-2001 08:53 AM
Re: Checking for a certain time and date variable within a script
I would like to use it if it does work.
thanks
Richard
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2001 09:24 AM
07-09-2001 09:24 AM
Re: Checking for a certain time and date variable within a script
I have one script in perl does good job.
if ($Curr_Date > 15 && $Date < 5){
chomp;
$User{$uname}++;
print FILE "$_ more then 10 Days old\n";
next;
}
if ($Curr_Date > 20 && $Date < 10){
chomp;
$User{$uname}++;
print FILE "$_ more then 10 Days old\n";
next;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2001 09:46 AM
07-09-2001 09:46 AM
Re: Checking for a certain time and date variable within a script
I'm wondering if the statement:
if [[ $TIME -gt 08
is hosing up because of the 08, rather than just reporting 8. This may be ugly, but can you check for each hour between 8 and 17? That is:
if [[ $TIME=08 || $TIME=09 || $TIME=10 ... $TIME=17 && $DAY != Sat && $DAY != Sun ]] (notice the || OR instead of && AND) and see if that works? I'm wondering if KSH is seeing 08 as a string and not a number, so that the -gt is throwing it off..
My $.02...
-Tim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2001 09:54 AM
07-09-2001 09:54 AM
Re: Checking for a certain time and date variable within a script
#!/bin/ksh
TIME=`date +%H`
DAY=`date +%a`
if [[ $TIME -gt 08 && $TIME -lt 17 && $DAY != Sat && $DAY != Sun ]];
then
echo "Hello"
else
:
fi
####
It works just fine...that is why I'm confused.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2001 10:01 AM
07-09-2001 10:01 AM
Re: Checking for a certain time and date variable within a script
With -gt 08 and -lt 17, this would only run between 9:00 am and 4:59 pm. That is, the hours 8 and 17 are not inclusive. That is what you are shooting for?
-Tim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2001 10:05 AM
07-09-2001 10:05 AM
Re: Checking for a certain time and date variable within a script
Good point, actually it should be -gt 07:59 and -lt 17:01. I guess that would actually get everything from 8 to 5. That still does not explain to me why our DBA was getting paged at 22:00 over the weekend. Thoughts...?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2001 10:14 AM
07-09-2001 10:14 AM
Re: Checking for a certain time and date variable within a script
Actually, the date +%H is only going to give the hour as a 2 digit number. It would never be 07:59 or something like that. You would probably want
if [[ $TIME -gt 7 && $TIME -lt 18....
better yet,
if [[ $TIME -ge 8 && $TIME -lt 17 (this covers 8:00 AM - 4:59 PM)
Why would it page at 22:00 on a Weekend night? Still looking and thinking, but from what I can see, it couldn't... is this the only instance of this script running?
-Tim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2001 10:18 AM
07-09-2001 10:18 AM
Re: Checking for a certain time and date variable within a script
Yep that makes much sense. When you ask "is this the only instance of this script running" what do you actually mean by that. I'm sorry to have to ask that. By the way, if it is easier for you, you can e-mail me at
cookm@fleishman.com
I really want to thank you for your efforts.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2001 10:30 AM
07-09-2001 10:30 AM
Re: Checking for a certain time and date variable within a script
I'm wondering if there isn't another cron entry on this or another server that calls this same script (or one like it) that has the hour/day check mixed up, or a -gt where a -lt is needed...
From what I see, there is no way this action would be performed unless it is between 8 AM and 5 PM on a weekday.
Also, in the 'else' section of the if loop, does it perform a similar action? I'm not sure if you removed the else section to save space/typing, or if that is the way it actually exists in the script. If there is nothing in the 'else' section, you can just remove it.
-Tim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2001 10:46 AM
07-09-2001 10:46 AM
Re: Checking for a certain time and date variable within a script
nohup ./sqlcapture > nohup.out &
Any then this guy just keeps running unless we make changes to the code. Then it is stoped and then restarted. There is much more to this script, but only the CRITICAL status is what he wants to be paged on. Do you think that because it is a continues running process, that this is why it is not working correctly? I'm grasping for straws now.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2001 11:09 AM
07-09-2001 11:09 AM
Re: Checking for a certain time and date variable within a script
I sent you an email to the address you listed above.
Is this a newly generated script, or has it been running for some time without incident?
-Tim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2001 01:12 PM
07-09-2001 01:12 PM
Re: Checking for a certain time and date variable within a script
I don't know if it helps you any, but here is a bit of script I was just playing with after reading this thread. There is an argument for the 'date' command that will return the day of the week as a number (1-Mon, 2-Tue...7-Sun), so it allows you to check for the day of the week as a number instead of a string. I use this in a script that ejects a DDS tape daily each Monday through Friday morning after a backup, but leaves the tape alone on the weekend. Here is the script I was playing with:
#!/bin/sh
# date_test
while true
do
TIME=$(date +'%H')
DAY=$(date +'%u')
if [[ $TIME -gt 7 && $TIME -lt 17 && $DAY -lt 6 ]]
then
print "TIME to work: HOUR is $TIME and WKDAY is $DAY"
else
print "TIME to go home"
fi
sleep 60
done
JP