Instructions to set up a basic LAMP+SSH server environment
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

127 lines
4.6 KiB

5 years ago
  1. Linux servers - Exercice 6
  2. ==============
  3. *Disclaimer:*
  4. --------------
  5. This exercise is a part of [Linux servers (ICT4TN021, spring 2018) // Linux-palvelimet (ICT4TN021, kevät 2018)](http://www.haaga-helia.fi/fi/opinto-opas/opintojaksokuvaukset/ICT4TN021) school course organized as a part of Information Technology studies in Haaga-Helia university of Applied Sciences, Helsinki, Finland. Course lecturer [Tero Karvinen](http://terokarvinen.com/) has defined the original assignment descriptions in Finnish presented in this document in English. Answers and translations have been written by Pekka Helenius (me, ~ Fincer).
  6. **a)** Write and execute "Hello world" in three code languages of your choice. Set up a necessary development environments.
  7. --------------
  8. **Answer:**
  9. Let's write "Hello World" in the following three languages: perl, python 3 and C. Let's install needed development tools:
  10. ```
  11. sudo apt-get -y install perl python gcc
  12. ```
  13. (GCC = [Gnu Compiler Collection](https://gcc.gnu.org/) + [Wikipedia](https://en.wikipedia.org/wiki/GNU_Compiler_Collection))
  14. Let's write the codes into a subfolder _hello-world_ in user's home dir:
  15. ```
  16. [newuser@goauldhost: ~ ]$ mkdir ~/hello-world
  17. [newuser@goauldhost: ~ ]$ cd hello-world/
  18. [newuser@goauldhost: hello-world ]$ touch {hello.py,hello.pl,hello.c}
  19. ```
  20. - hello.py = "Hello World" written in Python 3
  21. - hello.pl = "Hello World" written in Perl
  22. - hello.c = "Hello World" written in C
  23. Hello World program written in three languages (nano editor used):
  24. **Perl (hello.pl):**
  25. ```
  26. #!/usr/bin/env perl
  27. # Declare runtime environment above
  28. # Include these to find common warnings, syntax errors etc in the code
  29. import strict;
  30. import warnings;
  31. # Print Hello World! with a newline
  32. print "Hello World!\n";
  33. ```
  34. **Python (hello.py):**
  35. ```
  36. #!/usr/bin/env python3
  37. # Declare runtime environment above
  38. # Print Hello World!
  39. print("Hello World!");
  40. ```
  41. **NOTE!** Pay attention when referring to python executable. On some Linux distributions, python refers to python2, and on some, python refers to python3. Practices differ. It can be safer to use 'python3' or 'python2' instead of just 'python'.
  42. In a simple program like "Hello world" this python issue doesn't really matter but if any python libraries are imported into the code, you must know which python environment to use, Python 2 or Python 3.
  43. **C (hello.c):**
  44. ```
  45. // Include Standard Input Output Library (stdio.h core library included in)
  46. #include <stdio.h>
  47. // Declare main function for the program. Int for returning a integer
  48. int main()
  49. {
  50. // Print Hello World! (stdout in CLI)
  51. printf("Hello World!");
  52. // Return boolean value "true" to the execution environment
  53. return 0;
  54. }
  55. ```
  56. hello.c requires compiling from source code to executable binary file. Therefore, we compile the source code with the following command in _hello-world_ folder:
  57. ```
  58. gcc -o hello hello.c
  59. ```
  60. after which our 'binary' can be executed with
  61. ```
  62. ~/hello-world/hello
  63. ```
  64. All programs give stdout/output string "Hello World!" in our shell environment:
  65. ```
  66. [newuser@goauldhost: hello-world ]$ pwd
  67. /home/newuser/hello-world
  68. [newuser@goauldhost: ~ ]$ python hello.py
  69. Hello World!
  70. [newuser@goauldhost: ~ ]$ perl hello.pl
  71. Hello World!
  72. [newuser@goauldhost: ~ ]$ ./hello
  73. Hello World!
  74. ```
  75. **b)** (optional) Write a simple program for some practical purpose with each language. Ideas: utilize the key benefits of your language of choice. Take an input value from a user, generate a calculation and print the output (input-processing-layout).
  76. --------------
  77. **Answer:**
  78. This could have been very interesting assignment to work out. Unfortunately, my working laptop was broken so that I was not effectively able to write new code. I have worked with a perl program which generated random port and TCP/UDP sequences for knockd daemon. In addition, I have worked with some updates to Wine Configuration window (winecfg, part of Wine program) in C language:
  79. ![winecfg-update](https://i.imgur.com/SihmPUA.jpg)
  80. Some Python and bash based program-related scripts and code updates are available here:
  81. - [PlayOnLinux patches](https://github.com/Fincer/linux-patches-and-scripts/tree/master/playonlinux).
  82. - Little CMake script targeted for compiling C++ code can be found [here](https://github.com/Fincer/linux-patches-and-scripts/tree/master/xclipshow)
  83. - Some basic scripting to convert videos with ffmpeg in KDE DE: [ffmpeg-fileconversion-video](https://github.com/Fincer/linux-patches-and-scripts/blob/master/kde-servicemenus-multimediatools/ffmpeg-fileconversion-video.sh)
  84. etc.