Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- require 'time'
- # Set system time. If the new time is in the past, "Freeze" system time for some time.
- # Useful when your system time is ahead of actural time and you cannot adjust time to the past directly.
- #
- # Example:
- #
- # $0 '2013-10-1 9:30:00'
- # set date needs root
- raise "root required" if Process.uid != 0
- raise "Please provide some time such as '2013-10-1 9:30:00'" if ARGV.empty?
- expected = Time.parse(ARGV.join(' '))
- actural = Time.now
- def set_date(date)
- system "date #{date.strftime('%m%d%H%M%Y.%S')} >/dev/null"
- end
- seconds = actural - expected
- if seconds <= 0
- puts "Fast forward to #{expected}"
- set_date expected
- else
- print "Freeze system time for #{seconds} seconds."
- (seconds * 2).to_i.times do |i|
- Thread.new { set_date actural }
- sleep 0.5
- print '.' if i % 4 == 0
- end
- puts ' Done.'
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement