{"id":134,"date":"2019-01-16T09:42:54","date_gmt":"2019-01-16T05:42:54","guid":{"rendered":"http:\/\/kidds.co.za\/?p=134"},"modified":"2019-01-16T09:46:09","modified_gmt":"2019-01-16T05:46:09","slug":"linux-run-a-command-over-and-over","status":"publish","type":"post","link":"https:\/\/kidds.co.za\/index.php\/2019\/01\/16\/linux-run-a-command-over-and-over\/","title":{"rendered":"Linux run a command over and over"},"content":{"rendered":"\n<p>This is a great way to monitor a directory for changes every 5 seconds as an example, or monitor a large files changing size as you move it from one server to another.<\/p>\n\n\n\n<p>the\u00a0<code>watch<\/code>\u00a0command.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Usage: watch [-dhntv] [--differences[=cumulative]] [--help] [--interval=&lt;n>] \n             [--no-title] [--version] &lt;command>`\n<\/code><\/pre>\n\n\n\n<p>So that:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>watch -n1  command\n<\/code><\/pre>\n\n\n\n<p>will run the command every second (well, technically, every one second plus the time it takes for&nbsp;<code>command<\/code>&nbsp;to run as&nbsp;<code>watch<\/code>&nbsp;(at least the&nbsp;<code>procps<\/code>&nbsp;and&nbsp;<code>busybox<\/code>&nbsp;implementations) just sleeps one second in between two runs of&nbsp;<code>command<\/code>), forever.<\/p>\n\n\n\n<p>Would you want to pass the command to&nbsp;<code>exec<\/code>&nbsp;instead of&nbsp;<code>sh -c<\/code>, use&nbsp;<code>-x<\/code>&nbsp;option:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>watch -n1 -x command<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This is a great way to monitor a directory for changes every 5 seconds as an example, or monitor a large files changing size as you move it from one server to another. the\u00a0watch\u00a0command. So that: will run the command every second (well, technically, every one second plus the time it takes for&nbsp;command&nbsp;to run as&nbsp;watch&nbsp;(at [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,2],"tags":[],"class_list":["post-134","post","type-post","status-publish","format-standard","hentry","category-general-commands","category-linux"],"_links":{"self":[{"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/posts\/134","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/comments?post=134"}],"version-history":[{"count":2,"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/posts\/134\/revisions"}],"predecessor-version":[{"id":136,"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/posts\/134\/revisions\/136"}],"wp:attachment":[{"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/media?parent=134"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/categories?post=134"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/tags?post=134"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}