Tag Info

Hot answers tagged

42

You're seeing this behavior because of summer time (daylight saving time). Because you are currently in summer time, where your clock is one hour ahead, when you ask for three months ago at just after midnight on the first of June, the time ends up being one hour "earlier" because it was not summer time three months ago. The GNU date documentation suggests ...


13

If absolute timing is your primary concern, it's probably best to work off of UTC as it exists for that purpose. Michael's answer is very useful for when you have to work inside of the problem, but it's usually a good idea to avoid it entirely where you can. When your system isn't set to UTC by default, the simplest way to pass the timezone in is by ...


13

ring0 beat me by a few seconds, but the full command is: echo $(($(date --utc --date "$1" +%s)/86400)) This goes by UTC time. Result: root@hostname:~# echo $((`date --utc --date "$1" +%s`/86400)) 14984 A quick check with WolframAlpha shows that this is the correct value.


11

Don't do this. Instead use two separate cron jobs to invoke your tasks. 15 5 1 * * scripts/full_back_up 15 5 2-31 * * scripts/incremental_backup


11

The date command can't do this internally, so you need some external arithmetic. echo $((($(date +%d)-1)/7+1))


10

Has he left his computer logged in since 10/25? Some people just lock their screens at nice for weeks at a time until a Windows update forces reboot. Have Bob log off and log back on and see if it's updated.


10

In systems that represent time as a 32bit interger, no. See http://en.wikipedia.org/wiki/Year_2038_problem for more details. Per that article, the latest time that most systems can represent is 03:14:07 UTC on Tuesday, 19 January 2038. Note that most 64bit systems already use 64 bits to store time, so this won't be a problem once you upgrade (which you ...


9

I have been through this before. Try (on domU): echo 1 > /proc/sys/xen/independent_wallclock and try updating the time again.


8

This is because your system is set to use UTC (or has no Time Zone set) and not JST. The date command will accept JST as an input modifier but then uses the system default to display it. If you want your system to want your system to display the time in JST format then you should set the timezone to JST remove or rename /etc/localtime and then link the ...


7

You have serveral options; I propose two of them: Remove the file by date (each day the destination dir will be searched for files older than one month and the matches will be deleted): 10 3 * * * find /tmp/mysqldumps/ -maxdepth 1 -ctime +30 -exec rm {} \; Remove the file by name: 10 3 * * * rm /tmp/mysqldumps/mydb.`date -d "last month" +'%Y-%m-%d.gz'` ...


7

The date command can give you the number of seconds since 1970-01-01 00:00:00 UTC. date +"%s" You can divide the result by 3600*24 to get the number of days (UTC). E.g. in Bash x=`date +"%s"` ; echo $(( $x / 3600 / 24 )) to display the number of days.


7

Using the date command makes sense to me, do you have any errors in your cron log? Is the cron job being run as the superuser (required to change system time). Maybe post the cron job so we can troubleshoot it? Also, make sure ntpd is not running and resetting the clock after you change it: /etc/init.d/ntpd status Also, make sure ntpd doesn't start at ...


7

Try if [ `date +%d` != "01" ] then incremental_backup else full_backup fi


6

Just extend the call to include hour information too: sudo date +"%m/%d/%Y %H:%M:%S" -s "7/14/2010 10:00:00"


6

Three Simple Rules for Not Going Insane When Dealing With Time: First: You're running Unix (and presumably NTP): Make sure you have set your system's BIOS/Hardware clock to UTC. The absolute last thing you need is your hardware (BIOS) clock fighting with Unix over whose timezone is right and when daylight saving time begins/ends. Setting your hardware ...


6

I'm not certain how your clock got into the condition it's in, but may I suggest that you eliminate the script which calls the date command if possible? The usual method for setting the system clock on startup on most systems I've worked with is: Start the network. Start ntpd with the -g to sync the clock. -g is a new-ish option that lets ntpd step ...


6

You could do something with stat to get the file's Access, Modify and Change timestamps and then after editing the file you can use touch to set the relevant times back to what they were originally.


5

I can do it using just touch, test, and date. (tested on AIX 5.3.0.0) First you need to create a file 30 minutes in the past (Unfortunately, this requires prior knowledge of the current timezone on the machine. But you may be able to work that into things if need be.) In this example, the current timezone is EST5EDT (GMT-4). If you're lucky, the machine ...


5

You can use the following command to get the date output in the timezone GMT+5:30. $ TZ='Asia/Kolkata' date You can choose whatever timezone you want from tzselect.


5

There are two attributes in Active Directory for Last Login tracking lastLogon and `lastLogonTimestamp'. The first (lastLogon) is a per Domain controller attribute that can take up to two weeks to sync to all other DC's due to low priority sync. When synced it updates 'lastLogonTimestamp' which is the one shared by all DC's. I imagine that the AD Admin ...


4

If you don't have ntp running than it appears that Guest Additions is resetting the date to that found in the VM virtual bios. Have a look at this discussion for some more information and some scripts to change the vbios date/time.


4

This can also come from the client having an incorrect time.


4

I'm a little late to this party, but this will give you the day of week: wmic path win32_localtime get dayofweek Use a batch for loop to obtain the output, and you have a testable condition for the day of the week. Rob


4

Instead of parsing the file name, you can also check the modification time of a file. The next command looks in the /tmp/mysqldumps directory. Filenames starting with mydb. and ending on .gz, older than 30 days are removed. find /tmp/mysqldumps -name 'mydb.*.gz' -mtime +30 -exec rm {} \;


4

You should fix the real problem instead of working around it: your clock is drifting (either your DC or your XP client). What you should do is configure the windows time service (http://technet.microsoft.com/en-us/library/bb490605.aspx) to keep the clock in sync. This will resolve your issue indefinitely. In direct answer to your question, whenever the ...


4

There are a few relative date strings. minutes ago works (vs. minutes-ago with the dash). There are quite a few examples on the coreutils date info pages: http://www.gnu.org/software/coreutils/manual/html_node/Date-input-formats.html


4

Cron is not a shell - it does not parse commands in the same way that a shell does. As such, your variable is assigned as if it was static text. There are three solutions I know of to this problem: Option 1: Use a shell script to generate your command, include whatever variables and logic you want - and call that shell script from cron. * * * * * ...


4

Save yourself a world of pain, use a better language! Here is the script you want in PowerShell: $yesterday = [DateTime]::Today.AddDays(-1).ToString("yyMMdd") copy \\server01\E$\LogFiles\IVR\bcR\??${yesterday}.* \\LBC\workgroup\cs\ftp\Team\bcR\ copy \\server02\E$\LogFiles\IVR\bcR\??${yesterday}.* \\LBC\workgroup\cs\ftp\Team\bcR\ copy ...


4

You can't set the time yourself in a shared-kernel, container-based VPS such as OpenVZ or Virtuozzo. If the system time is wrong, contact the hosting provider. If the system time remains wrong, switch to another provider and consider using something other than OpenVZ. Problems with the system time is, in fact, one of the many reasons I don't use OpenVZ ...


4

Without knowing more about your setup, your theory sounds plausible. You will want to change your startup scripts to ensure that your date command which sets the system date is complete before ntpdate starts.



Only top voted, non community-wiki answers of a minimum length are eligible