{"id":8604,"date":"2022-02-19T13:14:55","date_gmt":"2022-02-19T18:14:55","guid":{"rendered":"https:\/\/www.rushworth.us\/lisa\/?p=8604"},"modified":"2022-02-22T23:48:51","modified_gmt":"2022-02-23T04:48:51","slug":"useful-bash-commands","status":"publish","type":"post","link":"https:\/\/www.rushworth.us\/lisa\/?p=8604","title":{"rendered":"Useful Bash Commands"},"content":{"rendered":"<h1 id=\"HelpfulShellCommands-ViewingLogFiles\">Viewing Log Files<\/h1>\n<h2 id=\"HelpfulShellCommands-TailingtheFile\">Tailing the File<\/h2>\n<p>When the same file name is used when logs are rotated (i.e. app.log is renamed to app.yyyymmdd.log and a new app.log is created), use the -F flag to follow the <em>name<\/em> instead of the file descriptor<\/p>\n<pre>tail -F \/var\/log\/app.log<\/pre>\n<h2 id=\"HelpfulShellCommands-TailingwithFiltering\">Tailing with Filtering<\/h2>\n<p>When you are looking for something specific in the log file, it often helps to run the log output through grep. This example watches a sendmail log for communication with the host 10.5.5.5<\/p>\n<pre>tail -F \/var\/log\/maillog | grep \"10.5.5.5\"<\/pre>\n<h2 id=\"HelpfulShellCommands-HandlingLogFileswithDateSpecificNaming\">Handling Log Files with Date Specific Naming<\/h2>\n<p>I alias out commands for viewing commonly read log files. This is easy enough when the current log file is always \/var\/log\/application\/content.log, but some <em>active<\/em> log files have date components in the file name. As an example, our Postgresql servers have the short day-of-week string in the log. Use command substitution to get the date-specific elements from the date executable. Here, I tail a file named postgresql-Tue.log on Tuesday. Since logs rotate to a new name, tail -F doesn&#8217;t really <em>do<\/em> anything. You&#8217;ll still need to ctrl-c the tail and restart it for the next day.<\/p>\n<pre>tail -f \/pgdata\/log\/postgresql-$(date +%a).log<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Viewing Log Files Tailing the File When the same file name is used when logs are rotated (i.e. app.log is renamed to app.yyyymmdd.log and a new app.log is created), use the -F flag to follow the name instead of the file descriptor tail -F \/var\/log\/app.log Tailing with Filtering When you are looking for something specific &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30],"tags":[632,294,1188],"class_list":["post-8604","post","type-post","status-publish","format-standard","hentry","category-system-administration","tag-bash","tag-linux","tag-shell"],"_links":{"self":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/8604","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8604"}],"version-history":[{"count":2,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/8604\/revisions"}],"predecessor-version":[{"id":8617,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/8604\/revisions\/8617"}],"wp:attachment":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8604"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8604"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8604"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}