Linux servers ICT4TN021 – H6

In this post I’m reporting Tero Karvinen’s “Linux Palvelimet” assignment 6.[1] Report was started 02.10.2018 @ 12:54 and written from my desktop.

What am I working with?

  • Operating system: Xubuntu-18.04.1 64b[2] (Bootable USB)
  • CPU: Intel I5-6600k @ 3.5GHz
  • GPU: Geforce GTX 1070, 8Gb VRAM
  • RAM: 2x 8Gb DDR4 @ 2667MHz
  • MoBo: Asus Maximus VIII Ranger (boot menu F8)

 

I started by booting my computer using a bootable USB, plugged it in to an open USB slot and pressed F8 during startup. Once the boot menu had opened I selected the the USB-stick that I’m using (in this case Toshiba transmemory 32Gb) and pressed enter. This led me to xubuntu’s GRUB, where i chose “Xubuntu toram noprompt” -option that I had created earlier in the course.

Once my computer had loaded I tested it by opening the web browser, which seemed to work normally. After testing that web browser worked normally; I switched the timezone to Europe/Helsinki and had some display settings done. After getting all the personal preference settings done I switched my keyboard layout to scandinavian and updated the repository packages with:

setxkbmap fi
sudo apt-get update

The computer was now ready to be used and all it took was around 5 minutes in total. It was time to move to the given assignments.

Assignment A)

Write and run a “Hey world” script in three different languages (coding languages like python or php) and download the required working environments.[1]

Assignment started at 13:21.

Python3

I started by opening xubuntu terminal with ctrl + alt + del and creating a python file called 21.py. I did all this by typing:

nano 21.py

to create the python script I am using.

I wrote the following inside the script called 21.py:

print("Hello world")

screenshot_2018-10-02_10-30-06.png

And i ran the script by giving the following command in terminal:

python3 21.py

Which printed:

screenshot_2018-10-02_10-29-29.png

I also created a directory called scripts and moved the 21.py script there. By giving the following commands in terminal:

mkdir scripts
mv 21.py scripts/

screenshot_2018-10-02_10-36-47.png

BASH

I decided that the 2nd language I would use was going to be bash. I started with creating a .sh script by typing:

 nano hello.sh

I wrote a simple Hello world script that the hello.sh would have to run:

echo Hello world

screenshot_2018-10-02_12-09-21.png

I ran the script by typing:

bash hello.sh

to the terminal and it obviously printed “Hello world”

screenshot_2018-10-02_12-10-58.png

RUBY

I decided to use Ruby as the last language, since I’m interested in learning it and have no prior knowledge of it.

(I only used Tero’s guide[3] for this ruby part, since I had some prior knowledge for the other scripts.)

I started by downloading ruby with the following command:

sudo apt-get -y install ruby

Then i followed Tero’s guide[3] and created a ruby file called hello.rb:

nano hello.rb

And wrote the following inside it:

print ("Hello World\n")

screenshot_2018-10-02_12-06-51.png

Then I ran the script with ruby by typing the following in to terminal:

ruby hello.rb

And it printed “Hello world” so it seemed to be working fine.

screenshot_2018-10-02_12-14-43.png

This assingment took around ~15 minutes of actual working time. This report itself took a bit longer since I had to run some personal errands in between. First assignment and its reporting was done @ clk. 15:15.

Assignment B)

(Optional) Write a simple (input-processing-output) program using the same languages.[1]

Python

I started by creating a simple input/output script using python3. I only have a little experience using python and I’m going (or atleast trying) to create this script from memory/scratch.

I used the .py file that I had created earlier and edited it a bit:

nano 21.py

And wrote the following inside it:

print("Hello world")

answer = input("What's 9+10")

I started by testing out the actual input part of the script, which I did by giving the following command:

python3 21.py

Screenshot_2018-10-02_12-27-28

The input worked correctly, but I didn’t use it.

This is the final script that I ended up making:

name = input("What's your name? ")

print("Well hello there, "+name)

answer = input("What's 9+10? ")

if answer == '19':

        print ("You smart boi, you very mathematician")

else:

        print ("you stupid, learn to mathematics")

screenshot_2018-10-02_12-51-30.png
(The English that I used in the script is purposefully incorrect as this is a joke)

This is me running the script in terminal and testing that it actually works:

screenshot_2018-10-02_12-55-33.png

I was done with the script @ clk. 15:27

BASH

This is my first time writing an “input-output” script using bash. I used Ryan’s tutorial[4] to make this script and I thought that it would suffice since this is an optional assignment.

echo What are your top5 memes?

This prints “What are your top5 memes?” in to terminal for the user to read.

read mem1 mem2 mem3 mem4 mem5

Read allows user input for the script itself and “mem1 to mem5” are the references that the script is going to print out later.

echo Your top1 meme is: $mem1
echo Your top2 meme is: $mem2
echo Your top3 meme is: $mem3
echo Your top4 meme is: $mem4
echo Your top5 meme is: $mem5

screenshot_2018-10-02_13-53-45.png

Echo prints out “your top5 meme is:” and prints out what the user wrote earlier. Like so:

screenshot_2018-10-02_13-53-40.png

This part didn’t take so long, since the script itself was pretty self explanatory and didn’t require too complicated strings.

RUBY

I used http://zetcode.com/lang/rubytutorial/io/[5] to find this simple tutorial for ruby.

I wrote a super simple input output script using ruby, the script printed out “Hello dude” in terminal and required user’s input using “gets”. The script then called for gets at the end and printed out “Hello + (user input) + How are you?”

print ("Hello dude\n")

puts "Hwat are is yuo'r name? "
name = gets

puts "Hello " + name + "How are you?"

I ran the script by typing:

ruby name.rb

Screenshot_2018-10-02_22-31-54

I have to admit that I used the most simple input/output scripts I could find, but since this was an optional assignment it didn’t really matter. I find that the most important part was for me to learn more than just the basic “Hello world”. But then again I didn’t dig that much deeper in to the language which probably was the idea of this assignment.

All in all I was done @ clk 01:35, since i took some breaks and met a few friends in between working with this report and various scripts.

 

Sources:

[1] Assignment: http://terokarvinen.com/2018/aikataulu-%E2%80%93-linux-palvelimet-ict4tn021-3003-to-8-14-alkusyksy-2018p1-%E2%80%93-5-op

[2] Operating system: http://ftp.lysator.liu.se/ubuntu-dvd/xubuntu/releases/18.04/release/

[3] Tero’s guide: http://terokarvinen.com/2018/hello-python3-bash-c-c-go-lua-ruby-java-programming-languages-on-ubuntu-18-04

[4] Bash simple script tutorial: https://ryanstutorials.net/bash-scripting-tutorial/bash-input.php

[5] Ruby tutorial: http://zetcode.com/lang/rubytutorial/io/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s