{"id":525,"date":"2012-08-03T10:22:27","date_gmt":"2012-08-03T14:22:27","guid":{"rendered":"http:\/\/www.deadcodersociety.org\/?p=525"},"modified":"2012-08-03T10:39:27","modified_gmt":"2012-08-03T14:39:27","slug":"using-irc-to-set-reminders-with-the-at-command","status":"publish","type":"post","link":"http:\/\/www.deadcodersociety.org\/blog\/using-irc-to-set-reminders-with-the-at-command\/","title":{"rendered":"Using IRC to set Reminders with the &#8220;at&#8221; Command"},"content":{"rendered":"<figure id=\"attachment_526\" aria-describedby=\"caption-attachment-526\" style=\"width: 300px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/www.deadcodersociety.org\/blog\/wp-content\/uploads\/2012\/07\/reminder.jpeg\"><img loading=\"lazy\" class=\"size-medium wp-image-526\" title=\"reminder\" src=\"http:\/\/www.deadcodersociety.org\/blog\/wp-content\/uploads\/2012\/07\/reminder-300x199.jpeg\" alt=\"reminder\" width=\"300\" height=\"199\" srcset=\"http:\/\/www.deadcodersociety.org\/blog\/wp-content\/uploads\/2012\/07\/reminder-300x199.jpeg 300w, http:\/\/www.deadcodersociety.org\/blog\/wp-content\/uploads\/2012\/07\/reminder.jpeg 500w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-526\" class=\"wp-caption-text\">Remind me at 5pm to go to the bank<\/figcaption><\/figure>\n<p>You can use IRC to remind you to do anything. Now that you have a <a title=\"Mixing the Command-Line and IRC\" href=\"http:\/\/www.deadcodersociety.org\/blog\/mixing-the-command-line-and-irc-bots\" target=\"_blank\">directory that your IRC bot reads<\/a>, you can use one of Linux&#8217;s best kept secrets: the <a title=\"At command\" href=\"http:\/\/en.wikipedia.org\/wiki\/At_(Unix)\" target=\"_blank\">at command<\/a>. The at command allows you to schedule one-time jobs to be run in the future &#8212; a non-reoccurring cronjob. The real win with using at is its time syntax.\u00a0Here&#8217;s a few examples from the man page:<\/p>\n<ul>\n<li>to run a job at 4pm three days from now, you would do <strong>at 4pm + 3 day<\/strong><\/li>\n<li>to run a job at 10:00am on July 31, you would do <strong>at 10am Jul 31<\/strong><\/li>\n<li>to run a job at 1am tomorrow, you would do <strong>at 1am tomorrow<\/strong>.<\/li>\n<\/ul>\n<p>You can use this to run any command or script at a given time. This makes the at command perfect for usage over IRC &#8212; we just need to drop a file with the reminder in the \/say directory at the given time. It&#8217;s easy to wrap some of this syntax to give the reminder command a human-like syntax.<\/p>\n<p><strong>Syntax<\/strong><\/p>\n<p>I went with the following syntax, best expressed with a summarized version of the regular expression used to parse it:<\/p>\n<pre> ^(remind|pm) (me|us|everyone) (at|in|on) (.*?) to (.*)$<\/pre>\n<p>You might say the following things in the IRC channel to the bot:<\/p>\n<ul>\n<li>remind me in 5 minutes to check the dryer<\/li>\n<li>pm me at 10pm to remember to charge my cell phone<\/li>\n<li>remind everyone on august 1s to enjoy the weather<\/li>\n<\/ul>\n<p>These commands all get sent to at. Behind the scenes, the bot does the following:<\/p>\n<ol>\n<li>creates a file under \/var\/tmp with the contents of the reminder. The filename follows the format mentioned in the <a title=\"Mixing the command-line and IRC\" href=\"http:\/\/www.deadcodersociety.org\/blog\/mixing-the-command-line-and-irc-bots\" target=\"_blank\">Mixing the Command-Line and IRC<\/a> post, and sets the unique identifier to a hash of the submitter&#8217;s nick and current timestamp.<\/li>\n<li>the at command is instructed to move the file from \/var\/tmp\/ to the ~\/say directory at the requested time<\/li>\n<li>at the requested time, at moves the file and the bot picks it up and prints it to the channel.<\/li>\n<\/ol>\n<p>There&#8217;s only a small amount of additional wrapping needed to make the interaction fluid. The biggest abstraction is in the difference between the &#8220;remind me\u00a0<strong>at\/on<\/strong>&#8221; and &#8220;remind me\u00a0in&#8221; commands. &#8220;remind me at\/on&#8221; passes the date straight through to the at command, where &#8220;in&#8221; prepends &#8220;now +&#8221; to the request. That&#8217;s it!<\/p>\n<p>The channel has been using the reminder feature more and more. It&#8217;s nice to set a reminder with a long article you&#8217;d like to read, or set a reminder in 2 weeks to write a blog post for the DeadCoderSociety. Socializing reminders is a great way to increase community interaction and raise awareness for interesting information that might otherwise end up on a sticky note in a pocket somewhere.<\/p>\n<p><strong>Bonus<\/strong>:<\/p>\n<p>The other Friday I was talking about payday and one guy had added a reminder to &#8220;GET PAID&#8221; for the next set of pairs of weeks. We ended up adding this on the command-line:<\/p>\n<pre lang=\"bash\" escaped=\"true\">for i in `seq 12 2 50`; do\r\n    echo 'echo \"GET PAID\" &gt; \/srv\/git\/neilforobot\/say\/#dcs@paid' | \r\n    at now + $i weeks ; \r\ndone<\/pre>\n<p>At makes setting these types of reminders up easy!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You can use IRC to remind you to do anything. Use the Linux at command.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_links_to":"","_links_to_target":""},"categories":[4],"tags":[38,31,37,28,36,17],"aioseo_notices":[],"_links":{"self":[{"href":"http:\/\/www.deadcodersociety.org\/blog\/wp-json\/wp\/v2\/posts\/525"}],"collection":[{"href":"http:\/\/www.deadcodersociety.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.deadcodersociety.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.deadcodersociety.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.deadcodersociety.org\/blog\/wp-json\/wp\/v2\/comments?post=525"}],"version-history":[{"count":13,"href":"http:\/\/www.deadcodersociety.org\/blog\/wp-json\/wp\/v2\/posts\/525\/revisions"}],"predecessor-version":[{"id":538,"href":"http:\/\/www.deadcodersociety.org\/blog\/wp-json\/wp\/v2\/posts\/525\/revisions\/538"}],"wp:attachment":[{"href":"http:\/\/www.deadcodersociety.org\/blog\/wp-json\/wp\/v2\/media?parent=525"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.deadcodersociety.org\/blog\/wp-json\/wp\/v2\/categories?post=525"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.deadcodersociety.org\/blog\/wp-json\/wp\/v2\/tags?post=525"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}