Operating System - HP-UX
1751907 Members
5100 Online
108783 Solutions
New Discussion юеВ

Re: Script to know that server time has a new date

 
Deepu Chakravarty
Regular Advisor

Script to know that server time has a new date

Need a script which will tell that the server time has the clock time 12 midnight. The script should check when the 12 midnight has occurred in the server and print a message as soon as the server has the new day with midnight 12 a.m.

Please suggest.
7 REPLIES 7
Stephan.
Honored Contributor

Re: Script to know that server time has a new date

Deepu Chakravarty
Regular Advisor

Re: Script to know that server time has a new date

But what to write in cron job? The script is required.
Stephan.
Honored Contributor

Re: Script to know that server time has a new date

The question is what you want, a email to ?, a message to all user, an entry in a log file, ...

Usual crontab syntax would be:

0 0 * * *

for example insert a message to syslog.log:

0 0 * * * /usr/bin/echo "+++ Midnight +++" >> /var/adm/syslog/syslog.log

hth

Deepu Chakravarty
Regular Advisor

Re: Script to know that server time has a new date

This script you have provided will only append the text "Midnight" in syslog file. But my requirement is different. The script can be run as a cron job. I am restating my requirement as follows:
1. The cron job should check that midnight(12 a.m.) occurs in the server,
2. The cron job should immediately print in the file /tmp/midnight.txt the current time of the server.
Dennis Handly
Acclaimed Contributor

Re: Script to know that server time has a new date

>But my requirement is different.

But once you know about crontab, you should be able modify it to do what you want.

>2. The cron job should immediately print in the file /tmp/midnight.txt the current time of the server.

0 0 * * * date > /tmp/midnight.txt
Stephan.
Honored Contributor

Re: Script to know that server time has a new date

>This script you have provided will only append the text "Midnight" in syslog file. But my requirement is different

Without any given information or requirements i can only answer with examples.

Perhaps a simple 'man cron' helps.

#man cron


NAME
cron - timed-job execution daemon

SYNOPSIS
/usr/sbin/cron

DESCRIPTION
cron executes commands at specified dates and times.

For the new requiremnts Dennis posted the correct answer.
James R. Ferguson
Acclaimed Contributor

Re: Script to know that server time has a new date

Hi:

> Need a script which will tell that the server time has the clock time 12 midnight. The script should check when the 12 midnight has occurred in the server and print a message as soon as the server has the new day with midnight 12 a.m.

And that's because you're not sure if midnight will come every day?

...JRF...