crontab time-to-run utility

Thus fun small script will give you a nice eye-candy log of your time-to-next-run on each line of your crontab!

crontab time-to-run utility

This small block of python code will automatically show you the number of days, hours, and minutes until the next item in your cron runs.  Handy!

What is this?  If you run the unix system there are two methods commonly utilized to run tasks at intervals (like windows task manager.)  One is the older cron, and the newer one is to build a systemctl module.   System administrators that do not need the exotic and complexity of using systemctl modules cna often set a schedule for a task by simply:

crontab -e   # Edit tasks 
crontab -l	# List the crontab

Hostzinger has a good basic article on the basics of setting up your crontab schedule

from colorama import Fore
from croniter import croniter
import subprocess
import datetime

start_time =
print(St, f"{Fore.GREEN} cron inspect start :: {Fore.LIGHTCYAN_EX}{start_time}{Fore.RESET}")
	cronlist = subprocess.check_output(['crontab', '-l'])
    cronlist = cronlist.decode('utf-8').split('\n')
    for cron in cronlist:
    	if cron[0] != '#' and len(cron) > 5:
        	cron = cron.split('/')[0]
            cvalue = croniter(cron, start_time)
            nextrun = cvalue.get_next()
            nextrun_time = datetime.datetime.fromtimestamp(nextrun)
            delta_time = nextrun_time - start_time
            delta_hours = int(delta_time.seconds / 3600)
            delta_min = int(delta_time.seconds / 60) % 60
            print(St, f"{Fore.GREEN}       cron run :: {Fore.LIGHTCYAN_EX}{cron} :: {nextrun_time} :: {delta_time.days} days {delta_hours} hrs {delta_min} min {Fore.RESET}")
except Exception as e:
	print(St,f"{Fore.RED} cron inspect fail :: {Fore.LIGHTCYAN_EX}")

Some purdy outputs:

Linux Rocks Every Day