{"id":13231,"date":"2019-04-01T08:47:50","date_gmt":"2019-04-01T08:47:50","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=13231"},"modified":"2019-04-01T08:47:50","modified_gmt":"2019-04-01T08:47:50","slug":"ntfy-get-desktop-or-phone-alerts-when-long-running-command-finishes","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/01\/ntfy-get-desktop-or-phone-alerts-when-long-running-command-finishes\/","title":{"rendered":"Ntfy \u2013 Get Desktop or Phone Alerts When Long Running Command Finishes"},"content":{"rendered":"<p><strong>Ntfy<\/strong>\u00a0is a simple yet serviceable cross-platform Python utility that enables you to automatically get desktop notifications on demand or when long running commands complete. It can as well send push notifications to your phone once a particular command completes.<\/p>\n<p>It supports shell integration with\u00a0<a href=\"https:\/\/www.tecmint.com\/different-types-of-linux-shells\/\" target=\"_blank\" rel=\"noopener\">popular Linux shells<\/a>\u00a0such as\u00a0<strong>bash<\/strong>\u00a0and\u00a0<strong>zsh<\/strong>; by default,\u00a0<strong>ntfy<\/strong>\u00a0will only send notifications for commands lasting longer than 10 seconds and if the terminal is focused. It also offers features for process, emjoi, XMPP, Telegram, Instapush and Slack notification support.<\/p>\n<p>Check out the following video that demonstrates some of ntfy functionality:<\/p>\n<p><center><img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/dschep\/ntfy\/master\/docs\/demo.gif\" data-lazy-loaded=\"true\" \/><\/center>In this article, we\u2019ll show you how to install, configure and use ntfy in the mainstream Linux distributions to get desktop or phone notifications when long running commands finishes.<\/p>\n<h3>Step 1: How to Install Ntfy in Linux<\/h3>\n<p><strong>Ntfy<\/strong>\u00a0package can be installed using\u00a0<strong>Python Pip<\/strong>\u00a0as follows.<\/p>\n<pre>$ sudo pip install ntfy\r\n<\/pre>\n<p>Once ntfy installed, it can be configured using a YAML file located in\u00a0<code>~\/.ntfy.yml<\/code>\u00a0or in standard platform specific locations,\u00a0<code>~\/config\/ntfy\/ntfy.yml<\/code>\u00a0on Linux.<\/p>\n<p>It operates via dbus, and works on most if not all popular Linux desktop environments such as Gnome, KDE, XFCE and with libnotify. Make sure you have required dependencies installed before using it as shown.<\/p>\n<pre>$ sudo apt-get install libdbus-glib-1-dev libdbus-1-dev [On Debian\/Ubuntu]\r\n$ sudo yum install dbus-1-glib-devel libdbus-1-devel    [On Fedora\/CentOS]\r\n$ pip install --user dbus-python\r\n<\/pre>\n<h3>Step 2: Integrate Ntfy with Linux Shells<\/h3>\n<p>ntfy offers support for spontaneously sending notifications once long running commands complete in bash and zsh. In bash, it reproduces the function of zsh\u2019s preexec and precmd functionality using rcaloras\/bash-preexec.<\/p>\n<p>You can enable it in your\u00a0<code>.bashrc<\/code>\u00a0or\u00a0<code>.zshrc<\/code>\u00a0file as below:<\/p>\n<pre>eval  \"$(ntfy shell-integration)\"\r\n<\/pre>\n<p>After integrating it with the shell, nfty will send notifications on your desktop for any commands lasting longer than 10 seconds provided the terminal is focused, this is the default setting.<\/p>\n<p>Note that terminal focus works on X11 and with Terminal.app. You can configure it via the\u00a0<code>--longer-than<\/code>\u00a0and\u00a0<code>--foreground-too<\/code>\u00a0flags.<\/p>\n<h4>Ignore Unnecessary Notifications<\/h4>\n<p>Imaginably, you can do away with unnecessary notifications when running interactive programs, this can be configured using the\u00a0<strong>AUTO_NTFY_DONE_IGNORE<\/strong>\u00a0env variable.<\/p>\n<p>For instance, using the\u00a0<strong>export<\/strong>\u00a0command below, you will prevent the command \u201c<strong>vim screen meld<\/strong>\u201d from generating notifications:<\/p>\n<pre>$ export AUTO_NTFY_DONE_IGNORE=\"vim screen meld\"\r\n<\/pre>\n<h3>Step 3: How to Use Nfty in Linux<\/h3>\n<p>Once you have installed and configured ntfy, you can test it with a these examples:<\/p>\n<pre>$ ntfy send \"This is TecMint, we\u2019re testing ntfy\"\r\n<\/pre>\n<div id=\"attachment_25219\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/03\/Ntfy-Send-Notification-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-25219\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/03\/Ntfy-Send-Notification-1.png\" alt=\"Ntfy Send Notification \" width=\"640\" height=\"480\" aria-describedby=\"caption-attachment-25219\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-25219\" class=\"wp-caption-text\">Ntfy Send Notification<\/p>\n<\/div>\n<p>The example below shows how to run a command and send a notification when it is done:<\/p>\n<pre>$ ntfy done sleep 5\r\n<\/pre>\n<div id=\"attachment_25220\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/03\/Ntfy-Send-Notification-2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-25220\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/03\/Ntfy-Send-Notification-2.png\" alt=\"Ntfy Auto Send Notification\" width=\"640\" height=\"480\" aria-describedby=\"caption-attachment-25220\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-25220\" class=\"wp-caption-text\">Ntfy Auto Send Notification<\/p>\n<\/div>\n<p>To use a custom notification title, set the\u00a0<code>-t<\/code>\u00a0flag as follows.<\/p>\n<pre>$ ntfy -t 'TecMint' send \"Using custom notification title\"\r\n<\/pre>\n<div id=\"attachment_25221\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/03\/using-custom-notif-title.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-25221\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/03\/using-custom-notif-title.png\" alt=\"Ntfy Custom Notification Title\" width=\"640\" height=\"480\" aria-describedby=\"caption-attachment-25221\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-25221\" class=\"wp-caption-text\">Ntfy Custom Notification Title<\/p>\n<\/div>\n<p>The example below will show an emoji for the particular code used.<\/p>\n<pre>$ ntfy send \":wink: Using emoji extra! :joy:\" \r\n<\/pre>\n<div id=\"attachment_25222\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/03\/using-emoji-extra.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-25222\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/03\/using-emoji-extra.png\" alt=\"Ntfy Use Emoji in Notification\" width=\"640\" height=\"480\" aria-describedby=\"caption-attachment-25222\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-25222\" class=\"wp-caption-text\">Ntfy Use Emoji in Notification<\/p>\n<\/div>\n<p>To send a notification to the desktop once a process with the specified ID completes, use the example below:<\/p>\n<pre>$ ntfy done --pid 2099\r\n<\/pre>\n<p>You can view all notifications using notification indicator, run the commands below to install recent notifications indicator.<\/p>\n<pre>$ sudo add-apt-repository ppa:jconti\/recent-notifications\r\n$ sudo apt update &amp;&amp; sudo apt install indicator-notifications\r\n<\/pre>\n<p>When the installation completes, launch the indicator from the Unity Dash, run a few ntfy commands and click on the icon from the panel to view all notifications.<\/p>\n<div id=\"attachment_25223\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/03\/view-all-notifications.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-25223\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/03\/view-all-notifications.png\" alt=\"Ntfy Notifications\" width=\"640\" height=\"480\" aria-describedby=\"caption-attachment-25223\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-25223\" class=\"wp-caption-text\">Ntfy Notifications<\/p>\n<\/div>\n<p>To view a help message, run:<\/p>\n<pre>$ ntfy -h\r\n<\/pre>\n<h3>Step 4: Install Additional Ntfy Features<\/h3>\n<p>You can install additional features but this calls for extra dependencies:<\/p>\n<p><strong>ntfy done -p $PID<\/strong>\u00a0\u2013 requires installing as\u00a0<strong>ntfy[pid]<\/strong>.<\/p>\n<pre>$ pip install ntfy[pid]\r\n<\/pre>\n<p><strong>emjoi support<\/strong>\u00a0\u2013 requires installing as\u00a0<strong>ntfy[emoji]<\/strong>.<\/p>\n<pre>$ pip install ntfy[emoji]\r\n<\/pre>\n<p><strong>XMPP support<\/strong>\u00a0\u2013 requires installing as\u00a0<strong>ntfy[xmpp]<\/strong>.<\/p>\n<pre>$ pip install ntfy[xmpp]\r\n<\/pre>\n<p><strong>Telegram support<\/strong>\u00a0\u2013 requires installing as\u00a0<strong>ntfy[telegram]<\/strong>.<\/p>\n<pre>$ pip install ntfy[telegram]\r\n<\/pre>\n<p><strong>Instapush support<\/strong>\u00a0\u2013 requires installing as\u00a0<strong>ntfy[instapush]<\/strong>.<\/p>\n<pre>$ pip install ntfy[instapush]\r\n<\/pre>\n<p><strong>Slack support<\/strong>\u00a0\u2013 requires installing as\u00a0<strong>ntfy[slack]<\/strong>.<\/p>\n<pre>$ pip install ntfy[slack]\r\n<\/pre>\n<p>And to install multiple extra features using a single command, separate them with commas like so:<\/p>\n<pre>$ pip install ntfy[pid,emjoi,xmpp, telegram]\r\n<\/pre>\n<p>For an exhaustive usage guide, check out:\u00a0<a href=\"https:\/\/ntfy.readthedocs.io\/en\/latest\/\" target=\"_blank\" rel=\"nofollow noopener\">http:\/\/ntfy.readthedocs.io\/en\/latest\/<\/a><\/p>\n<p>That\u2019s all! In this article, we showed you how to setup and use ntfy in the mainstream Linux distributions. Use the feedback form below to share your thoughts concerning this article or else share with us info about any similar Linux utilities.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/ntfy-get-desktop-or-phone-alerts-for-linux-commands\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ntfy\u00a0is a simple yet serviceable cross-platform Python utility that enables you to automatically get desktop notifications on demand or when long running commands complete. It can as well send push notifications to your phone once a particular command completes. It supports shell integration with\u00a0popular Linux shells\u00a0such as\u00a0bash\u00a0and\u00a0zsh; by default,\u00a0ntfy\u00a0will only send notifications for commands lasting &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/01\/ntfy-get-desktop-or-phone-alerts-when-long-running-command-finishes\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Ntfy \u2013 Get Desktop or Phone Alerts When Long Running Command Finishes&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-13231","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13231","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=13231"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13231\/revisions"}],"predecessor-version":[{"id":13232,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13231\/revisions\/13232"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=13231"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=13231"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=13231"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}