Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8696169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:13:02+00:00 2026-06-13T01:13:02+00:00

Is there a way to validate crontabs with ruby? I’ve seen some decent php

  • 0

Is there a way to validate crontabs with ruby? I’ve seen some decent php implementations.

Crontabs are pretty common knowledge, so I will spare the details, though I don’t need the keywords like reboot to work.
basically just numbers with commas and dashes like so

0 4 25,31 12 2012-2020
  • the next 8 christmases and new years at 4 am
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T01:13:03+00:00Added an answer on June 13, 2026 at 1:13 am

    Well, it’s not the prettiest, though I made something that will split it up and parse it out. This isn’t going to be touched very often so I’m not worried about speed, though it should handle everything that whenever cannot handle, such as ranges and comma separated dates, as well as reboot.

    how it works?

    there is a method called cron_wrong which just adds a base error.

    I am using 2 columns, interval and interval_type .
    interval_type can be cron, @reboot, minute, hour, day, month, year. if it is minute, hour, day, month, or year, I am just passing the interval and interval_type to whenever and doing interval.send interval_type or using @reboot

    The tricky part is when the interval_type is cron — I am validating that it is indeed a valid cron string

     def cron_intervals
        non_num_at_beg_or_end = /^[^\d]|[^\d]$/
        has_non_nums = /[^\d]/
    
        return if interval_type == '@reboot'
    
        if interval_type != 'cron'
          has_non_nums.match(interval) { |str| errors.add :interval, "#{str} must be number" }
          errors.add :interval, "can't be blank" if interval.length == 0
          return
        end
    
    
        cron = interval.split(' ')
    
        if cron.length != 5
          cron_wrong
          errors.add :interval, 'Wrong number of arguments supplied, (must be 5 -- minute hour day month year)'
          return
        end
    
    
        cron.each do |c|
          # return if star or only numbers
          if c == '*' || !has_non_nums.match(c)
            next
          end
    
          non_num_at_beg_or_end.match(c) do |str|
            cron_wrong
            errors.add :interval, "Non-number '#{str}' found"
            return
          end
    
          c.split(',').each do |spl_dash|
            non_num_at_beg_or_end.match(spl_dash) do |str|
              cron_wrong
              errors.add :interval, "Non-number '#{str}' found"
              return
            end
    
            range = spl_dash.split('-')
    
            if range.length < 1 || range.length > 2
              cron_wrong 
              errors.add :interval, "ranges must be between two numbers"
              return
            elsif range.length == 2 and not (range[0].to_i < range[1].to_i)
              cron_wrong 
              errors.add :interval, "range numbers must be lower-higher"
              return
            end
    
            range.each do |num|
    
              # should be only numbers at this point
              has_non_nums.match(num) do |str|
                cron_wrong
                errors.add :interval, "Non-number '#{str}' found"
                return
              end
              if num.length.blank?
                cron_wrong
                errors.add :interval, "No number supplied"
              end
            end
          end
        end
      end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there some way to validate the image size (height and width) before upload
Is there any way to validate all countries phone number with php
Is there any way to validate the contents of a CEdit box without subclassing?
Is there any way to validate spring context xml files in eclipse? Features like:
Is there any way to validate using DataAnnotations in WPF & Entity Framework?
Is there a way to validate an XML file against a DTD with Qt's
I created this regular expression to validate names: ^[a-zA-Z0-9\s\-\,]+.\*?$ Is there a way add
Is there a way to validate that one text_field does not equal another before
is there any way to validate -moz-border-radius / -webkit-border-radius in the CSS validator? The
Is there any way to validate that a polymorphic association is only related to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.