{"data":{"markdownRemark":{"html":"<h3 id=\"in-this-tutorial-id-like-to-try-something-a-little-different-lets-write-a-script-together\"><a href=\"#in-this-tutorial-id-like-to-try-something-a-little-different-lets-write-a-script-together\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>In this tutorial I'd like to try something a little different, lets write a script together</h3>\n<blockquote>\n<p>👍 Normally I would never advocate copying and pasting anything directly from a website to your computer, but if you wish to copy and paste the lines from here, then it's your choice. I haven't hidden any nasty code anywhere, and I will explain every line of the script as we go along, so you know that nothing freaky will happen when you run my/our/your code on your system.</p>\n</blockquote>\n<p>So lets get to it,</p>\n<p>This will be a Linux bash script, so you can write this script in any linux based text editor you like, I will be using one called Vim but gedit will be fine</p>\n<p>So first we need a file, lets create a file called \"get<em>user</em>info.sh\" in your home directory</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"> cd ~ ; touch get_user_info.sh</code></pre></div>\n<ul>\n<li><code class=\"language-text\">cd ~</code> takes you to your home directory</li>\n<li><code class=\"language-text\">touch</code> is a command used to create files, in this case, get<em>user</em>info.sh</li>\n</ul>\n<p>ok, so now we have our file, just one more step and we can start editing it. We need to make the script 'executable', that is to say that we can 'execute/run' our script, to do that, do the following</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">chmod u+x ./get_user_info.sh</code></pre></div>\n<p>This will \"change the mode\" of our script to <code class=\"language-text\">+x</code> be e<strong>x</strong>ecutable.</p>\n<p>to check we have the desired results, try this command,</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">ls -l ./get_user_info.sh\n\noutput:\n-rwxr--r-- 1 sean 1049089 0 Aug  3 22:53 get_user_info.sh</code></pre></div>\n<p>The whole output is unimportant for this tutorial all that matters is that you have a little 'x' here:  -rw<strong>x</strong>r--r--</p>\n<p>if yes, then lets get scripting!</p>\n<h3 id=\"lets-do-it\"><a href=\"#lets-do-it\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Lets do it!</h3>\n<p>Ok so, our script will collect as much information about the current user (you) as possible, and output it to the screen... in a neat and tidy way, sounds like a good first project.</p>\n<p>lets open up the file, and as with all bash scripts the first line should look exactly like this,</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">#!/bin/bash</code></pre></div>\n<p>Lets not get into why just now, but just know, if youre creating a bash script, this should always be your first line! nothing more nothing less..\njust remember ... \"hash-bang/bin/bash\"</p>\n<p>TODO finish this tutorial</p>","timeToRead":2,"excerpt":"In this tutorial I'd like to try something a little different, lets write a script together 👍 Normally I would never advocate copying and…","frontmatter":{"title":"Lets create a script to get all user information, together","cover":"https://picsum.photos/id/41/2500/1000","date":"2019-06-03","category":"sysadmin","tags":["Sysadmin","Medium","Linux","Scripting"],"author":"Endless"},"fields":{"slug":"/lets-create-a-script-to-get-all-user-information-together"}},"prev":{"excerpt":"If you regularly work with the same files and tabs open in Vim, Sessions could be your new best friend 📣 For…","frontmatter":{"title":"How to work with Sessions in Vim","cover":"https://picsum.photos/id/145/2500/1000","date":"2019-07-04"},"fields":{"slug":"/how-to-work-with-sessions-in-vim"}},"next":{"excerpt":"After changes to the NTP configuration file (usually ntp.conf) the NTP service needs to be restarted. Lets find…","frontmatter":{"title":"How to restart Linux NTPD service","cover":"https://picsum.photos/id/357/2500/1000","date":"2019-05-02"},"fields":{"slug":"/how-to-restart-linux-ntpd-service"}},"authors":{"edges":[{"node":{"uid":"Endless","name":"Endless","image":"https://api.adorable.io/avatars/285/pwpwpw.png","url":"https://github.com/RH-sdavey/sean-will-help-you","bio":"Endless Will Help You"}},{"node":{"uid":"Weez","name":"Salloweezy","image":"https://api.adorable.io/avatars/124/weezzzy.png","url":"http://gatsbyjs.org/","bio":"."}},{"node":{"uid":"Sean","name":"Sean","image":"https://api.adorable.io/avatars/124/weez.png","url":"https://github.com/RH-sdavey/sean-will-help-you","bio":"SEAN User created for SWHY"}},{"node":{"uid":"casper","name":"Casper User","image":"https://api.adorable.io/avatars/124/seasz.png","url":"http://gatsbyjs.org/","bio":"Yeah, I like animals better than people sometimes... Especially dogs. Dogs are the best. Every time you come home, they act like they haven't seen you in a year. And the good thing about dogs... is they got different dogs for different people."}},{"node":{"uid":"guinevere","name":"Guinevere Kuiper","image":"https://api.adorable.io/avatars/282/seaszss.png","url":"https://randomuser.me/api/?seed=user1","bio":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam laoreet lorem nec ligula aliquet, porta blandit augue luctus. Vivamus ac quam diam. Sed vestibulum pharetra hendrerit."}}]}},"pageContext":{"slug":"/lets-create-a-script-to-get-all-user-information-together","total":12,"prev":"/how-to-work-with-sessions-in-vim","next":"/how-to-restart-linux-ntpd-service"}}