Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>NOTE: Running this as root, or using <code>sudo</code> should capture all the cron jobs on a system, not just a single users' jobs. Run it as yourself or as that user and it might capture just those jobs. I haven't test that aspect of it.</p> <hr> <p>Trying to run <code>crontab -l</code> to capture crontab files for all the users and packages seems the indirect way to do the task and could have the hassle of dealing with password requests hanging your code. I'd write code to comb through the directories that store them, rather than mess with prompts. Run the code using <code>sudo</code> and you shouldn't have any problems accessing the files.</p> <p>Take a look at the discussion at: <a href="http://www.linuxquestions.org/questions/linux-newbie-8/etc-crontab-vs-etc-cron-d-vs-var-spool-cron-crontabs-853881/" rel="nofollow noreferrer">http://www.linuxquestions.org/questions/linux-newbie-8/etc-crontab-vs-etc-cron-d-vs-var-spool-cron-crontabs-853881/</a> for information on where the actual cron tab files are stored on disk. </p> <p>Also <a href="https://superuser.com/questions/389116/how-to-recover-crontab-jobs-from-filesystem/389137">https://superuser.com/questions/389116/how-to-recover-crontab-jobs-from-filesystem/389137</a> has similar information. </p> <p>Mac OS varies a little from Linux in where Apple puts the cron files. Run <code>man cron</code> at the command-line for the definitive details on either OS.</p> <hr> <p>Here's slightly-tested code for how I'd back up the files. How you restore them is for you to figure out, but it shouldn't be hard to figure out:</p> <pre><code>require 'fileutils' BACKUP_PATH = '/path/to/some/safe/storage/directory' CRONTAB_DIRS = %w[ /usr/lib/cron/tabs /var/spool/cron /etc/anacrontab /etc/cron.d ] CRONTAB_FILES = %w[ /etc/cron_list ] def dump_pre_cron_jobs(file_path) full_backup_path = File.join( BACKUP_PATH, File.dirname(file_path) ) FileUtils.mkdir_p(full_backup_path) unless Dir.exist?(full_backup_path) File.write( File.join( full_backup_path, file_path ), File.read(file_path) ) rescue Exception =&gt; e STDERR.puts e.message end CRONTAB_DIRS.each do |ct| next unless Dir.exist?(ct) begin Dir.entries(File.join(ct, '*')).each { |fn| dump_pre_cron_jobs(fn) } rescue Errno::EACCES =&gt; e STDERR.puts e.message end end CRONTAB_FILES.each do |fn| dump_pre_cron_jobs(fn) end </code></pre> <p>You'll need to run this as root via <code>sudo</code> to access the directories and files as they're usually locked down from unauthorized prying eyes.</p> <p>The code creates a repository of crontabs, in <code>BACKUP_PATH</code>, based on their original file paths. No changes are made to the file contents so they can be restored as-is by copying them back via <code>cp</code> or writing code to reverse this process.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload