Add article for at command
parent
053d69c331
commit
376b033c6b
@ -0,0 +1,93 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<meta name="description" content="A guide to adding a free SSL certificate to your website(s) using cerbot, and automatically renewing them">
|
||||||
|
<meta name="keywords" content="Blog, articles, guide, certbot, SSL, secure certificate, website">
|
||||||
|
<meta name="author" content="Nathan (Aney) Steel">
|
||||||
|
<meta name="theme-color" content="white">
|
||||||
|
<meta name="theme-color" content="black">
|
||||||
|
<link rel="stylesheet" type="text/css" href="/main.css">
|
||||||
|
<link rel="icon" type="image/png" href="/images/favicon.svg">
|
||||||
|
<title>at, for one-off cronjobs</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<header>
|
||||||
|
<a href="#main" class="vh">Jump directly to main content</a>
|
||||||
|
<h1>at, for one-off cronjobs</h1>
|
||||||
|
<input id="burger-toggle" type="checkbox"/>
|
||||||
|
<label class="burger-container" for="burger-toggle"><div class="burger"></div><span class="sr">Burger menu</span></label>
|
||||||
|
<hr/>
|
||||||
|
<nav>
|
||||||
|
<a href="/">home</a>
|
||||||
|
<a href="/about.html">about</a>
|
||||||
|
<a href="/projects.html">projects</a>
|
||||||
|
<a href="/blog/">blog</a>
|
||||||
|
<a href="/sitemap.html">misc</a>
|
||||||
|
<a href="/support.html">support</a>
|
||||||
|
</nav>
|
||||||
|
<hr/>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<main id="main">
|
||||||
|
<section>
|
||||||
|
<p><a href="/guides/backup-with-cron.html#add-a-cronjob">Scheduling a cronjob</a> is great, but sometimes you only want it to run once. You could add, then remove the job, or write a script that executes once, but there is a better way.</p>
|
||||||
|
|
||||||
|
<h2>Install at</h2>
|
||||||
|
<pre><code>sudo apt install at</code></pre>
|
||||||
|
|
||||||
|
<h2>Schedule a script with at</h2>
|
||||||
|
<p>The below examples show two different ways to run a script with at.</p>
|
||||||
|
<pre><code>echo /script/to/run | at 20:30</code></pre>
|
||||||
|
<pre><code>at 20:30 -f ./script/to/run</code></pre>
|
||||||
|
<p>For this, the script needs to exist, and needs executable permissions for your user, <code>sudo chmod +x /script/to/run</code>, if you need a lil' hint.</p>
|
||||||
|
|
||||||
|
<p>The time/date passed <code>20:30</code> in this example, can then be passed in a few assorted ways.</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><code>at now +5 minutes</code></li>
|
||||||
|
<li><code>at 11:00 today</code></li>
|
||||||
|
<li><code>at 11:00 tomorrow</code></li>
|
||||||
|
<li><code>at 20:30</code></li>
|
||||||
|
<li><code>at 20:30 093024</code></li>
|
||||||
|
<li><code>at 08:30PM Sep 30</code></li>
|
||||||
|
<li><code>at 08:30PM Sep 30 2024</code></li>
|
||||||
|
<li><code>at 08:30PM Sep 30 24</code></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<h3>Batch a script</h3>
|
||||||
|
<p>Similar to the regular means of scheduling, except the batch will wait for the system load drops to a set point.</p>
|
||||||
|
<pre><code>echo /script/to/run | at -b 20:30</code></pre>
|
||||||
|
<p>You can also run <code>batch</code>, as follows.</p>
|
||||||
|
<pre><code>echo /script/to/run | batch 20:30</code></pre>
|
||||||
|
|
||||||
|
<h2>Check Queue</h2>
|
||||||
|
<pre><code>atq</code></pre>
|
||||||
|
<p>Running the command above, will show you something akin to...</p>
|
||||||
|
<pre><code>10 Sun Sep 29 14:14:00 2024 a user</code></pre>
|
||||||
|
<p>Which broken down shows the ID <code>10</code>, the date/time the item will run <code>Sun Sep 29 14:14:00 2024</code>,
|
||||||
|
the queue the item is in <code>a</code>, and the user executing the item <code>user</code></p>
|
||||||
|
|
||||||
|
|
||||||
|
<h2>Remove from Queue</h2>
|
||||||
|
<p>You can remove an item from the queue, with the <code>atrm</code> command, passing just the ID.</p>
|
||||||
|
<pre><code>atrm 3</code></pre>
|
||||||
|
|
||||||
|
<h2>Mail the user</h2>
|
||||||
|
<p>Like cron, at also allows the ability to mail the user about the task once executed. By default, if the command produces an output, at will mail the user, you can override this with:</p>
|
||||||
|
<pre><code>at -M</code></pre>
|
||||||
|
<p>This will prevent mail being sent to the user. You can also force a mail sent even if there is no output with:</p>
|
||||||
|
<pre><code>at -m</code></pre>
|
||||||
|
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
<hr/>
|
||||||
|
<p>Written by <a href="https://aney.co.uk" target="_blank" rel="noopener">@aney</a> with <a href="https://danluu.com/web-bloat/" target="_blank" rel="noopener">web bloat</a> in mind | <a href="https://github.com/Aney/website" target="_blank" rel="noopener">Source Code</a></p>
|
||||||
|
</footer>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
Loading…
Reference in New Issue