TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: How do you monitor your background jobs?

1 pointsby kostareloabout 5 years ago
When you have many background jobs, that take either a few seconds or lots of minutes&#x2F;hours, how do you monitor them?<p>How do you know when they started and when they finished, their outcome, etc. Do others, non-tenchical folks, need access to that or is it just the developers?

1 comment

simonblackabout 5 years ago
Most background jobs are run by cron.<p>Cron has the capability to set environment variables. The scripts&#x2F;programs can check those variables and then have the ability to adjust the type and quantity of logging according to whether they are run as cron jobs or from the command-line.<p>The logging of these jobs goes to a specific log file which is rotated daily. The daily logs are kept for 10 days before being discarded.<p>For instance this is a cron entry. Note the logfile argument as $1.<p><pre><code> # update BAK_MONTHLY on 2nd of the month only 24 09 2 * * &#x2F;home&#x2F;jvs&#x2F;binscripts&#x2F;rsync.bak.monthly.xpz &#x2F;var&#x2F;log&#x2F;cronlog_jvs </code></pre> This is cron setting variables in the crontab file<p><pre><code> # DO NOT EDIT THIS FILE - edit the master and reinstall. # tell cronjobs that they are running under cron CRONJOB=CRONJOB # specify the logfile for cronjobs output LOGFILE=&#x2F;var&#x2F;log&#x2F;cronlog_jvs # expand the path PATH=&#x2F;usr&#x2F;sbin:&#x2F;sbin:&#x2F;usr&#x2F;local&#x2F;sbin:&#x2F;usr&#x2F;bin:&#x2F;bin:&#x2F;usr&#x2F;local&#x2F;bin:&#x2F;home&#x2F;jvs&#x2F;binscripts # # m h dom mon dow command </code></pre> and this is a cronjob template<p><pre><code> #!&#x2F;bin&#x2F;bash #jvs script # # DATE WRITTEN ...... # # This crontab item does ........ # #Set variables TARGET= NOW=$(date +%y%m%d) DAY=$(date +%d) LOGFILE=&quot;&#x2F;tmp&#x2F;${HOSTNAME}.crontab-item.log&quot; if [ &quot;$1&quot; != &quot;&quot; ]; then LOGFILE=&quot;$1&quot; fi touch &quot;$LOGFILE&quot; chmod 666 &quot;$LOGFILE&quot; echo -e &quot;#######################################################\n &quot; &gt;&gt;&quot;$LOGFILE&quot; &#x2F;bin&#x2F;date +&quot;%F %H%M&quot; &gt;&gt;&quot;$LOGFILE&quot; 2&gt;&amp;1 echo &quot;$0&quot; &gt;&gt;&quot;$LOGFILE&quot; ### *************************************************** ### ******* Guts of crontab item goes here ******** ### *************************************************** # Say when this item completed echo -e &quot;\n$0 Completed at $(date)&quot; &gt;&gt;&quot;$LOGFILE&quot;</code></pre>