{"id":280,"date":"2011-09-21T16:48:21","date_gmt":"2011-09-21T16:48:21","guid":{"rendered":"http:\/\/www.pasko.net\/wordpress\/?p=280"},"modified":"2011-09-21T16:48:21","modified_gmt":"2011-09-21T16:48:21","slug":"applied-laziness-bash-functions-to-make-you-a-better-lazier-sysadmin","status":"publish","type":"post","link":"https:\/\/www.pasko.net\/wordpress\/2011\/09\/21\/applied-laziness-bash-functions-to-make-you-a-better-lazier-sysadmin\/","title":{"rendered":"Applied Laziness, bash functions to make you a better lazier sysadmin"},"content":{"rendered":"<p id=\"top\" \/>As a good sysadmin, you are probably in the good habit of making a backup copy of critical system files before editing them.<\/p>\n<p>But, as a good sysadmin, you are probably confident enough to occasionally skip the above step.<\/p>\n<p>With a few bash functions and an alias or two stuffed in your .bashrc, doing the right thing can be seamless and alleviate the worry about having to\u00a0retrieve\u00a0backup tapes in a timely fashion.<\/p>\n<p>Bash function I use daily.<\/p>\n<p>&nbsp;<\/p>\n<pre>function back_file\n{\n        echo \"Working on $1\"\n        if [ ! -f $1 ];then\n                echo \"$1 doesn't exist\"\n        fi\n        export ndate=`date  +%m-%d-%y-%H:%M`\n        echo    cp $1 $1.$ndate\n        cp $1 $1.$ndate\n}<\/pre>\n<p>Example usage:<\/p>\n<pre>paskoblaster:~: $ touch foo\npaskoblaster:~: $ back_file foo\nWorking on foo\ncp foo foo.09-21-11-10:42<\/pre>\n<p>This alone is a timesaver, but when combined with an another bash function, I get good things for few keystrokes, and an easy back out plan should I fat-finger or typo the change.<\/p>\n<pre>function bvi\n{\n if [ ! -f $1 ]\n then\n        echo \"must enter file to edit\"\n        return\n fi\n back_file $1\n resize\n vi $1\n\n}<\/pre>\n<p>with the keystrokes:<\/p>\n<p><strong>bvi foo<\/strong><\/p>\n<p>The function makes a backup copy, resizes the terminal window and runs vi on the file.<\/p>\n<p>All in all, a huge time saver which supports good sysadmin karma.<\/p>\n<p>Season to taste, your mileage may vary.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As a good sysadmin, you are probably in the good habit of making a backup copy of critical system files before editing them. But, as a good sysadmin, you are probably confident enough to occasionally skip the above step. With &hellip; <a href=\"https:\/\/www.pasko.net\/wordpress\/2011\/09\/21\/applied-laziness-bash-functions-to-make-you-a-better-lazier-sysadmin\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[6,7,1],"tags":[],"class_list":["post-280","post","type-post","status-publish","format-standard","hentry","category-nerd","category-solaris","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.pasko.net\/wordpress\/wp-json\/wp\/v2\/posts\/280","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pasko.net\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pasko.net\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pasko.net\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pasko.net\/wordpress\/wp-json\/wp\/v2\/comments?post=280"}],"version-history":[{"count":0,"href":"https:\/\/www.pasko.net\/wordpress\/wp-json\/wp\/v2\/posts\/280\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.pasko.net\/wordpress\/wp-json\/wp\/v2\/media?parent=280"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pasko.net\/wordpress\/wp-json\/wp\/v2\/categories?post=280"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pasko.net\/wordpress\/wp-json\/wp\/v2\/tags?post=280"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}