0

I'd like to know if there's a way to find out when the next time a cron job will run - via a bash job. Has anyone tried something like this?

I've been googling but I haven't found anything yet.

Thanks.

EDIT 1

Just some more details of what I'm after. When I check crontab -l, see the following output:

lab-1:/etc/crontabs# crontab -l
# do daily/weekly/monthly maintenance
# min   hour    day     month   weekday command
*/15    *       *       *       *       run-parts /etc/periodic/15min
0       *       *       *       *       run-parts /etc/periodic/hourly
0       2       *       *       *       run-parts /etc/periodic/daily
0       3       *       *       6       run-parts /etc/periodic/weekly
0       5       1       *       *       run-parts /etc/periodic/monthly

#Ansible: Run every minute
* * * * * run-parts /etc/periodic/1min

What I need to know is not just that the 15 minute folder is "enabled" but if there's a way, I'd like to know that for example, 3 minutes from now, the job in the 15 minute folder will be triggered.

Is there any way to do this?

0

I don't know if it fit exactly your needs, but you can translate crontab files in english, check crontab2english

   Usage:
     % crontab2english [-f] files...
   Or:
     % cat files... | crontab2english

   If you do just this:
     % crontab2english
   then it's the same as crontab -l | crontab2english

   Example output:
   % crontab2english | less
   Setting env var MAILTO to hulahoops@polygon.int

   Command: (line 2)
     Run: /bin/csh -c 'perl ~/thang.pl | mail -s hujambo root'
     At: 8:10am on    the 15th of    every month

   Command: (line 5)
     Run: df -k
     At: 5:40am    every day

   Command: (line 7)
     Run: ls -l /tmp
     At: 6:50am    every Monday

   Or with the -f ("f" for filter) switch, it just adds comments
   to the input file:

   % crontab2english -f | less
   # My happy crontab file
   MAILTO=hulahoops@polygon.int
   10 8 15 * * /bin/csh -c 'perl ~/thang.pl | mail -s hujambo root'
   #>  At: 8:10am on    the 15th of    every month


   40 5 * * * df -k
   #>  At: 5:40am    every day

   50 6 * * 1 ls -l /tmp
   #>  At: 6:50am    every Monday
  • hm. i need something either in bash or python. – dot Feb 15 '18 at 20:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.