{"id":702,"date":"2013-07-30T19:38:39","date_gmt":"2013-07-30T19:38:39","guid":{"rendered":"http:\/\/scunster.co.uk\/?p=702"},"modified":"2013-10-26T18:51:07","modified_gmt":"2013-10-26T18:51:07","slug":"silence-bash-command-output-or-change-it-to-something-custom","status":"publish","type":"post","link":"https:\/\/scunster.co.uk\/?p=702","title":{"rendered":"Silence bash command output or change it to something custom"},"content":{"rendered":"<p>You may find that when running commands through bash or scripts that you want to silence or even change their default output to suit your needs.<\/p>\n<p>The easiest way to silence the output of a command is to add &gt; \/dev\/null<\/p>\n<p>Assuming that mysql is running on the system in question (This will also work for any running process)<\/p>\n<pre>pgrep mysql\r\n1046<\/pre>\n<p>To silence the output you would do this:<\/p>\n<pre>pgrep mysql &gt; \/dev\/null<\/pre>\n<p>To change the output you could place it inside an if statement and call it from a script.<\/p>\n<p>Save the following as mysqlrunning.sh and run it!<\/p>\n<pre>if pgrep mysql; \/dev\/nul <span style=\"color: #008000;\">#checks if process mysql is running and silences the output<\/span>\r\nthen <span style=\"color: #008000;\">#If it is running do what ever is on the line underneath<\/span>\r\necho MySQL is running normally <span style=\"color: #008000;\">#In this case display the following message<\/span>\r\nexit <span style=\"color: #008000;\">#Now Quit<\/span>\r\nelse <span style=\"color: #008000;\">#If no process with the name mysql is running then do the line beneath\r\n<\/span>echo MySQL is not running AAARGGGHHHH! <span style=\"color: #008000;\">#Display this message!<\/span>\r\nfi <span style=\"color: #008000;\">#END<\/span><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>You may find that when running commands through bash or scripts that you want to silence or even change their default output to suit your needs. The easiest way to silence the output of a command is to add &gt; \/dev\/null Assuming that mysql is running on the system in question (This will also work [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-702","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/scunster.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/702","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/scunster.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/scunster.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/scunster.co.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/scunster.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=702"}],"version-history":[{"count":13,"href":"https:\/\/scunster.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/702\/revisions"}],"predecessor-version":[{"id":825,"href":"https:\/\/scunster.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/702\/revisions\/825"}],"wp:attachment":[{"href":"https:\/\/scunster.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=702"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/scunster.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=702"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/scunster.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=702"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}