Set up a special command in the crontab.

    CLI Example:

    .. code-block:: bash

        salt '*' cron.set_special root @hourly 'echo foobar'
161207
def set_special(user,
                special,
                cmd,
                commented=False,
                comment=None,
                identifier=None):
    '''
    
    '''
    lst = list_tab(user)
    for cron in lst['special']:
        cid = _cron_id(cron)
        if _cron_matched(cron, cmd, identifier):
            test_setted_id = (
                cron['identifier'] is None
                and SALT_CRON_NO_IDENTIFIER
                or cron['identifier'])
            tests = [(cron['comment'], comment),
                     (cron['commented'], commented),
                     (identifier, test_setted_id),
                     (cron['spec'], special)]
            if cid or identifier:
                tests.append((cron['cmd'], cmd))
            if any([_needs_change(x, y) for x, y in tests]):
                rm_special(user, cmd, identifier=cid)

                # Use old values when setting the new job if there was no
                # change needed for a given parameter
                if not _needs_change(cron['spec'], special):
                    special = cron['spec']
                if not _needs_change(cron['commented'], commented):
                    commented = cron['commented']
                if not _needs_change(cron['comment'], comment):
                    comment = cron['comment']
                if not _needs_change(cron['cmd'], cmd):
                    cmd = cron['cmd']
                    if (
                        cid == SALT_CRON_NO_IDENTIFIER
                    ):
                        if identifier:
                            cid = identifier
                        if (
                            cid == SALT_CRON_NO_IDENTIFIER
                            and cron['identifier'] is None
                        ):
                            cid = None
                        cron['identifier'] = cid
                if not cid or (
                    cid and not _needs_change(cid, identifier)
                ):
                    identifier = cid
                jret = set_special(user, special, cmd, commented=commented,
                                   comment=comment, identifier=identifier)
                if jret == 'new':
                    return 'updated'
                else:
                    return jret
            return 'present'
    cron = {'spec': special,
            'cmd': cmd,
            'identifier': identifier,
            'comment': comment,
            'commented': commented}
    lst['special'].append(cron)

    comdat = _write_cron_lines(user, _render_tab(lst))
    if comdat['retcode']:
        # Failed to commit, return the error
        return comdat['stderr']
    return 'new'
1364824
function Cron (pattern, options, fn) {
		var self = this;
		
		// Optional "new" keyword
		if( !(this instanceof Cron) ) {
			return new Cron(pattern, options, fn);
		}

		self.pattern = new CronPattern(pattern);

		self.schedulerDefaults = {
			stopAt:     Infinity,
			maxRuns:    Infinity,
			kill:       false
		};

		// Make options optional
		if( typeof options === "function" ) {
			fn = options;
			options = {};
		}

		// Store and validate options
		self.opts = self.validateOpts(options || {});

		// Determine what to return, default is self
		if( fn === void 0 ) {
			// Normal initialization, return self
			return self;

		} else {
			// Shorthand schedule requested, return job
			return this.schedule(options, fn);

		}

	}
1165175
def _sysv_enabled(name, root):
    '''
    
    '''
    # Find exact match (disambiguate matches like "S01anacron" for cron)
    rc = _root('/etc/rc{}.d/S*{}'.format(_runlevel(), name), root)
    for match in glob.glob(rc):
        if re.match(r'S\d{,2}%s' % name, os.path.basename(match)):
            return True
    return False
315571
def _check_cron(user,
                path,
                mask,
                cmd):
    '''
    
    '''
    arg_mask = mask.split(',')
    arg_mask.sort()

    lst = __salt__['incron.list_tab'](user)
    for cron in lst['crons']:
        if path == cron['path'] and cron['cmd'] == cmd:
            cron_mask = cron['mask'].split(',')
            cron_mask.sort()
            if cron_mask == arg_mask:
                return 'present'
            if any([x in cron_mask for x in arg_mask]):
                return 'update'
    return 'absent'
1176872
def call(command, silent=False):
    
    try:
        if silent:
            with open(os.devnull, 'w')  as FNULL:
                return subprocess.check_call(command_to_array(command), stdout=FNULL)
        else:
            # Using the defaults, shell=False, no i/o redirection.
            return check_call(command_to_array(command))
    except CalledProcessError as e:
        # We are modifying the error itself for 2 reasons.  1) it WILL contain
        # login credentials when run_mongodump is run, 2) CalledProcessError is
        # slightly not-to-spec (the message variable is blank), which means
        # cronutils.ErrorHandler would report unlabeled stack traces.
        e.message = "%s failed with error code %s" % (e.cmd[0], e.returncode)
        e.cmd = e.cmd[0] + " [arguments stripped for security]"
        raise e
1009992
protected function setCron()
    {
        $interval = (int) $this->config('cron_interval', 24 * 60 * 60);

        if (!empty($interval) && (GC_TIME - $this->config('cron_last_run', 0)) > $interval) {
            $url = $this->url('cron', array('key' => $this->config('cron_key', '')));
            $this->setJs("\$(function(){\$.get('$url', function(data){});});", array('position' => 'bottom'));
        }
    }
1046063
def _setup_root_plugins(self):
        

        def run_root(_self, command):
            """ Executes a shell command as root.

                `command`
                    Shell command string.

                Returns boolean.
                """

            try:
                # get lock, so this plugin has exclusive access to command pipe
                self._rlock.acquire()

                # TODO: log root command for this plugin
                self._cmd_pipe.send_bytes('\x80'.join(['SHL', command]))
                res = self._cmd_pipe.recv_bytes()

                if res != 'TRM':  # sentinel value, shutdown
                    return res == 'OK'

            except (EOFError, IOError):
                pass

            finally:
                self._rlock.release()

            self.shutdown(skip_hooks=True)
            return False

        # inject method into each event plugin
        for plugin in registration.get_registered(event_hooks=True,
                                                  root_access=True):
            plugin.run_root = types.MethodType(run_root, plugin)
212542
def _timedatectl():
    '''
    
    '''
    ret = __salt__['cmd.run_all'](['timedatectl'], python_shell=False)

    if ret['retcode'] != 0:
        msg = 'timedatectl failed: {0}'.format(ret['stderr'])
        raise CommandExecutionError(msg)

    return ret
188776
function (data) {
  var q = _q.defer();
  data = data.replace(/\'/g,"\\\'");
  data = data.replace(/\"/g,'\\\"');
  exec(`echo "${data}" | crontab -`, (err, stdout, stderr) => {
    if (err) q.reject(err);
    if(stdout)q.resolve(stdout);
    else q.resolve(stderr);
  });
  return q.promise;
}
1028507
protected function crontabCommand(Crontab $crontab)
    {
        $cmd = $this->getCrontabExecutable();
        if ($crontab->getUser()) {
            $cmd .= sprintf(' -u %s ', $crontab->getUser());
        }

        return $cmd;
    }
714346
def update(every, timezone: nil)
            time = Scheduler.parse_in(every, :quiet) || Scheduler.parse_cron(every, :quiet, timezone: timezone)
            raise ArgumentError.new("couldn't parse \"#{o}\"") if time.nil?

            @every = time
            reschedule
        end
484033
def schedule(code, interval, secret_key=None, url=None):
  
  if not secret_key:
    secret_key = default_key()
  if not url:
    url = default_url()

  url = '%s/schedule' % url
  values = {
    'interval': interval,
    'code': code,
  }
  return _send_with_auth(values, secret_key, url)
503878
def build_crontab_output(opts)
      chdir = Makesure.chdir || File.dirname(Makesure.makesurefile)
      crontab = ""
      crontab << "# Autogenerated by makesure: you probably don't want to edit this file\n\n"
      crontab << "# Cron environment\n"
      crontab << (Makesure.cron_env || "#   customize this by setting Makesure.cron_env in your Makesurefile")
      crontab << "\n"
      Makesure.systems.each do |s|
        uid = s.uid || Makesure.uid
        crontab << "\n"
        crontab << "## Tasks for '#{s.name}'\n"
        crontab << "# Commands\n"
        s.cmds.each do |c|
          crontab << "#{c.cron}\t"
          crontab << "#{uid} " if uid
          crontab << "cd #{chdir} && "

          cmd = "makesure-runner run #{c.command.inspect}"
          crontab << if (opts[:rvm])
            "/bin/bash -l -c '#{cmd}'"
          else
            cmd
          end
          crontab << "\n"
        end

        crontab << "# Verification\n"
        s.verifies.each do |v|
          crontab << "#{v.cron}\t"
          crontab << "#{uid} " if uid
          crontab << "cd #{chdir} && "

          cmd = "makesure-runner verify #{s.name} #{v.name}"
          crontab << if (opts[:rvm])
            "/bin/bash -l -c '#{cmd}'"
          else
            cmd
          end
          crontab << "\n"
        end
        # TODO summarizes
      end
      crontab
    end
1120004
def set_job(user, path, mask, cmd):
    '''
    
    '''
    # Scrub the types
    mask = six.text_type(mask).upper()

    # Check for valid mask types
    for item in mask.split(','):
        if item not in _MASK_TYPES:
            return 'Invalid mask type: {0}' . format(item)

    updated = False
    arg_mask = mask.split(',')
    arg_mask.sort()
    lst = list_tab(user)

    updated_crons = []
    # Look for existing incrons that have cmd, path and at least one of the MASKS
    # remove and replace with the one we're passed
    for item, cron in enumerate(lst['crons']):
        if path == cron['path']:
            if cron['cmd'] == cmd:
                cron_mask = cron['mask'].split(',')
                cron_mask.sort()
                if cron_mask == arg_mask:
                    return 'present'

                if any([x in cron_mask for x in arg_mask]):
                    updated = True
                else:
                    updated_crons.append(cron)
            else:
                updated_crons.append(cron)
        else:
            updated_crons.append(cron)

    cron = {'cmd': cmd, 'path': path, 'mask': mask}
    updated_crons.append(cron)

    lst['crons'] = updated_crons
    comdat = _write_incron_lines(user, _render_tab(lst))
    if comdat['retcode']:
        # Failed to commit, return the error
        return comdat['stderr']

    if updated:
        return 'updated'
    else:
        return 'new'
2639
public function parseExistingCrontab(Crontab $crontab)
    {
        // parsing cron file
        $process = new Process($this->crontabCommand($crontab).' -l');
        $process->run();

        foreach ($this->parseString($process->getOutput()) as $item) {
            $crontab->addItem($item);
        }

        $this->error = $process->getErrorOutput();

        return $this;
    }
943505
def schedule(dev):
    
    # TODO: expose setting the schedule somehow?
    for d in range(7):
        dev.query_schedule(d)
    for day in dev.schedule.values():
        click.echo("Day %s, base temp: %s" % (day.day, day.base_temp))
        current_hour = day.next_change_at
        for hour in day.hours:
            if current_hour == 0: continue
            click.echo("\t[%s-%s] %s" % (current_hour, hour.next_change_at, hour.target_temp))
            current_hour = hour.next_change_at
816280
def run_cron_with_cache_check(cron_class, force=False, silent=False):
    

    with CronJobManager(cron_class, silent) as manager:
        manager.run(force)