├── 0x00-shell_basics ├── .school.mgc.swp ├── 0-current_working_directory ├── 1-listit ├── 10-back ├── 100-lets_move ├── 101-clean_emacs ├── 102-tree ├── 103-commas ├── 11-lists ├── 12-file_type ├── 13-symbolic_link ├── 14-copy_html ├── 2-bring_me_home ├── 3-listfiles ├── 4-listmorefiles ├── 5-listfilesdigitonly ├── 6-firstdirectory ├── 7-movethatfile ├── 8-firstdelete ├── 9-firstdirdeletion ├── README.md ├── my_first_directory └── school.mgc ├── 0x01-shell_permissions ├── .6-multiple_permissions.swp ├── .9-John_Doe.swp ├── 0-iam_betty ├── 1-who_am_i ├── 10-mirror_permissions ├── 100-change_owner_and_group ├── 101-symbolic_link_permissions ├── 102-if_only ├── 103-Star_Wars ├── 11-directories_permissions ├── 12-directory_permissions ├── 13-change_group ├── 2-groups ├── 3-new_owner ├── 4-empty ├── 5-execute ├── 6-multiple_permissions ├── 7-everybody ├── 8-James_Bond ├── 9-John_Doe └── README.md ├── 0x02-shell_redirections ├── 0-hello_world ├── 1-confused_smiley ├── 10-no_more_js ├── 100-empty_casks ├── 101-gifs ├── 102-acrostic ├── 103-the_biggest_fan ├── 11-directories ├── 12-newest_files ├── 13-unique ├── 14-findthatword ├── 15-countthatword ├── 16-whatsnext ├── 17-hidethisword ├── 18-letteronly ├── 19-AZ ├── 2-hellofile ├── 20-hiago ├── 21-reverse ├── 22-users_and_homes ├── 3-twofiles ├── 4-lastlines ├── 5-firstlines ├── 6-third_line ├── 7-file ├── 8-cwd_state ├── 9-duplicate_last_line └── README.md ├── 0x03-shell_variables_expansions ├── 0-alias ├── 1-hello_you ├── 10-love_exponent_breath ├── 100-decimal_to_hexadecimal ├── 101-rot13 ├── 102-odd ├── 103-water_and_stir ├── 11-binary_to_decimal ├── 12-combinations ├── 13-print_float ├── 2-path ├── 3-paths ├── 4-global_variables ├── 5-local_variables ├── 6-create_local_variable ├── 7-create_global_variable ├── 8-true_knowledge ├── 9-divide_and_rule └── README.md ├── 0x04-loops_conditions_and_parsing ├── 0-RSA_public_key.pub ├── 1-for_best_school ├── 10-fizzbuzz ├── 100-read_and_cut ├── 101-tell_the_story_of_passwd ├── 102-lets_parse_apache_logs ├── 103-dig_the-data ├── 2-while_best_school ├── 3-until_best_school ├── 4-if_9_say_hi ├── 5-4_bad_luck_8_is_your_chance ├── 6-superstitious_numbers ├── 7-clock ├── 8-for_ls ├── 9-to_file_or_not_to_file ├── README.md └── apache-access.log ├── 0x05-processes_and_signals ├── 0-what-is-my-pid ├── 1-list_your_processes ├── 100-process_and_pid_file ├── 101-manage_my_process ├── 102-zombie.c ├── 2-show_your_bash_pid ├── 3-show_your_bash_pid_made_easy ├── 4-to_infinity_and_beyond ├── 5-dont_stop_me_now ├── 6-stop_me_if_you_can ├── 67-stop_me_if_you_can ├── 7-highlander ├── 8-beheaded_process ├── README.md └── manage_my_process ├── 0x06-regular_expressions ├── 0-simply_match_school.rb ├── 1-repetition_token_0.rb ├── 100-textme.rb ├── 2-repetition_token_1.rb ├── 3-repetition_token_2.rb ├── 4-repetition_token_3.rb ├── 5-beginning_and_end.rb ├── 6-phone_number.rb ├── 7-OMG_WHY_ARE_YOU_SHOUTING.rb └── README.md ├── 0x07-networking_basics ├── 0-OSI_model ├── 1-types_of_network ├── 2-MAC_and_IP_address ├── 3-UDP_and_TCP ├── 4-TCP_and_UDP_ports ├── 5-is_the_host_on_the_network └── README.md ├── 0x08-networking_basics_2 ├── 0-change_your_home_IP ├── 1-show_attached_IPs ├── 100-port_listening_on_localhost └── README.md ├── 0x09-web_infrastructure_design ├── 0-simple_web_stack ├── 1-distributed_web_infrastructure ├── 2-secured_and_monitored_web_infrastructure ├── 3-scale_up └── README.md ├── 0x0A-configuration_management ├── 0-create_a_file.pp ├── 1-install_a_package.pp ├── 2-execute_a_command.pp ├── README.md └── killmenow ├── 0x0B-ssh ├── 0-use_a_private_key ├── 1-create_ssh_key_pair ├── 100-puppet_ssh_config.pp ├── 2-ssh_config └── README.md ├── 0x0C-web_server ├── 0-transfer_file ├── 1-install_nginx_web_server ├── 2-setup_a_domain_name ├── 3-redirection ├── 4-not_found_page_404 ├── 7-puppet_install_nginx_web_server.pp ├── README.md └── fabfile.py ├── 0x0D-web_stack_debugging_0 ├── 0-give_me_a_page └── README.md ├── 0x0E-web_stack_debugging_1 ├── 0-nginx_likes_port_80 ├── 1-debugging_made_short └── README.md ├── 0x0F-load_balancer ├── 0-custom_http_response-header ├── 1-install_load_balancer ├── 2-puppet_custom_http_response-header.pp └── README.md ├── 0x10-https_ssl ├── 0-world_wide_web ├── 1-haproxy_ssl_termination ├── 100-redirect_http_to_https └── README.md ├── 0x11-what_happens_when_your_type_google_com_in_your_browser_and_press_enter ├── 0-blog_post ├── 1-what_happen_when_diagram ├── 2-contribution-to_what-happens-when_github_answer └── README.md ├── 0x12-web_stack_debugging_2 ├── 0-iamsomeonelese ├── 1-run_nginx_as_nginx ├── 100-fix_in_7_lines_or_less └── README.md ├── 0x13-firewall ├── 0-block_all_incoming_traffic_but ├── 100-port_forwarding └── README.md ├── 0x14-mysql ├── 4-mysql_configuration_primary ├── 4-mysql_configuration_replica ├── 5-mysql_backup └── README.md ├── 0x15-api ├── 0-gather_data_from_an_API.py ├── 1-export_to_CSV.py ├── 2-export_to_JSON.py ├── 3-dictionary_of_list_of_dictionaries.py └── README.md ├── 0x16-api_advanced ├── 0-subs.py ├── 1-top_ten.py ├── 100-count.py ├── 2-recurse.py ├── README.md └── tests │ ├── 0-main.py │ ├── 1-main.py │ ├── 100-main.py │ └── 2-main.py ├── 0x17-web_stack_debugging_3 ├── 0-strace_is_your_friend.pp └── README.md ├── 0x18-webstack_monitoring ├── 0-setup_datadog ├── 2-setup_datadog └── README.md ├── 0x1A-application_server ├── 2-app_server-nginx_config ├── 3-app_server-nginx_config ├── 4-app_server-nginx_config ├── 4-reload_gunicorn_no_downtime ├── 5-app_server-nginx_config ├── README.md └── gunicorn.conf ├── 0x1B-web_stack_debugging_4 ├── 0-the_sky_is_the_limit_not.pp ├── 1-user_limit.pp └── README.md ├── README.md └── command_line_for_the_win ├── 0-first_9_tasks.jpg ├── 1-next_9_tasks.jpg ├── 2-next_9_tasks.jpg └── README.md /0x00-shell_basics/.school.mgc.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lordwill1/alx-system_engineering-devops/b7aabfb4db4157146b2e329278d9e2390865d57d/0x00-shell_basics/.school.mgc.swp -------------------------------------------------------------------------------- /0x00-shell_basics/0-current_working_directory: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | pwd 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/1-listit: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ls 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/10-back: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd - 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/100-lets_move: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | mv [[:upper:]]* /tmp/u 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/101-clean_emacs: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | rm *~ 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/102-tree: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | mkdir -p welcome/to/school 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/103-commas: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ls -map 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/11-lists: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ls -al . .. /boot 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/12-file_type: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | file /tmp/iamafile 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/13-symbolic_link: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ln -s /bin/ls __ls__ 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/14-copy_html: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cp -r -u *.html .. 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/2-bring_me_home: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd /root 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/3-listfiles: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ls -l 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/4-listmorefiles: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ls -la 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/5-listfilesdigitonly: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ls -an 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/6-firstdirectory: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | mkdir /tmp/my_first_directory/ 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/7-movethatfile: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | mv /tmp/betty /tmp/my_first_directory/ 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/8-firstdelete: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | rm -r /tmp/my_first_directory/betty 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/9-firstdirdeletion: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | rm -r /tmp/my_first_directory 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/README.md: -------------------------------------------------------------------------------- 1 | [ALX COHORT]![image](https://user-images.githubusercontent.com/105258746/187828479-63082744-4c64-4bac-9f56-e32bae98a9a9.png) 2 | 3 | # SHELL, BASICS BASH PROJECTS 4 | 5 | ## TASKS 6 | 7 | ### Note: When doing this project, After using text editor of your choice to create and access the file on insert mode.Ensure the first line is always having # !/bin/bash, then the second line is having the correct command/answer. 8 | (From your terminal, convert the file created to `SCRIPT` i.e: cdmod u+x 1-listit) 9 | 10 | ## 0. Write a script that prints the absolute path name of the current working directory. 11 | ### File: 0-current_working_directory 12 | ``input: pwd`` *(print working directory)* 13 | 14 | ## 1. Display the contents list of your current directory. 15 | ### File: 1-listit 16 | ``input: ls`` *(list directory contents)* 17 | 18 | ## 2. Write a script that changes the working directory to the user’s home directory. 19 | ### File: 2-bring_me_home 20 | ``input: cd`` *(change directory)* 21 | 22 | ## 3. Display current directory contents in a long format. 23 | ### File: 3-listfiles 24 | ``input: ls -l`` *(list directory contents in long form)* 25 | 26 | ## 4. Display current directory contents, including hidden files (starting with .). Use the long format. 27 | ### File: 4-listmorefiles 28 | ``input: ls -la`` *(list directory contents in long form, including hidden files)* 29 | 30 | ## 5. Display current directory contents. 31 | ### File: 5-listfilesdigitonly 32 | ``input: ls -la`` *(Note: Are files inherently ordered?)* 33 | 34 | ## 6. Create a script that creates a directory named my_first_directory in the /tmp/ directory. 35 | ### File: 6-firstdirectory 36 | ``input: mkdir /tmp/my_first_directory`` *(Create a holberton directory inside the tmp directory)* 37 | 38 | ## 7. Move the file betty from /tmp/ to /tmp/my_first_directory. 39 | ### File: 7-movethatfile 40 | ``input: mv /tmp/betty /tmp/my_first_directory/betty`` *(Move file betty, which is located inside the tmp directory, to the holberton directory, which is also located inside the tmp directory. This exercise required some dir traversing.)* 41 | 42 | ## 8. Delete the file betty. 43 | ### File: 8-firstdelete 44 | ``input: rm /tmp/my_first_directory/betty`` *(Remove file betty located in tmp/my_first_directory directory.)* 45 | 46 | ## 9. Delete the directory my_first_directory that is in the /tmp directory.** 47 | ### File: 9-firstdirdeletion 48 | ``input: rmdir /tmp/my_first_directory`` *(Remove directory my_first_directory located in directory tmp.)* 49 | 50 | ## 10. Write a script that changes the working directory to the previous one. 51 | ### File: 10-back 52 | ``input: cd -`` *(Change directory to the previous directory you were in.)* 53 | 54 | ## 11. Write a script that lists all files (even ones with names beginning with a period character, which are normally hidden) in the current directory and the parent of the working directory and the /boot directory (in this order), in long format. 55 | ### File: 11-lists 56 | ``*input: ls -la . .. /boot`` *(List all files/directories, including hidden files/directories, from 3 separate directories: current directory, parent of working directory, and /boot directory. The ls command allows multiple directories to be listed separated by spaces.)* 57 | 58 | ## 12. Write a script that prints the type of the file named iamafile. The file iamafile will be in the /tmp directory when we will run your script. 59 | ### File: 12-file_type 60 | ``input: file /tmp/iamafile`` *(Prints the type of file iamafile.)* 61 | 62 | ## 13. Create a symbolic link to /bin/ls, named __ls__. The symbolic link should be created in the current working directory. 63 | ### File: 13-symbolic_link 64 | ``input: ln -s /bin/ls __ls__`` *(Create a symbolic link named ls for /bin/ls)* 65 | 66 | ## 14. Create a script that copies all the HTML files from the current working directory to the parent of the working directory, but only copy files that did not exist in the parent of the working directory or were newer than the versions in the parent of the working directory. 67 | ### File: 14-copy_html 68 | ``input: cp -u *.html ..`` *(Copy all html files from the current directory to the parent directory, but only copy files that didn't exist in the parent directory or are newer versions than the ones that already exist in the parent directory. The -u option didn't show on the terminal manual page. The -u option copies the file into the directory if its a newer version. If the file doesn't exist in the directory, it will copy over. The -n option works for copying files that don't exist in the parent directory, but it doesn't check if the file is a newer version or not.) 69 | 70 | ## 15. Create a script that moves all files beginning with an uppercase letter to the directory /tmp/u. You can assume that the directory /tmp/u will exist when we will run your script. 71 | ### File: 100-lets_move 72 | ``input: mv [[:upper:]]* /tmp/u`` *(Move all files that begin with a capital letter to /tmp/u)* 73 | 74 | ## 16. Create a script that deletes all files in the current working directory that end with the character ~. 75 | ### File: 101-clean_emacs 76 | ``input: rm *~`` *(Deletes all files in the current directory that end with a ~)* 77 | 78 | ## 17. Create a script that creates the directories welcome/, welcome/to/ and welcome/to/school in the current directory. You are only allowed to use two spaces (and lines) in your script, not more. 79 | ### File: 102-tree 80 | ``input: mkdir -p welcome/to/school`` *(Create directory `welcome` in current directory. Create directory `to` inside directory `welcome`. Create directory `holberton` inside directory `to`. The -p option creates any intermediate directories in the path argument.)* 81 | 82 | ## 18. Write a command that lists all the files and directories of the current directory, separated by commas (,) and hidden directory names(..) should end with a slash (/) 83 | ### File: 103-commas 84 | ``input: ls -map*`` 85 | *(List all files and directories of the current directory, separated by commas. Directory names should end with a `/`. The listing should be alph ordered, except for dot (.) or dot dot (..), which should be listed at the beginning.)* 86 | The -a option is to show any hidden files. 87 | The -p option writes a `/` at the end of directory names. 88 | The -m option streams the output, separating each listing with commas. 89 | 90 | ## 19. Create a magic file school.mgc that can be used with the command file to detect School data files. School data files always contain the string SCHOOL at offset 0. 91 | ### File: school.mgc 92 | ``input 1: 0 string SCHOOL School data`` 93 | 94 | ``input 2: !:mime School`` 95 | 96 | *Then_on_your_terminal_run:* ``file -C -m school.mgc`` 97 | 98 | 99 | Create a magic file called `school.mgc` that can be used with the command `file` to detect `School` data files. Holberton data files always contain "SCHOOL" at offset 0. 100 | 101 | This exercise was much different from the previous exercises. From what I understand, the magic file is used to detect patterns in files and will give a specified output depending on a matching pattern. 102 | The first argument is a number representing the offset. 103 | The second argument is the data type you are searching for. In our case, it is a string. 104 | The third argument is the data you are searching for. In our case, "SCHOOL", which we specified as a string in the second argument. 105 | The fourth argument is the message you want to output on match. If the search matches, it will output this message. 106 | The last argument is separated by a line. Since the fourth argument can be long and contain multiple strings, we separate the fourth and fifth arguments with this new line. This last argument can be multiple different things. In this case, a MIME type. 107 | According to bash manual, a "MIME type is given on a separate line, which must be the next non-blank or comment line after the magic line that identifies the file type". 108 | I knew to search for a MIME type because the example provided: 109 | $ file --mime-type -m school.mgc * 110 | The above returns message "School" when matching a MIME ?? Not exactly sure, but this is what I can tell from what I've tested out and can see from the output and examples. 111 | $ file -m school.mgc * 112 | The above will return message "School data" for any offset 0 "SCHOOL" matches. 113 | A cool thing to note is that the `file` command is compiling and running the magic file. So there is no need to compile to magic "permanently". 114 | NOTE: Compiling a magic source file: 115 | $ file -C -m .mgc 116 | This produces the compiled magic file. 117 | $ file -i -m .mgc * 118 | This allows you to use the compiled file by specifying its name using the -m switch again. 119 | 120 | 121 | 122 | 123 | -------------------------------------------------------------------------------- /0x00-shell_basics/my_first_directory: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | mkdir /tmp/my_first_directory/ 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/school.mgc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lordwill1/alx-system_engineering-devops/b7aabfb4db4157146b2e329278d9e2390865d57d/0x00-shell_basics/school.mgc -------------------------------------------------------------------------------- /0x01-shell_permissions/.6-multiple_permissions.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lordwill1/alx-system_engineering-devops/b7aabfb4db4157146b2e329278d9e2390865d57d/0x01-shell_permissions/.6-multiple_permissions.swp -------------------------------------------------------------------------------- /0x01-shell_permissions/.9-John_Doe.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lordwill1/alx-system_engineering-devops/b7aabfb4db4157146b2e329278d9e2390865d57d/0x01-shell_permissions/.9-John_Doe.swp -------------------------------------------------------------------------------- /0x01-shell_permissions/0-iam_betty: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | su betty 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/1-who_am_i: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | whoami 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/10-mirror_permissions: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chmod --reference=olleh hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/100-change_owner_and_group: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chown vincent:staff * 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/101-symbolic_link_permissions: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chown -h vincent:staff _hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/102-if_only: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chown --from=guillaume betty hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/103-Star_Wars: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | telnet towel.blinkenlights.nl 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/11-directories_permissions: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chmod a+X * 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/12-directory_permissions: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | mkdir -m 751 my_dir 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/13-change_group: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chgrp school hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/2-groups: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | groups 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/3-new_owner: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | sudo chown betty hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/4-empty: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | touch hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/5-execute: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chmod u+x hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/6-multiple_permissions: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chmod ug+x,o+r hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/7-everybody: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chmod a+x hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/8-James_Bond: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chmod 007 hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/9-John_Doe: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chmod 753 hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/README.md: -------------------------------------------------------------------------------- 1 | ![image](https://user-images.githubusercontent.com/105258746/188032422-183595a4-c203-4d44-8f19-e6101f26ed0f.png) 2 | 3 | # 0x01. SHELL, PERMISSIONS PROJECT 4 | 5 | # TASKS: 6 | 7 | ## 0. Create a script that switches the current user to the user `betty`. 8 | ### File: 0-iam_betty 9 | 10 | ## 1. Write a script that prints the effective username of the current user. 11 | ### File: 1-who_am_i 12 | 13 | ## 2. Write a script that prints all the groups the current user is part of. 14 | ### File: 2-groups 15 | 16 | ## 3. Write a script that changes the owner of the file `hello` to the user `betty`. 17 | ### File: 3-new_owner 18 | 19 | ## 4. Write a script that creates an empty file called `hello`. 20 | ### File: 4-empty 21 | 22 | ## 5. Write a script that adds execute permission to the owner of the file `hello`. 23 | ### File: 5-execute 24 | 25 | ## 6. Write a script that adds execute permission to the owner and the group owner, and read permission to other users, to the file `hello`. 26 | ### File: 6-multiple_permissions 27 | 28 | ## 7. Write a script that adds execution permission to the owner, the group owner and the other users, to the file `hello`. 29 | ### File: 7-everybody 30 | 31 | ## 8. Write a script that sets the permission to the file `hello` as follows: 32 | ``Owner: no permission at all`` 33 | ``Group: no permission at all`` 34 | ``Other users: all the permissions`` 35 | ### File: 8-James_Bond 36 | 37 | ## 9. Write a script that sets the mode of the file `hello` to this: `-rwxr-x-wx 1 julien julien 23 Sep 20 14:25 hello` 38 | ### File: 9-John_Doe 39 | 40 | ## 10. Write a script that sets the mode of the file `hello` the same as `olleh’s` mode. 41 | ### File: 10-mirror_permissions 42 | 43 | ## 11. Create a script that adds execute permission to all subdirectories of the current directory for the owner, the group owner and all other users. Regular files should not be changed. 44 | ### File: 11-directories_permissions 45 | 46 | ## 12. Create a script that creates a directory called `my_dir` with permissions `751` in the working directory. 47 | ### File: 12-directory_permissions 48 | 49 | ## 13. Write a script that changes the group owner to `school` for the file `hello` 50 | ### File: 13-change_group 51 | 52 | ## 14. Write a script that changes the owner to `vincent` and the group owner to `staff` for all the files and directories in the working directory. 53 | ### File: 100-change_owner_and_group 54 | 55 | ## 15. Write a script that changes the owner and the group owner of `_hello` to `vincent` and `staff` respectively. 56 | ### File: 101-symbolic_link_permissions 57 | 58 | ## 16. Write a script that changes the owner of the file `hello` to `betty` only if it is owned by the user `guillaume`. 59 | ### File: 102-if_only 60 | 61 | ## 17. Write a script that will play the StarWars IV episode in the terminal. 62 | ### File: 103-Star_Wars 63 | -------------------------------------------------------------------------------- /0x02-shell_redirections/0-hello_world: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "Hello, World" 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/1-confused_smiley: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "\"(Ôo)'" 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/10-no_more_js: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | find -name "*.js" -type f -delete 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/100-empty_casks: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | find -empty | rev | cut -d'/' -f1 | rev 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/101-gifs: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | find -type f -name "*.gif" -printf "%f\n" | rev | cut -d'.' -f 2- | rev | LC_ALL=C sort -f 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/102-acrostic: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cut -c1 | paste -s | tr -d "[:blank:]" 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/103-the_biggest_fan: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | tail -n +2 | cut -f1 | sort | uniq -c | sort -nr | head -11 | tr -s ' ' | cut -d' ' -f3 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/11-directories: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | find . -type d ! -path . -print | wc -l 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/12-newest_files: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ls -1t | head -10 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/13-unique: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | sort | uniq -u 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/14-findthatword: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | grep "root" /etc/passwd 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/15-countthatword: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | grep -c "bin" /etc/passwd 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/16-whatsnext: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | grep -A 3 "root" /etc/passwd 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/17-hidethisword: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | grep -v "bin" /etc/passwd 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/18-letteronly: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | grep ^[[:alpha:]] /etc/ssh/sshd_config 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/19-AZ: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | tr 'A' 'Z' | tr 'c' 'e' 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/2-hellofile: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cat /etc/passwd 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/20-hiago: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | tr -d 'c' | tr -d 'C' 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/21-reverse: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | rev 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/22-users_and_homes: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cut -d : -f 1,6 /etc/passwd | sort 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/3-twofiles: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cat /etc/passwd /etc/hosts 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/4-lastlines: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | tail /etc/passwd 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/5-firstlines: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | head /etc/passwd 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/6-third_line: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | head -3 iacta | tail -1 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/7-file: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "Best School" > "\*\\\'\"Best School\"\'\\\*$\?\*\*\*\*\*:)" 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/8-cwd_state: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ls -la>ls_cwd_content 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/9-duplicate_last_line: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | tail -1 >iacta 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/README.md: -------------------------------------------------------------------------------- 1 | File 0-current_working_directory prints the current working directory. 2 | 3 | File 1-listit displays the contents list of the current directory. 4 | 5 | File 2-bring_me_home changes the working directory to the user’s home directory. 6 | 7 | File 3-listfiles displays current directory contents in a long format. 8 | 9 | File 4-listmorefiles displays current directory contents, including hidden files (starting with .). 10 | 11 | File 5-listfilesdigitonly displays current directory contents in long format, with user and group IDs displayed numerically and hidden files. 12 | 13 | File 6-firstdirectory creates a script that creates a directory named holberton in the /tmp/ directory. 14 | 15 | File 7-movethatfile moves the file betty from /tmp/ to /tmp/holberton. 16 | 17 | File 8-firstdelete deletes he file betty. 18 | 19 | File 9-firstdirdeletion deletes the directory holberton that is in the /tmp directory. 20 | 21 | File 10-back writes a script that changes the working directory to the previous one. 22 | 23 | File 11-lists writes a script that lists all files (even ones with names beginning with a period character, which are normally hidden) in the current directory and the parent of the working directory and the /boot directory (in this order), in long format. 24 | 25 | File 12-file_type writes a script that prints the type of the file named iamafile. 26 | 27 | File 13-symbolic_link creates a symbolic link to /bin/ls, named ls. 28 | 29 | File 14-copy_html creates a script that copies all the HTML files from the current working directory to the parent of the working directory, but only copy files that did not exist in the parent of the working directory or were newer than the versions in the parent of the working directory. 30 | 31 | File 15-lets_move creates a script that moves all files beginning with an uppercase letter to the directory /tmp/u. 32 | 33 | File 16-clean_emacs creates a script that deletes all files in the current working directory that end with the character ~. 34 | 35 | File 17-tree creates a script that creates the directories welcome/, welcome/to/ and welcome/to/holberton in the current directory. 36 | 37 | File 18-commas writes a command that lists all the files and directories of the current directory, separated by commas (,). 38 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/0-alias: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | alias ls="rm *" 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/1-hello_you: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "hello $USER" 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/10-love_exponent_breath: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo $((BREATH**LOVE)) 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/100-decimal_to_hexadecimal: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | printf '%x\n' $DECIMAL 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/101-rot13: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | tr 'A-Za-z' 'N-ZA-Mn-za-m' 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/102-odd: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | paste -d, - - | cut -d, -f1 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/103-water_and_stir: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | printf "%o\n" $(( $((5#$(echo $WATER | tr water 01234))) + $((5#$(echo $STIR | tr stir. 01234))) )) | tr 01234567 bestchol 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/11-binary_to_decimal: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo $((2#$BINARY)) 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/12-combinations: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo {a..z}{a..z} | tr ' ' '\n' | grep -v "oo" 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/13-print_float: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | printf '%.2f\n' $NUM 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/2-path: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | PATH=$PATH:/action 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/3-paths: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo $PATH | tr ':' '\n' | wc -l 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/4-global_variables: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | printenv 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/5-local_variables: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/6-create_local_variable: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | BEST="School" 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/7-create_global_variable: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | export BEST="School" 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/8-true_knowledge: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo $((128 + $TRUEKNOWLEDGE)) 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/9-divide_and_rule: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo $((POWER/DIVIDE)) 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/README.md: -------------------------------------------------------------------------------- 1 | ![image](https://user-images.githubusercontent.com/105258746/188752518-2606bf0a-0726-4c8a-8843-eb06d121d9cd.png) 2 | 3 | # SHELL, init files, variables and expansions PROJECTS 4 | 5 | ## TASKS 6 | 7 | ### Note: When doing this project, After using text editor of your choice to create and access the file on insert mode.Ensure the first line is always having `#!/bin/bash`, then the second line is having the correct command/answer. 8 | (From your terminal, convert the file created to `SCRIPT` i.e: chmod u+x filename) 9 | 10 | ### File: 0-alias is a script that creates an alias. 11 | 12 | - input: `alias ls="rm *"` 13 | 14 | ### File: 1-hello_you is a script that prints hello user, where user is the current Linux user. 15 | 16 | - input: `echo "hello $USER"` 17 | 18 | ### File: 2-path is a script that adds /action to the PATH. 19 | 20 | - input: `PATH=$PATH:/action` 21 | 22 | ### File: 3-paths is a script that counts the number of directories in the PATH. 23 | 24 | - input: `echo $PATH | tr ':' '\n' | wc -l` 25 | 26 | ### File: 4-global_variables is a script that lists environment variables. 27 | 28 | - input: `printenv` 29 | 30 | ### File: 5-local_variables is a script that lists all local variables and environment variables, and functions. 31 | 32 | - input: `set` 33 | 34 | ### File: 6-create_local_variable is a script that creates a new local variable. 35 | 36 | - input: `BEST="School"` 37 | 38 | ### File: 7-create_global_variable is a script that creates a new global variable. 39 | 40 | - input: `export BEST="School"` 41 | 42 | ### File: 8-true_knowledge is a script that prints the result of the addition of 128 with the value stored in the environment variable TRUEKNOWLEDGE, followed by a new line. 43 | 44 | - input: `echo $((128 + $TRUEKNOWLEDGE))` 45 | 46 | ### File: 9-divide_and_rule is a script that prints the result of POWER divided by DIVIDE, followed by a new line. 47 | 48 | - input: `echo $((POWER/DIVIDE))` 49 | 50 | ### File: 10-love_exponent_breath is a script that displays the result of BREATH to the power LOVE. 51 | 52 | - input: `echo $((BREATH**LOVE))` 53 | 54 | ### File: 11-binary_to_decimal` is a script that converts a number from base 2 to base 10. 55 | 56 | - input: `echo $((2#$BINARY))` 57 | 58 | ### File: 12-combinations is a script that prints all possible combinations of two letters, except oo. 59 | 60 | - input: `echo {a..z}{a..z} | tr ' ' '\n' | grep -v "oo"` 61 | 62 | ### File: 13-print_float is a script that prints a number with two decimal places. 63 | 64 | - input: `printf '%.2f\n' $NUM` 65 | 66 | ### File: 100-decimal_to_hexadecimal is a script that converts a number from base 10 to base 16. 67 | 68 | - input: `printf '%x\n' $DECIMAL` 69 | 70 | ### File: 101-rot13 is a script that encodes and decodes text using the rot13 encryption. 71 | 72 | - input: `tr 'A-Za-z' 'N-ZA-Mn-za-m'` 73 | 74 | ### File: 102-odd is a script that prints every other line from the input, starting with the first line. 75 | 76 | - input: `paste -d, - - | cut -d, -f1` 77 | 78 | ### File: 103-water_and_stir is a shell script that adds the two numbers stored in the environment variables WATER and STIR and prints the result. 79 | 80 | - input: `printf "%o\n" $(( $((5#$(echo $WATER | tr water 01234))) + $((5#$(echo $STIR | tr stir. 01234))) )) | tr 01234567 bestchol` 81 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/0-RSA_public_key.pub: -------------------------------------------------------------------------------- 1 | ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDosSe3dnBxA2GAe7SU/E7u9OFelSMd27P5e/FgtJCY4EfpIlx3vBOt42OSdXoTd/AJvKF7Et5/rDZ8O2IVnG/3Stq/tH2tjdkRDXx4xzz70eGfWCfBcRSpS6ycQLTC9OisRJct9n0mCQQvw3edqepaVB1sUw2JWGq0D5LdQUlbU+fmLku/rOYfOJgAr3MAKHhOPZsEt4H0tKEqbFY84Vqml0eKFRet5BAB2vEJ6AHURgnsmw3+cEoPyqZrBzEB3DOebWzjCFw+UomwQXqDp+VHCmKR+y7NI2+M56I7ZsWWU/jXSuy1JHE4TzmiDRqr13VjUR02/yhNRLOOvPaAQqCj root@1a029f314a9e 2 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/1-for_best_school: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays "Best School" 10 times using a for loop. 3 | 4 | for (( i=0; i<10; i++ )) 5 | do 6 | echo "Best School" 7 | done 8 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/10-fizzbuzz: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays numbers from 1 to 100 in list format. 3 | # Displays "FizzBuzz" when the number is a multiple of 3 and 5. 4 | # Displays "Fizz" when the number is a multiple of 3. 5 | # Displays "Buzz" when the number is a multiple of 5. 6 | # Otherwise, displays the number. 7 | 8 | for num in {1..100} 9 | do 10 | if (( num % 3 == 0 && num % 5 == 0 )) 11 | then 12 | echo "FizzBuzz" 13 | elif (( num % 3 == 0 )) 14 | then 15 | echo "Fizz" 16 | elif (( num % 5 == 0 )) 17 | then 18 | echo "Buzz" 19 | else 20 | echo "$num" 21 | fi 22 | done 23 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/100-read_and_cut: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays the contents of the file `/etc/passwd`. 3 | # Only displays the username, user id, and user home directory path. 4 | 5 | while read -r passwd; do 6 | echo "$passwd" | cut -d ':' -f1,3,6 7 | done < "/etc/passwd" 8 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/101-tell_the_story_of_passwd: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Tells a story based on the contents of the `/etc/passwd` file. 3 | 4 | while IFS=':' read -r username password uid gid info home shell; do 5 | echo "The user $username is part of the $gid gang,"\ 6 | "lives in $home and rides $shell."\ 7 | "$uid's place is protected by the passcode $password,"\ 8 | "more info about the user here: $info" 9 | done < "/etc/passwd" 10 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/102-lets_parse_apache_logs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Parses Apache log files in list format. 3 | # Displays the IP and HTTP status code. 4 | 5 | awk '{print $1 " " $9}' apache-access.log 6 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/103-dig_the-data: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Parses Apache log files in list format. 3 | # Groups visitors by IP and HTTP status code. 4 | # Displays the number of occurrences, IP, and HTTP status 5 | #+ code of each log, in sorted order. 6 | 7 | awk '{ print $1 " " $9}' apache-access.log | sort | uniq -c | sort -rn 8 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/2-while_best_school: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays "Best School" 10 times using a while loop. 3 | 4 | count=0 5 | 6 | while [ $count -lt 10 ] 7 | do 8 | echo "Best School" 9 | (( count++ )) 10 | done 11 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/3-until_best_school: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays "Best School" 10 times using an until loop. 3 | 4 | count=0 5 | 6 | until [ $count -eq 10 ] 7 | do 8 | echo "Best School" 9 | (( count++ )) 10 | done 11 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/4-if_9_say_hi: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays "Best School" 10 times using a while loop. 3 | # On the 9th iteration, displays "Hi" before "Best School". 4 | 5 | count=0 6 | 7 | while [ $count -lt 10 ] 8 | do 9 | if [ $count -eq 9 ] 10 | then 11 | echo "Hi" 12 | fi 13 | echo "Best School" 14 | (( count++ )) 15 | done 16 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/5-4_bad_luck_8_is_your_chance: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Loops from 1 to 10 and displays: 3 | # "bad luck" for the 4th iteration 4 | # "good luck" for the 8th iteration 5 | # "Best School" for all other iterations 6 | 7 | count=0 8 | 9 | while [ $count -lt 10 ] 10 | do 11 | if [ $count -eq 3 ] 12 | then 13 | echo "bad luck" 14 | elif [ $count -eq 7 ] 15 | then 16 | echo "good luck" 17 | else 18 | echo "Best School" 19 | fi 20 | (( count++ )) 21 | done 22 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/6-superstitious_numbers: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays numbers from 1 to 20 in addition to: 3 | # "bad luck from China" for the 4th iteration 4 | # "bad luck from Japan" for the 9th iteration 5 | # "bad luck from Italy" for the 17th loop iteration 6 | 7 | count=1 8 | 9 | while [ $count -le 20 ] 10 | do 11 | echo "$count" 12 | case $count in 13 | "4") echo "bad luck from China";; 14 | "9") echo "bad luck from Japan";; 15 | "17") echo "bad luck from Italy";; 16 | esac 17 | (( count++ )) 18 | done 19 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/7-clock: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays the time for 12 horus and 59 minutes. 3 | # Displays hours from 0 to 12 4 | # Displays minutes from 1 to 59 5 | 6 | hour=0 7 | 8 | while [ $hour -le 12 ] 9 | do 10 | echo "Hour: $hour" 11 | minute=1 12 | while [ $minute -le 59 ] 13 | do 14 | echo "$minute" 15 | (( minute++ )) 16 | done 17 | (( hour++ )) 18 | done 19 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/8-for_ls: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays the contents of the current directory in list format. 3 | # Only displays the part of the name after the first dash. 4 | 5 | list=$(ls) 6 | for i in $list; do 7 | echo "$i" | cut -d '-' -f2 8 | done 9 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/9-to_file_or_not_to_file: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays information about the `school` file. 3 | 4 | if [ -e "school" ] 5 | then 6 | echo "school file exists" 7 | if [ -s "school" ] 8 | then 9 | echo "school file is not empty" 10 | else 11 | echo "school file is empty" 12 | fi 13 | 14 | if [ -f "school" ] 15 | then 16 | echo "school is a regular file" 17 | fi 18 | else 19 | echo "school file does not exist" 20 | fi 21 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/README.md: -------------------------------------------------------------------------------- 1 | # Shell Loops, Conditions, 2 | ![](https://phoenixnap.com/kb/wp-content/uploads/2021/12/individual.sh-for-loop-script.png) 3 | 4 | ## Use this command to generate RSA key `ssh-keygen -t rsa` 5 | 6 | ## Learning objectives 7 | 8 | - How to create SSH keys 9 | - What is the advantage of using `#!/usr/bin/env` bash over `#!/bin/bash` 10 | - How to use `while`, `until` and `for` loops 11 | - How to use `if`, `else`, `elif` and case condition statements 12 | - How to use the `cut` command 13 | - What are files and other comparison operators, and how to use them 14 | 15 | ## Requirements 16 | 17 | - Allowed editors: `vi`, `vim`, `emacs` 18 | - All your files will be interpreted on `Ubuntu 20.04 LTS` 19 | - All your files should end with a new line 20 | - A README.md file, at the root of the folder of the project, is mandatory 21 | - All your Bash script files must be executable 22 | - You are not allowed to use `awk` 23 | - Your Bash script must pass `Shellcheck` (version 0.7.0) without any error 24 | - The first line of all your Bash scripts should be exactly `#!/usr/bin/env bash` 25 | - The second line of all your Bash scripts should be a comment explaining what the script doing 26 | 27 | ## Concepts 28 | 29 | - `env` 30 | - `cut` 31 | - `for` 32 | - `while` 33 | - `until` 34 | - `if` 35 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/0-what-is-my-pid: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays its own PID. 3 | 4 | echo $$ 5 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/1-list_your_processes: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays a list of currently running processes. 3 | # Shows all processes, for all users, including those 4 | #+ which might not have a TTY. 5 | 6 | ps -auxf 7 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/100-process_and_pid_file: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Does the following: 3 | # Create a file /var/run/myscript.pid containing the script PID. 4 | # Displays "To infinity and beyond" indefinitely 5 | # Displays "I hate the kill command" upon receiving a SIGTERM 6 | # Displays "Y U no love me?!" upon receiving a SIGINT 7 | # Deletes the file /var/run/myscript.pid and terminates upon 8 | #+ receiving a SIGQUIT or SIGTERM. 9 | 10 | terminator() { 11 | rm /var/run/myscript.pid 12 | exit 13 | } 14 | 15 | echo "$$" > /var/run/myscript.pid 16 | 17 | while true 18 | do 19 | echo "To infinity and beyond" 20 | sleep 2 21 | trap 'echo "Y U no love me?!"' SIGINT 22 | trap 'echo "I hate the kill command" && terminator' SIGTERM 23 | trap 'terminator' SIGQUIT 24 | done 25 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/101-manage_my_process: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Manages the script manage_my_process. 3 | # When passed the argument `start`: 4 | # 1. Starts manage_my_process 5 | # 2. Creates a file containings its PID in /var/run/my_process.pid 6 | # 3. Displays "manage_my_process started" 7 | # When passed the argument `stop`: 8 | # 1. Stops manage_my_process 9 | # 2. Deletes the file /var/run/my_process.pid 10 | # 3. Displays "manage_my_process stopped" 11 | # When passed the argument `restart`: 12 | # 1. Stops manage_my_process 13 | # 2. Deletes the file /var/run/my_process.pid 14 | # 3. Starts manage_my_process 15 | # 4. Creates a file containing its PID in /var/run/my_process.pid 16 | # 5. Displays "manage_my_process restarted" 17 | # If any other or no arguments are passed, displays 18 | #+ "Usage: manage_my_process {start|stop|restart}" 19 | 20 | if [ "${1}" == "start" ] 21 | then 22 | ./manage_my_process & 23 | touch /var/run/my_process.pid 24 | echo "$!" > /var/run/my_process.pid 25 | echo "manage_my_process started" 26 | elif [ "${1}" == "stop" ] 27 | then 28 | echo "manage_my_process stopped" 29 | kill "$(cat /var/run/my_process.pid)" 30 | rm /var/run/my_process.pid 31 | elif [ "${1}" == "restart" ] 32 | then 33 | kill "$(cat /var/run/my_process.pid)" 34 | rm /var/run/my_process.pid 35 | ./manage_my_process & 36 | touch /var/run/my_process.pid 37 | echo "$!" > /var/run/my_process.pid 38 | echo "manage_my_process restarted" 39 | else 40 | echo "Usage: manage_my_process {start|stop|restart}" 41 | fi 42 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/102-zombie.c: -------------------------------------------------------------------------------- 1 | /* 2 | * File: 102-zombie.c 3 | * Auth: Brennan D Baraban 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | /** 13 | * infinite_while - Run an infinite while loop. 14 | * 15 | * Return: Always 0. 16 | */ 17 | int infinite_while(void) 18 | { 19 | while (1) 20 | { 21 | sleep(1); 22 | } 23 | return (0); 24 | } 25 | 26 | /** 27 | * main - Creates five zombie processes. 28 | * 29 | * Return: Always 0. 30 | */ 31 | int main(void) 32 | { 33 | pid_t pid; 34 | char count = 0; 35 | 36 | while (count < 5) 37 | { 38 | pid = fork(); 39 | if (pid > 0) 40 | { 41 | printf("Zombie process created, PID: %d\n", pid); 42 | sleep(1); 43 | count++; 44 | } 45 | else 46 | exit(0); 47 | } 48 | 49 | infinite_while(); 50 | 51 | return (EXIT_SUCCESS); 52 | } 53 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/2-show_your_bash_pid: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays a list of currently running processes containing the bash keyword. 3 | # shellcheck disable=SC2009 4 | 5 | ps -aux | grep bash 6 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/3-show_your_bash_pid_made_easy: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays the PID along with the process name, of 3 | #+ processes whose name contains the word "bash". 4 | 5 | pgrep bash -l 6 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/4-to_infinity_and_beyond: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays "To infinity and beyond" indefinitely with 3 | #+ a sleep 2 in between each iteration. 4 | 5 | while true 6 | do 7 | echo "To infinity and beyond" 8 | sleep 2 9 | done 10 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/5-dont_stop_me_now: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Kills the 4-to_infinity_and_beyond process 3 | 4 | kill "$(pgrep -f 4-to_infinity_and_beyond)" 5 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/6-stop_me_if_you_can: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Kills the 4-to_infinity_and_beyond process. 3 | 4 | pkill -f 4-to_infinity_and_beyond 5 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/67-stop_me_if_you_can: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Kills the 4-to_infinity_and_beyond process. 3 | 4 | pkill -f 7-highlander 5 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/7-highlander: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays "To infinity and beyond" indefinitely with 3 | #+ a sleep 2 in between each iteration. 4 | # Displays "I am invincible!!!" in between each iteration. 5 | 6 | while true 7 | do 8 | echo "To infinity and beyond" 9 | sleep 2 10 | trap 'echo "I am invincible!!!"' SIGTERM 11 | done 12 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/8-beheaded_process: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Kills the process 7-highlander. 3 | 4 | pkill -f -SIGKILL 7-highlander 5 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/README.md: -------------------------------------------------------------------------------- 1 | # Processes and signals 2 | 3 | In this project, I learned about handling process ID's and signals in Bash with `ps`, `pgrep`, `pkill`, `pkill`, `exit`, and `trap`. 4 | 5 | ## Tasks :page_with_curl: 6 | 7 | * **0. What is my PID** 8 | * [0-what-is-my-pid](./0-what-is-my-pid): Bash script that displays its own PID. 9 | 10 | * **1. List your processes** 11 | * [1-list_your_processes](./1-list_your_processes): Bash script that displays a list of currently running processes. 12 | * Shows all processes for all users, including those not featuring a TTY. 13 | * Processes are displayed in a user-oriented hierarchy. 14 | 15 | * **2. Show your Bash PID** 16 | * [2-show_your_bash_pid](./2-show_your_bash_pid): Bash script that displays lines containing the `bash` keyword based on the script defined in `1-list_your_processes`. 17 | 18 | * **3. Show your Bash PID made easy** 19 | * [3-show_your_bash_pid_made_easy](./3-show_your_bash_pid_made_easy): Bash script that displays the PID along with the process name of processes who name contains the word `bash`. 20 | 21 | * **4. To infinity and beyond** 22 | * [4-to_infinity_and_beyond](./4-to_infinity_and_beyond): Bash script that displays `To infinity and beyond` indefinitely with a `sleep 2` in between each iteration. 23 | 24 | * **5. Don't stop me now!** 25 | * [5-dont_stop_me_now](./5-dont_stop_me_now): Bash script that kills the [4-to_infinity_and_beyond](./4-to_infinity_and_beyond) process using `kill`. 26 | 27 | * **6. Stop me if you can** 28 | * [6-stop_me_if_you_can](./6-stop_me_if_you_can): Bash script that kills the [4-to_infinity_and_beyond](./4-to_infinity_and_beyond) process using `pkill`. 29 | 30 | * **7. Highlander** 31 | * [7-highlander](./7-highlander): Bash script that displays `To infinity and beyond` indefinitely with a `sleep 2` in between each iteration. 32 | * Displays `I am invincible!!!` upon receiving a `SIGTERM` signal. 33 | 34 | 35 | * **8. Beheaded process** 36 | * [8-beheaded_process](./8-beheaded_process): Bash script that kills the process [7-highlander](./7-highlander). 37 | 38 | 39 | ![alt text](https://s3.amazonaws.com/alx-intranet.hbtn.io/uploads/medias/2020/9/d8ecfe9109334898b9540ffd20cf64d1c06f0c09.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIARDDGGGOUSBVO6H7D%2F20220722%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20220722T101619Z&X-Amz-Expires=86400&X-Amz-SignedHeaders=host&X-Amz-Signature=8831f4931db87fcebcbad63936313cf1ea4a070d0d73bc8ba8531a85eb862046) 40 | 41 | * **9. Process and PID file** 42 | * [100-process_and_pid_file](./100-process_and_pid_file): Bash script that creates the file `/var/run/myscript.pid` containing its PID and displays `To infinity and beyond` indefinitely. 43 | * Displays `I hate the kill command` upon receiving a `SIGTERM` signal. 44 | * Displays `Y U no love me?!` upon receiving a `SIGINT` signal. 45 | * Deletes the file `/var/run/myscript.pid` and terminates itself upon receiving the `SIGQUIT` or `SIGTERM` signal. 46 | 47 | 48 | ![](https://s3.amazonaws.com/alx-intranet.hbtn.io/uploads/medias/2020/9/37975393ead381f4d27f268f7337c6d3013b4991.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIARDDGGGOUSBVO6H7D%2F20220722%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20220722T101619Z&X-Amz-Expires=86400&X-Amz-SignedHeaders=host&X-Amz-Signature=ad4edea7cdd7ecaaa7ab06f0cb40c5b269a1c2777a349c54587445b68ff1c304) 49 | 50 | * **10. Manage my process** 51 | * [manage_my_process](./manage_my_process): Bash script that writes `I am alive!` to the file `/tmp/my_process` indefinitely. 52 | * Sleeps two seconds in between each write. 53 | * [101-manage_my_process](./101-manage_my_process): Bash script that manages the [manage_my_process](./manage_my_process) script. 54 | * When passed the argument `start`: 55 | * Starts [manage_my_process](./manage_my_process). 56 | * Creates a file containing its PID in `/var/run/my_process.pid`. 57 | * Displays `manage_my_process started`. 58 | * When passed the argument `stop`: 59 | * Stops [manage_my_process](./manage_my_process). 60 | * Deletes the file `/var/run/my_process.pid`. 61 | * Displays `manage_my_process stopped`. 62 | * When passed the argument `restart`: 63 | * Stops [manage_my_process](./manage_my_process). 64 | * Deletes the file `/var/run/my_process.pid`. 65 | * Starts `manage_my_process`. 66 | * Creates a file containing its PID in `/var/run/my_process.pid`. 67 | * Displays `manage_my_process started`. 68 | * Otherwise, displays `Usage: manage_my_process {start|stop|restart}`. 69 | 70 | 71 | ![alt text](https://s3.amazonaws.com/intranet-projects-files/holbertonschool-sysadmin_devops/255/C6mO7b3.jpg) 72 | 73 | * **11. Zombie** 74 | * [102-zombie.c](./102-zombie.c): C program that creates five zombie processes. 75 | * For every zombie created, displays `Zombie process created, PID: `. 76 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/manage_my_process: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Indefinitely writes "I am alive" to the file /tmp/my_process. 3 | # Pauses two seconds in between each message. 4 | 5 | while true 6 | do 7 | echo "I am alive!" >> /tmp/my_process 8 | sleep 2 9 | done 10 | -------------------------------------------------------------------------------- /0x06-regular_expressions/0-simply_match_school.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | puts ARGV[0].scan(/School/).join 3 | -------------------------------------------------------------------------------- /0x06-regular_expressions/1-repetition_token_0.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | puts ARGV[0].scan(/hbt{2,5}n/).join 3 | -------------------------------------------------------------------------------- /0x06-regular_expressions/100-textme.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | puts ARGV[0].scan(/\[from:(.*?)\] \[to:(.*?)\] \[flags:(.*?)\]/).join(",") 3 | -------------------------------------------------------------------------------- /0x06-regular_expressions/2-repetition_token_1.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | puts ARGV[0].scan(/hb?t?n/).join 3 | -------------------------------------------------------------------------------- /0x06-regular_expressions/3-repetition_token_2.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | puts ARGV[0].scan(/hbt+n/).join 3 | -------------------------------------------------------------------------------- /0x06-regular_expressions/4-repetition_token_3.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | puts ARGV[0].scan(/hbt*n/).join 3 | -------------------------------------------------------------------------------- /0x06-regular_expressions/5-beginning_and_end.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | puts ARGV[0].scan(/^h.n$/).join 3 | -------------------------------------------------------------------------------- /0x06-regular_expressions/6-phone_number.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | puts ARGV[0].scan(/^\d{10,10}$/).join 3 | -------------------------------------------------------------------------------- /0x06-regular_expressions/7-OMG_WHY_ARE_YOU_SHOUTING.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | puts ARGV[0].scan(/[A-Z]*/).join 3 | -------------------------------------------------------------------------------- /0x06-regular_expressions/README.md: -------------------------------------------------------------------------------- 1 | # Regular expression 2 | 3 | In this project, I learned how to use regular expressions. All my regex is built for the Oniguruma library. 4 | 5 | ## Tasks :page_with_curl: 6 | 7 | _Note: Each Ruby script in the project matches regular expressions based on an argument passed to it via the command line._ 8 | 9 | * **0. Simply matching Holberton** 10 | * [0-simply_match_holberton.rb](./0-simply_match_holberton.rb): Ruby script that matches the regular expression `School`. 11 | 12 | * **1. Repetition Token #0** 13 | * [1-repetition_token_0.rb](./1-repetition_token_0.rb): Ruby script that matches the regular expression `hbn` with between 2-5 `t`'s in between `hb` and `n`. 14 | 15 | * **2. Repetition Token #1** 16 | * [2-repetition_token_1.rb](./2-repetition_token_1.rb): Ruby script that matches the regular expression `hn` with 0 or 1 occurrences of `b` and 0 or 1 17 | occurrences of `t` in between `h` and `n`. 18 | 19 | * **3. Repetition Token #2** 20 | * [3-repetition_token_2.rb](./3-repetition_token_2.rb): Ruby script that matches the regular expression `hbn` with 1 or more `t`'s in between `hb` and `n`. 21 | 22 | * **4. Repetition Token #3** 23 | * [4-repetition_token_3.rb](./4-repetition_token_3.rb): Ruby script that matches the regular expression `hbn` with 0 or more `t`'s in between `hb` and `n`. 24 | 25 | * **5. Not quite HBTN yet** 26 | * [5-beginning_and_end.rb](./5-beginning_and_end.rb): Ruby script that matches a regular expression starting with `h` and ending with `n` with any single character in between. 27 | 28 | * **6. Call me maybe** 29 | * [6-phone_number.rb](./6-phone_number.rb): Ruby script that matches a regular expression representing a 10-digit phone number. 30 | 31 | * **7. OMG WHY ARE YOU SHOUTING?** 32 | * [7-OMG_WHY_ARE_YOU_SHOUTING.rb](./7-OMG_WHY_ARE_YOU_SHOUTING.rb): Ruby script that matches regular expressions of uppercase letters. 33 | 34 | * **8. Textme** 35 | * [100-textme.rb](./100-textme.rb): Ruby script that runs statistics on TextMe app text message transcations. 36 | * Output: `[SENDER],[RECEIVER],[FLAGS]` where 37 | * `[SENDER]` is the sender phone number or name (including country code if present). 38 | * `[RECEIVER]` is the receiver phone number or name (including country code if present). 39 | * `[FLAGS]` is the flags that were used. 40 | 41 | 42 | -------------------------------------------------------------------------------- /0x07-networking_basics/0-OSI_model: -------------------------------------------------------------------------------- 1 | 2 2 | 2 3 | -------------------------------------------------------------------------------- /0x07-networking_basics/1-types_of_network: -------------------------------------------------------------------------------- 1 | 3 2 | 2 3 | 1 4 | -------------------------------------------------------------------------------- /0x07-networking_basics/2-MAC_and_IP_address: -------------------------------------------------------------------------------- 1 | 2 2 | 1 3 | -------------------------------------------------------------------------------- /0x07-networking_basics/3-UDP_and_TCP: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 1 4 | -------------------------------------------------------------------------------- /0x07-networking_basics/4-TCP_and_UDP_ports: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays listening ports. Includes listening sockets as well 3 | # + as the PID and name of the program to which each socket belongs. 4 | 5 | netstat -l --program 6 | -------------------------------------------------------------------------------- /0x07-networking_basics/5-is_the_host_on_the_network: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Pings an IP address received as an argument 5 times. 3 | 4 | if [ $# -eq 0 ] 5 | then 6 | echo "Usage: 5-is_the_host_on_the_network {IP_ADDRESS}" 7 | else 8 | ping -c 5 "$1" 9 | fi 10 | -------------------------------------------------------------------------------- /0x07-networking_basics/README.md: -------------------------------------------------------------------------------- 1 | # Networking basics #0 2 | 3 | This project was the first of two introducing networking concepts. In this project, I answered a few quiz-like questions and wrote a couple bash scripts while learning about the OSI model, LAN and WAN networks, and TCP/UDP data transfer protocols. 4 | 5 | ## Tasks :page_with_curl: 6 | 7 | * **0. OSI model** 8 | * [0-OSI_model](./0-OSI_model): Text file answering the following questions: 9 | * What is the OSI model? 10 | 1. Set of specifications that network hardware manufacturers must respect 11 | 2. The OSI model is a conceptual model that characterizes the communication functions of a telecommunication system without regard to their underlying internal structure and technology. 12 | 3. The OSI model is a model that characterizes the communication functions of a telecommunication system with a strong regard for their underlying internal structure and technology. 13 | * How is the OSI model organized? 14 | 1. Alphabetically 15 | 2. From the lowest to the highest level 16 | 3. Randomly 17 | 18 | * **1. Types of network** 19 | * [1-types_of_network](./1-types_of_network): Text file answering the following questions: 20 | * What type of network a computer in local is connected to? 21 | 1. Internet 22 | 2. WAN 23 | 3. LAN 24 | * What type of network could connect an office in one building to another office in a building a few streets away? 25 | 1. Internet 26 | 2. WAN 27 | 3. LAN 28 | * What network do you use when you browse www.google.com from your smartphone (not connected to the Wifi)? 29 | 1. Internet 30 | 2. WAN 31 | 3. LAN 32 | 33 | * **2. MAC and IP address** 34 | * [2-MAC_and_IP_address](./2-MAC_and_IP_address): Text file answering the following questions: 35 | * What is a MAC address? 36 | 1. The name of a network interface 37 | 2. The unique identifier of a network interface 38 | 3. A network interface 39 | * What is an IP address? 40 | 1. Is to devices connected to a network what postal address is to houses 41 | 2. The unique identifier of a network interface 42 | 3. Is a number that network devices use to connect to networks 43 | 44 | * **3. UDP and TCP** 45 | * [3-UDP_and_TCP](./3-UDP_and_TCP): Text file answering the following questions: 46 | * Which statement is correct for the TCP box: 47 | 1. It is a protocol that is transferring data in a slow way but surely 48 | 2. It is a protocol that is transferring data in a fast way and might loss data along in the process 49 | * Which statement is correct for the UDP box: 50 | 1. It is a protocol that is transferring data in a slow way but surely 51 | 2. It is a protocol that is transferring data in a fast way and might loss data along in the process 52 | * Which statement is correct for the TCP worker: 53 | 1. Have you received boxes x, y, z? 54 | 2. May I increase the rate at which I am sending you boxes? 55 | 56 | * **4. TCP and UDP ports** 57 | * [4-TCP_and_UDP_ports](./4-TCP_and_UDP_ports): Bash script that displays listening ports. 58 | * That only shows listening sockets. 59 | * That shows the PID and name of the program to which each socket belongs. 60 | 61 | * **5. Is the host on the network** 62 | * [5-is_the_host_on_the_network](./5-is_the_host_on_the_network): Bash script that pings an IP address received as an argument 5 times. 63 | * Usage: `5-is_the_host_on_the_network {IP_ADDRESS}`. 64 | -------------------------------------------------------------------------------- /0x08-networking_basics_2/0-change_your_home_IP: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Configures an Ubuntu server as follows: 3 | # - localhost resolves to 127.0.0.2 4 | # - facebook.com resolves to 8.8.8.8 5 | 6 | cp /etc/hosts ~/hosts.new 7 | echo "127.0.0.2 localhost" > ~/hosts.new 8 | echo "8.8.8.8 facebook.com" >> ~/hosts.new 9 | cp -f ~/hosts.new /etc/hosts 10 | -------------------------------------------------------------------------------- /0x08-networking_basics_2/1-show_attached_IPs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays all acive IPv4 addresses on the machine. 3 | 4 | ifconfig | grep -Eo "inet (addr:)?([0-9]*\.){3}[0-9]*" | cut -b 11- 5 | -------------------------------------------------------------------------------- /0x08-networking_basics_2/100-port_listening_on_localhost: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Listens on port 98 on localhost. 3 | 4 | nc -l localhost 98 5 | -------------------------------------------------------------------------------- /0x08-networking_basics_2/README.md: -------------------------------------------------------------------------------- 1 | # Networking basics #1 2 | 3 | In this project, I continued to learn about IP addresses while practicing manipulating them with Bash scripts. 4 | 5 | ## Tasks :page_with_curl: 6 | 7 | * **0. Change your home IP** 8 | * [0-change_your_home_IP](./0-change_your_home_IP): Bash script that configures an Ubuntu server as follows: 9 | * `localhost` resolves to `127.0.0.2` 10 | * `facebook.com` resolves to `8.8.8.8` 11 | 12 | * **1. Show attached IPs** 13 | * [1-show_attached_IPs](./1-show_attached_IPs): Bash script that displays all active IPv4 IP's on the machine. 14 | 15 | * **2. Port listening on localhost** 16 | * [100-port_listening_on_localhost](./100-port_listening_on_localhost): Bash script that listens on port `98` on `localhost`. 17 | -------------------------------------------------------------------------------- /0x09-web_infrastructure_design/0-simple_web_stack: -------------------------------------------------------------------------------- 1 | https://i.im.ge/2022/08/21/OU3M9z.My-First-Board.jpg 2 | -------------------------------------------------------------------------------- /0x09-web_infrastructure_design/1-distributed_web_infrastructure: -------------------------------------------------------------------------------- 1 | https://i.im.ge/2022/08/21/OU3RB9.1-distributed-web-infrastructure.jpg 2 | -------------------------------------------------------------------------------- /0x09-web_infrastructure_design/2-secured_and_monitored_web_infrastructure: -------------------------------------------------------------------------------- 1 | https://i.imgur.com/t33iKQB.jpg 2 | -------------------------------------------------------------------------------- /0x09-web_infrastructure_design/3-scale_up: -------------------------------------------------------------------------------- 1 | https://i.imgur.com/kqexZ40.jpg 2 | -------------------------------------------------------------------------------- /0x09-web_infrastructure_design/README.md: -------------------------------------------------------------------------------- 1 | # 0x09. Web infrastructure design 2 | 3 | ## Description 4 | 5 | This project contains links to diagrams representing different web infrastructures. 6 | Its goal is to understand, on a very high-level, how web infrastructures are organized and what are their components. 7 | -------------------------------------------------------------------------------- /0x0A-configuration_management/0-create_a_file.pp: -------------------------------------------------------------------------------- 1 | # creates a file in /tmp 2 | 3 | file { '/tmp/school': 4 | content =>'I love Puppet', 5 | mode => '0744', 6 | owner => 'www-data', 7 | group => 'www-data', 8 | } 9 | -------------------------------------------------------------------------------- /0x0A-configuration_management/1-install_a_package.pp: -------------------------------------------------------------------------------- 1 | #!/usr/bin/pup 2 | # Install an especific version of flask (2.1.0) 3 | package {'flask': 4 | ensure => '2.1.0', 5 | provider => 'pip3' 6 | } 7 | -------------------------------------------------------------------------------- /0x0A-configuration_management/2-execute_a_command.pp: -------------------------------------------------------------------------------- 1 | # kill process killmenow 2 | 3 | exec { 'pkill': 4 | command => 'pkill killmenow', 5 | provider => 'shell', 6 | } 7 | -------------------------------------------------------------------------------- /0x0A-configuration_management/README.md: -------------------------------------------------------------------------------- 1 | # Configuration management 2 | 3 | In this project, I started working with Puppet as a configuration management 4 | tool. I practiced writing Puppet manifest files to create a file, install a 5 | package, and execute a command. 6 | 7 | ## Tasks :page_with_curl: 8 | 9 | * **0. Create a file** 10 | * [0-create_a_file.pp](./0-create_a_file.pp): Puppet manifest file that 11 | creates a file `school` in the `/tmp` directory. 12 | * File permissions: `0744`. 13 | * File group: `www-data`. 14 | * File owner: `www-data`. 15 | * File content: `I love Puppet`. 16 | 17 | * **1. Install a package** 18 | * [1-install_a_package.pp](./1-install_a_package.pp): Puppet manifest file 19 | that install `flask` from pip3. 20 | 21 | * **2. Execute a command** 22 | * [2-execute_a_command.pp](./2-execute_a_command.pp): Puppet manifest file 23 | that kills the process `killmenow`. 24 | -------------------------------------------------------------------------------- /0x0A-configuration_management/killmenow: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | while [[ true ]] 3 | do 4 | sleep 2 5 | done 6 | -------------------------------------------------------------------------------- /0x0B-ssh/0-use_a_private_key: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Connects to server 34.138.32.248 with key in ~/.ssh/school 3 | 4 | ssh -i ~/.ssh/school ubuntu@34.138.32.248 5 | -------------------------------------------------------------------------------- /0x0B-ssh/1-create_ssh_key_pair: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Create an RSA key pair 3 | ssh-keygen -b 4096 -f school -N betty 4 | -------------------------------------------------------------------------------- /0x0B-ssh/100-puppet_ssh_config.pp: -------------------------------------------------------------------------------- 1 | # Seting up my client config file 2 | include stdlib 3 | 4 | file_line { 'Turn off passwd auth': 5 | ensure => present, 6 | path => '/etc/ssh/ssh_config', 7 | line => ' PasswordAuthentication no', 8 | replace => true, 9 | } 10 | 11 | file_line { 'Delare identity file': 12 | ensure => present, 13 | path => '/etc/ssh/ssh_config', 14 | line => ' IdentityFile ~/.ssh/school', 15 | replace => true, 16 | } 17 | -------------------------------------------------------------------------------- /0x0B-ssh/2-ssh_config: -------------------------------------------------------------------------------- 1 | # ssh config file 2 | Host * 3 | PasswordAuthentication no 4 | IdentifyFile ~/.ssh/school -------------------------------------------------------------------------------- /0x0B-ssh/README.md: -------------------------------------------------------------------------------- 1 | # SSH 2 | 3 | In this project, I became familiar connecting to and working 4 | with servers using the SSH protocol. I worked on a server 5 | provided by ALX. 6 | 7 | ## Tasks :page_with_curl: 8 | 9 | * **0. Use a private key** 10 | * [0-use_a_private_key](./0-use_a_private_key): Bash script that uses `ssh` to connect to my 11 | Holberton-provided server. 12 | 13 | * **1. Create an SSH key pair** 14 | * [1-create_ssh_key_pair](./1-create_ssh_key_pair): Bash script that creates an RSA key pair. 15 | 16 | * **2. Client configuration file** 17 | * [2-ssh_config](./2-ssh_config): SSH configuration file configured to use the private key 18 | `~/.ssh/holberton` and to refuse authentication using a password. 19 | -------------------------------------------------------------------------------- /0x0C-web_server/0-transfer_file: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Transfers a file from Holberton's client to another. 3 | # Accepts four arguments: 4 | #+ The path to the file to be transferred. 5 | #+ The IP of the server to transfer the file to. 6 | #+ The username that scp connects with. 7 | #+ The path to the SSH private key that scp uses. 8 | 9 | if [ $# -lt 4 ] 10 | then 11 | echo "Usage: 0-transfer_file PATH_TO_FILE IP USERNAME PATH_TO_SSH_KEY" 12 | else 13 | scp -o StrictHostKeyChecking=no -i "$4" "$1" "$3@$2":~ 14 | fi 15 | -------------------------------------------------------------------------------- /0x0C-web_server/1-install_nginx_web_server: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # installs nginx and configures it on a remote server 3 | 4 | apt-get -y update 5 | apt-get -y install nginx 6 | ufw allow 'Nginx HTTP' 7 | echo 'Hello World!' > /var/www/html/index.nginx-debian.html 8 | service nginx start 9 | -------------------------------------------------------------------------------- /0x0C-web_server/2-setup_a_domain_name: -------------------------------------------------------------------------------- 1 | tolucodes.tech 2 | -------------------------------------------------------------------------------- /0x0C-web_server/3-redirection: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Installs, configures, and starts the server 3 | apt-get update 4 | apt-get -y install nginx 5 | sudo ufw allow 'Nginx HTTP' 6 | mkdir -p /var/www/html/ 7 | sudo chmod -R 755 /var/www 8 | echo 'Hello World!' > /var/www/html/index.html 9 | SERVER_CONFIG=\ 10 | "server { 11 | listen 80 default_server; 12 | listen [::]:80 default_server; 13 | root /var/www/html; 14 | index index.html index.htm index.nginx-debian.html; 15 | server_name _; 16 | location / { 17 | try_files \$uri \$uri/ =404; 18 | } 19 | if (\$request_filename ~ redirect_me){ 20 | rewrite ^ https://sketchfab.com/bluepeno/models permanent; 21 | } 22 | }" 23 | 24 | bash -c "echo -e '$SERVER_CONFIG' > /etc/nginx/sites-enabled/default" 25 | 26 | if [ "$(pgrep -c nginx)" -le 0 ]; then 27 | service nginx start 28 | else 29 | service nginx restart 30 | fi 31 | -------------------------------------------------------------------------------- /0x0C-web_server/4-not_found_page_404: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # sets up a new 404 error page 3 | sudo apt-get update 4 | sudo apt-get install -y nginx 5 | echo "Hello World!" > index.html 6 | sudo mv index.html /var/www/html 7 | 8 | 9 | echo "Ceci n'est pas une page" > 404.html 10 | sudo mv 404.html /var/www/html 11 | echo "server { 12 | listen 80 default_server; 13 | listen [::]:80 default_server; 14 | 15 | root /var/www/html; 16 | index index.html; 17 | location /redirect_me { 18 | return 301 https://www.youtube.com/watch?v=QH2-TGUlwu4; 19 | } 20 | error_page 404 /404.html; 21 | location = /404.html{ 22 | internal; 23 | } 24 | }" > default 25 | sudo mv -f default /etc/nginx/sites-available/default 26 | sudo service nginx restart 27 | -------------------------------------------------------------------------------- /0x0C-web_server/7-puppet_install_nginx_web_server.pp: -------------------------------------------------------------------------------- 1 | # Installs a Nginx server 2 | 3 | exec {'install': 4 | provider => shell, 5 | command => 'sudo apt-get -y update ; sudo apt-get -y install nginx ; echo "Hello World!" | sudo tee /var/www/html/index.nginx-debian.html ; sudo sed -i "s/server_name _;/server_name _;\n\trewrite ^\/redirect_me https:\/\/github.com\/Tolulope05 permanent;/" /etc/nginx/sites-available/default ; sudo service nginx start', 6 | } 7 | -------------------------------------------------------------------------------- /0x0C-web_server/README.md: -------------------------------------------------------------------------------- 1 | # Web server 2 | 3 | In this project, I learned how web servers work and began using one. I was 4 | provided a personal server by ALX. I learned how to use `scp` 5 | and Fabric to transfer files to my server. Additionally, I completed a basic 6 | configuration of the server using Nginx. 7 | 8 | The server is accessible at [bdbnb.site](http://bdbnb.site). 9 | 10 | ## Tasks :page_with_curl: 11 | 12 | * **0. Transfer a file to your server** 13 | * [0-transfer_file](./0-transfer_file): Bash script that transfers a file 14 | from Holberton's client to a server. 15 | * Accepts four arguments: 16 | * The path of the file to be transferred. 17 | * The IP of the server to transfer the file to. 18 | * The username that `scp` connects with. 19 | * The path of the SSH privtae key that `scp` uses. 20 | * `scp` transfers the file to the user home directory `~/`. 21 | 22 | * **1. Install nginx web server** 23 | * [1-install_nginx_web_server](./1-install_nginx_web_server): Bash script 24 | that configures a new Ubuntu machine with Nginx. 25 | * Nginx listens on port 80. 26 | * When querying Nginx at its root `/` with a `curl` GET request, 27 | it returns a page containing the string `Holberton School`. 28 | 29 | * **2. Setup a domain name** 30 | * [2-setup_a_domain_name](./2-setup_a_domain_name): A text file containing 31 | the domain name set up for the server through Gandi. 32 | 33 | * **3. Redirection** 34 | * [3-redirection](./3-redirection): Bash script that configures a new Ubuntu 35 | machine with Nginx. 36 | * Setup is identical to [1-install_nginx_web_server](./1-install_nginx_web_server) 37 | plus: 38 | * The location `/redirect_me` returns a `301 Moved Permanently` redirection 39 | to another page. 40 | 41 | * **4. Not found page 404** 42 | * [4-not_found_page_404](./4-not_found_page_404): Bash script that configures 43 | a new Ubuntu machine with Nginx. 44 | * Setup is identical to [1-install_nginx_web_server](./1-install_nginx_web_server) 45 | plus: 46 | * Features a custom 404 page containing the string `Ceci n'est pas une page`. 47 | 48 | * **5. Design a beautiful 404 page** 49 | * A custom-designed 404 error page for my server, accessible at 50 | [bdbnb.site/404](http://bdbnb.site/404). 51 | 52 | * **6. Deploy fast, deploy well** 53 | * [fabfile.py](./fabfile.py): A Python Fabric configuration file defining 54 | the following functions: 55 | * `pack` 56 | * Usage: `fabric pack` 57 | * Creates a tar gzipped archive of the current directory named 58 | `holbertonwebapp.tar.gz` in the local directory. 59 | * `deploy` 60 | * Usage: `fabric -H deploy` 61 | * Uploads the archive `holbertonwebapp.tar.gz` to the `/tmp` 62 | directory of the remote server. 63 | * Creates the directory `/tmp/holbertonwebapp` in the remote server. 64 | * Untars `holbertonwebapp.tar.gz` in the `/tmp/holbertonwebapp` directory 65 | of the remote server. 66 | * `clean` 67 | * Deletes the archive `holbertonwebapp.tar.gz` in the local directory. 68 | -------------------------------------------------------------------------------- /0x0C-web_server/fabfile.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Fabfile defining functions to pack, deploy, and clean the 3 | # current directory to a remote server. 4 | from fabric import task 5 | 6 | 7 | @task 8 | def pack(c): 9 | """Create a tar gzipped archive of the current directory.""" 10 | c.run("touch holbertonwebapp.tar.gz") 11 | c.run("tar --exclude='*.tar.gz' -cvzf holbertonwebapp.tar.gz .") 12 | 13 | 14 | @task 15 | def deploy(c): 16 | """Upload the archive to the remote server in the /tmp/ directory.""" 17 | c.user = "ubuntu" 18 | c.put("holbertonwebapp.tar.gz", "/tmp") 19 | c.run("mkdir /tmp/holbertonwebapp") 20 | c.run("tar -C /tmp/holbertonwebapp -xzvf /tmp/holbertonwebapp.tar.gz") 21 | 22 | 23 | @task 24 | def clean(c): 25 | """Deletes holbertonwebapp.tar.gz on the local machine.""" 26 | c.run("rm holbertonwebapp.tar.gz") 27 | -------------------------------------------------------------------------------- /0x0D-web_stack_debugging_0/0-give_me_a_page: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # run apache on designated container 3 | 4 | echo "ServerName localhost" >> /etc/apache2.conf 5 | service apache2 start 6 | -------------------------------------------------------------------------------- /0x0D-web_stack_debugging_0/README.md: -------------------------------------------------------------------------------- 1 | # Web stack debugging #0 2 | 3 | This was the first in a series of web stack debugging projects. In these 4 | projects, I was given broken/bugged webstacks in isolated containers, 5 | and tasked with fixing the web stack to a working state. For each 6 | task, I wrote a script automating the commands necessary to fix the 7 | web stack. 8 | 9 | ## Tasks :page_with_curl: 10 | 11 | * **0. Give me a page!** 12 | * [0-give_me_a_page](./0-give_me_a_page): Bash script that runs Apache on a 13 | web server and gets it to respond to queries to the root. 14 | -------------------------------------------------------------------------------- /0x0E-web_stack_debugging_1/0-nginx_likes_port_80: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Configures an Nginx server to listen on port 80. 3 | 4 | rm /etc/nginx/sites-enabled/default 5 | ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default 6 | service nginx restart 7 | -------------------------------------------------------------------------------- /0x0E-web_stack_debugging_1/1-debugging_made_short: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Configures an Nginx server to listen on port 80. 3 | ln -sf /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default 4 | service nginx start 5 | kill "$(pgrep 'nginx' | head -1)" 6 | -------------------------------------------------------------------------------- /0x0E-web_stack_debugging_1/README.md: -------------------------------------------------------------------------------- 1 | # Web stack debugging #1 2 | 3 | This was the second in a series of web stack debugging projects. In these 4 | projects, I was given broken/bugged webstacks in isolated containers, 5 | and tasked with fixing the web stack to a working state. For each 6 | task, I wrote a script automating the commands necessary to fix the 7 | web stack. 8 | 9 | ## Tasks :page_with_curl: 10 | 11 | * **0. Nginx likes port 80** 12 | * [0-nginx_likes_port_80](./0-nginx_likes_port_80): Bash script that 13 | configures Nginx to run and listen to port 80 on all of a server's active IPv4's. 14 | 15 | * **1. Make it sweet and short** 16 | * [1-debugging_made_short](./1-debugging_made_short): Bash script that 17 | configures Nginx to listen to port 80 without running on all of a server's 18 | active IPv4's. 19 | -------------------------------------------------------------------------------- /0x0F-load_balancer/0-custom_http_response-header: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Script that configures Nginx server with a custom header 3 | apt-get -y update 4 | apt-get -y install nginx 5 | echo "Hello World!" > /var/www/html/index.nginx-debian.html 6 | echo "Ceci n'est pas une page" > /usr/share/nginx/html/custom_404.html 7 | sed -i "s/server_name _;/server_name _;\n\trewrite ^\/redirect_me https:\/\/github.com\/Tolulope05 permanent;\n\n\terror_page 404 \/custom_404.html;\n\tlocation = \/custom_404.html {\n\t\troot \/usr\/share\/nginx\/html;\n\t\tinternal;\n\t}/" /etc/nginx/sites-available/default 8 | sed -i "s/include \/etc\/nginx\/sites-enabled\/\*;/include \/etc\/nginx\/sites-enabled\/\*;\n\tadd_header X-Served-By \"$HOSTNAME\";/" /etc/nginx/nginx.conf 9 | service nginx start 10 | -------------------------------------------------------------------------------- /0x0F-load_balancer/1-install_load_balancer: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Installs and setup haproxy 3 | 4 | apt-get install -y software-properties-common 5 | add-apt-repository -y ppa:vbernat/haproxy-1.8 6 | apt-get -y update 7 | apt-get install -y haproxy=1.8.\* 8 | 9 | echo "ENABLED=1" > /etc/default/haproxy 10 | 11 | # Listen to web1 and web2 servers 12 | echo " 13 | listen load_balancer 14 | bind *:80 15 | mode http 16 | balance roundrobin 17 | option httpclose 18 | option forwardfor 19 | server 17272-web-01 44.200.83.158:80 check 20 | server 17272-web-02 3.237.16.226:80 check 21 | " >> /etc/haproxy/haproxy.cfg 22 | 23 | service haproxy start 24 | -------------------------------------------------------------------------------- /0x0F-load_balancer/2-puppet_custom_http_response-header.pp: -------------------------------------------------------------------------------- 1 | # Installs a Nginx server with custome HTTP header 2 | 3 | exec {'update': 4 | provider => shell, 5 | command => 'sudo apt-get -y update', 6 | before => Exec['install Nginx'], 7 | } 8 | 9 | exec {'install Nginx': 10 | provider => shell, 11 | command => 'sudo apt-get -y install nginx', 12 | before => Exec['add_header'], 13 | } 14 | 15 | exec { 'add_header': 16 | provider => shell, 17 | environment => ["HOST=${hostname}"], 18 | command => 'sudo sed -i "s/include \/etc\/nginx\/sites-enabled\/\*;/include \/etc\/nginx\/sites-enabled\/\*;\n\tadd_header X-Served-By \"$HOST\";/" /etc/nginx/nginx.conf', 19 | before => Exec['restart Nginx'], 20 | } 21 | 22 | exec { 'restart Nginx': 23 | provider => shell, 24 | command => 'sudo service nginx restart', 25 | } -------------------------------------------------------------------------------- /0x0F-load_balancer/README.md: -------------------------------------------------------------------------------- 1 | # Load Balancer -------------------------------------------------------------------------------- /0x10-https_ssl/0-world_wide_web: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Usage: ./1-world_wide_web 3 | # Display information about subdomains. 4 | 5 | domain_information () { 6 | line=$(dig "$2"."$1" | grep -A1 'ANSWER SECTION:' | tr '\t' '\n' | tail -2 | tr '\n' ' ') 7 | echo "$2 $line" | awk '{print "The subdomain " $1 " is a " $2 " record and points to " $3}' 8 | } 9 | 10 | if [ "$#" == 1 ] 11 | then 12 | domain_information "$1" "www" 13 | domain_information "$1" "lb-01" 14 | domain_information "$1" "web-01" 15 | domain_information "$1" "web-02" 16 | elif [ "$#" == 2 ] 17 | then 18 | domain_information "$1" "$2" 19 | fi 20 | -------------------------------------------------------------------------------- /0x10-https_ssl/1-haproxy_ssl_termination: -------------------------------------------------------------------------------- 1 | global 2 | log /dev/log local0 3 | maxconn 2048 4 | user haproxy 5 | group haproxy 6 | tune.ssl.default-dh-param 2048 7 | 8 | defaults 9 | log global 10 | mode http 11 | option httplog 12 | option dontlognull 13 | retries 3 14 | option redispatch 15 | timeout connect 5000 16 | timeout client 10000 17 | timeout server 10000 18 | option forwardfor 19 | option http-server-close 20 | 21 | frontend www-http 22 | bind 0.0.0.0:80 23 | reqadd X-Forwarded-Proto:\ http 24 | default_backend www-backend 25 | 26 | frontend www-https 27 | bind 0.0.0.0:443 ssl crt /etc/haproxy/certs/www.bdbnb.site.pem 28 | reqadd X-Forwarded-Proto:\ https 29 | acl letsencrypt-acl path_beg /.well-known/acme-challenge/ 30 | use_backend letsencrypt-backend if letsencrypt-acl 31 | default_backend www-backend 32 | 33 | backend www-backend 34 | balance roundrobin 35 | redirect scheme https if !{ ssl_fc } 36 | server 375-web-01 104.196.168.90:80 check 37 | server 375-web-02 35.196.46.172:80 check 38 | 39 | backend letsencrypt-backend 40 | server letsencrypt 127.0.0.1:54321 41 | -------------------------------------------------------------------------------- /0x10-https_ssl/100-redirect_http_to_https: -------------------------------------------------------------------------------- 1 | global 2 | log /dev/log local0 3 | maxconn 2048 4 | user haproxy 5 | group haproxy 6 | tune.ssl.default-dh-param 2048 7 | 8 | defaults 9 | log global 10 | mode http 11 | option httplog 12 | option dontlognull 13 | retries 3 14 | option redispatch 15 | timeout connect 5000 16 | timeout client 10000 17 | timeout server 10000 18 | option forwardfor 19 | option http-server-close 20 | 21 | frontend www-http 22 | bind 0.0.0.0:80 23 | reqadd X-Forwarded-Proto:\ http 24 | default_backend www-backend 25 | redirect scheme https code 301 if !{ ssl_fc } 26 | 27 | frontend www-https 28 | bind 0.0.0.0:443 ssl crt /etc/haproxy/certs/www.bdbnb.site.pem 29 | reqadd X-Forwarded-Proto:\ https 30 | acl letsencrypt-acl path_beg /.well-known/acme-challenge/ 31 | use_backend letsencrypt-backend if letsencrypt-acl 32 | default_backend www-backend 33 | 34 | backend www-backend 35 | balance roundrobin 36 | redirect scheme https if !{ ssl_fc } 37 | server 375-web-01 104.196.168.90:80 check 38 | server 375-web-02 35.196.46.172:80 check 39 | 40 | backend letsencrypt-backend 41 | server letsencrypt 127.0.0.1:54321 42 | -------------------------------------------------------------------------------- /0x10-https_ssl/README.md: -------------------------------------------------------------------------------- 1 | # HTTPS SSL 2 | 3 | In this project, I learned about the importance of HTTPS and how it works. I 4 | configured my HolbertonBnB web servers with `certbot` certificate and HAproxy 5 | SSL termination. 6 | 7 | ## Tasks :page_with_curl: 8 | 9 | 10 | * **0. World wide web** 11 | * [1-world_wide_web](./0-world_wide_web): Bash script that displays 12 | information about subdomains on my configured servers. 13 | * Usage: `./1-world_wide_web ` 14 | * Output: `The subdomain [SUB_DOMAIN] is a [RECORD_TYPE] record and 15 | points to [DESTINATION]` 16 | * If no `subdomain` parameter is passed, displays information about the 17 | subdomains `www`, `lb-01`, `web-01` and `web-02`, in that order. 18 | 19 | * **2. HAproxy SSL termination** 20 | * [2-haproxy_ssl_termination](./2-haproxy_ssl_termination): HAproxy 21 | configuration file that accepts encrypted SSL traffic for the subdomain 22 | `www.` on TCP port 443. 23 | 24 | * **3. No loophole in your website traffic** 25 | * [100-redirect_http_to_https](./100-redirect_http_to_https): HAproxy 26 | configuration file that automatically redirects HTTP traffic to HTTPS. 27 | -------------------------------------------------------------------------------- /0x11-what_happens_when_your_type_google_com_in_your_browser_and_press_enter/0-blog_post: -------------------------------------------------------------------------------- 1 | https://medium.com/@fakunletolulope05/what-happens-when-you-type-google-com-in-your-browser-and-press-enter-b91559c4178d 2 | -------------------------------------------------------------------------------- /0x11-what_happens_when_your_type_google_com_in_your_browser_and_press_enter/1-what_happen_when_diagram: -------------------------------------------------------------------------------- 1 | https://im.ge/i/1ecIxa 2 | -------------------------------------------------------------------------------- /0x11-what_happens_when_your_type_google_com_in_your_browser_and_press_enter/2-contribution-to_what-happens-when_github_answer: -------------------------------------------------------------------------------- 1 | https://github.com/alex/what-happens-when/pull/385 2 | -------------------------------------------------------------------------------- /0x11-what_happens_when_your_type_google_com_in_your_browser_and_press_enter/README.md: -------------------------------------------------------------------------------- 1 | # Web Infrastructure 2 | -------------------------------------------------------------------------------- /0x12-web_stack_debugging_2/0-iamsomeonelese: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Runs the whoami command under the user passed as argument. 3 | sudo -u "$1" whoami 4 | -------------------------------------------------------------------------------- /0x12-web_stack_debugging_2/1-run_nginx_as_nginx: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Fixes a web server to run Nginx as the nginx user listening on port 8080. 3 | sed -i "s/#user www-data/user nginx/" /etc/nginx/nginx.conf 4 | sed -i "s/80/8080/g" /etc/nginx/sites-available/default 5 | chmod 644 /etc/nginx/nginx.conf 6 | pkill apache2 7 | sudo -u nginx service nginx start 8 | -------------------------------------------------------------------------------- /0x12-web_stack_debugging_2/100-fix_in_7_lines_or_less: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Fixes a web server to run Nginx as the nginx user listening on port 8080. 3 | sed -i "s/#user www-data/user nginx/" /etc/nginx/nginx.conf 4 | sed -i "s/80/8080/g" /etc/nginx/sites-available/default 5 | chmod 644 /etc/nginx/nginx.conf 6 | pkill apache2 7 | sudo -u nginx service nginx start 8 | -------------------------------------------------------------------------------- /0x12-web_stack_debugging_2/README.md: -------------------------------------------------------------------------------- 1 | # Web stack debugging #2 2 | 3 | This was the third in a series of web stack debugging projects. In these 4 | projects, I was given broken/bugged webstacks in isolated containers, 5 | and tasked with fixing the web stack to a working state. For each 6 | task, I wrote a script automating the commands necessary to fix the 7 | web stack. 8 | 9 | ## Tasks :page_with_curl: 10 | 11 | * **0. Run software as another user** 12 | * [0-iamsomeonelese](./0-iamsomeonelese): Bash script that runs the command 13 | `whoami` under the user passed as argument. 14 | * Usage: `./0-iamsomeonelese ` 15 | 16 | * **1. Run Nginx as Nginx** 17 | * [1-run_nginx_as_nginx](./1-run_nginx_as_nginx): Bash script that fixes a 18 | web server to run Nginx listening on port `8080` as the `nginx` user. 19 | 20 | * **2. 7 lines or less** 21 | * [100-fix_in_7_lines_or_less](./100-fix_in_7_lines_or_less): Bash script 22 | that fixes a web server to run Nginx listening on port `8080` as the `nginx` 23 | user. 24 | * 7 lines long. 25 | -------------------------------------------------------------------------------- /0x13-firewall/0-block_all_incoming_traffic_but: -------------------------------------------------------------------------------- 1 | sudo apt-get install ufw 2 | sudo ufw status 3 | sudo ufw enable -y 4 | sudo ufw default deny incoming -y 5 | sudo ufw default allow outgoing -y 6 | sudo ufw allow 22/tcp 7 | sudo ufw allow 443/tcp 8 | sudo ufw allow 80/tcp 9 | -------------------------------------------------------------------------------- /0x13-firewall/100-port_forwarding: -------------------------------------------------------------------------------- 1 | # 2 | # rules.before 3 | # 4 | # Rules that should be run before the ufw command line added rules. Custom 5 | # rules should be added to one of these chains: 6 | # ufw-before-input 7 | # ufw-before-output 8 | # ufw-before-forward 9 | # 10 | 11 | *nat 12 | :PREROUTING ACCEPT [0:0] 13 | -A PREROUTING -p tcp --dport 8080 -j REDIRECT --to-port 80 14 | 15 | # Don't delete these required lines, otherwise there will be errors 16 | *filter 17 | :ufw-before-input - [0:0] 18 | :ufw-before-output - [0:0] 19 | :ufw-before-forward - [0:0] 20 | :ufw-not-local - [0:0] 21 | # End required lines 22 | 23 | 24 | # allow all on loopback 25 | -A ufw-before-input -i lo -j ACCEPT 26 | -A ufw-before-output -o lo -j ACCEPT 27 | 28 | # quickly process packets for which we already have a connection 29 | -A ufw-before-input -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT 30 | -A ufw-before-output -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT 31 | -A ufw-before-forward -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT 32 | 33 | # drop INVALID packets (logs these in loglevel medium and higher) 34 | -A ufw-before-input -m conntrack --ctstate INVALID -j ufw-logging-deny 35 | -A ufw-before-input -m conntrack --ctstate INVALID -j DROP 36 | 37 | # ok icmp codes for INPUT 38 | -A ufw-before-input -p icmp --icmp-type destination-unreachable -j ACCEPT 39 | -A ufw-before-input -p icmp --icmp-type source-quench -j ACCEPT 40 | -A ufw-before-input -p icmp --icmp-type time-exceeded -j ACCEPT 41 | -A ufw-before-input -p icmp --icmp-type parameter-problem -j ACCEPT 42 | -A ufw-before-input -p icmp --icmp-type echo-request -j ACCEPT 43 | 44 | # ok icmp code for FORWARD 45 | -A ufw-before-forward -p icmp --icmp-type destination-unreachable -j ACCEPT 46 | -A ufw-before-forward -p icmp --icmp-type source-quench -j ACCEPT 47 | -A ufw-before-forward -p icmp --icmp-type time-exceeded -j ACCEPT 48 | -A ufw-before-forward -p icmp --icmp-type parameter-problem -j ACCEPT 49 | -A ufw-before-forward -p icmp --icmp-type echo-request -j ACCEPT 50 | 51 | # allow dhcp client to work 52 | -A ufw-before-input -p udp --sport 67 --dport 68 -j ACCEPT 53 | 54 | # 55 | # ufw-not-local 56 | # 57 | -A ufw-before-input -j ufw-not-local 58 | 59 | # if LOCAL, RETURN 60 | -A ufw-not-local -m addrtype --dst-type LOCAL -j RETURN 61 | 62 | # if MULTICAST, RETURN 63 | -A ufw-not-local -m addrtype --dst-type MULTICAST -j RETURN 64 | 65 | # if BROADCAST, RETURN 66 | -A ufw-not-local -m addrtype --dst-type BROADCAST -j RETURN 67 | 68 | # all other non-local packets are dropped 69 | -A ufw-not-local -m limit --limit 3/min --limit-burst 10 -j ufw-logging-deny 70 | -A ufw-not-local -j DROP 71 | 72 | # allow MULTICAST mDNS for service discovery (be sure the MULTICAST line above 73 | # is uncommented) 74 | -A ufw-before-input -p udp -d 224.0.0.251 --dport 5353 -j ACCEPT 75 | 76 | # allow MULTICAST UPnP for service discovery (be sure the MULTICAST line above 77 | # is uncommented) 78 | -A ufw-before-input -p udp -d 239.255.255.250 --dport 1900 -j ACCEPT 79 | 80 | # don't delete the 'COMMIT' line or these rules won't be processed 81 | COMMIT 82 | -------------------------------------------------------------------------------- /0x13-firewall/README.md: -------------------------------------------------------------------------------- 1 | # Firewall 2 | 3 | In this project, I used `ufw` to configure firewalls on my issued web servers. 4 | 5 | ## Tasks :page_with_curl: 6 | 7 | * **0. Block all incoming traffic but** 8 | * [0-block_all_incoming_traffic_but](./0-block_all_incoming_traffic_but): Bash 9 | script that installs a `ufw` firewall to block all incoming traffic except for 10 | ports `22`, `443` and `80` on a web server. 11 | 12 | * **2. Port forwarding** 13 | * [100-port_forwarding](./100-port_forwarding): `ufw` configuration file that 14 | configures a firewall to redirect port `8080/TCP` to port `80/TCP`. 15 | -------------------------------------------------------------------------------- /0x14-mysql/4-mysql_configuration_primary: -------------------------------------------------------------------------------- 1 | # 2 | # The MySQL Server configuration file. 3 | # 4 | 5 | [mysqld] 6 | pid-file = /var/run/mysqld/mysqld.pid 7 | socket = /var/run/mysqld/mysqld.sock 8 | datadir = /var/lib/mysql 9 | log-error = /var/log/mysql/error.log 10 | # By default we only accept connections from localhost 11 | bind-address = 0.0.0.0 12 | # Disabling symbolic-links is recommended to prevent assorted security risks 13 | symbolic-links=0 14 | # Distinguish servers in a replication setup 15 | server-id = 1 16 | # MySQL's Binary Log File 17 | log_bin = /var/log/mysql/mysql-bin.log 18 | # Database we want to replicate 19 | binlog_do_db = tyrell_corp 20 | -------------------------------------------------------------------------------- /0x14-mysql/4-mysql_configuration_replica: -------------------------------------------------------------------------------- 1 | # 2 | # The MySQL Server configuration file. 3 | # 4 | 5 | [mysqld] 6 | pid-file = /var/run/mysqld/mysqld.pid 7 | socket = /var/run/mysqld/mysqld.sock 8 | datadir = /var/lib/mysql 9 | log-error = /var/log/mysql/error.log 10 | # By default we only accept connections from localhost 11 | bind-address = 127.0.0.1 12 | # Disabling symbolic-links is recommended to prevent assorted security risks 13 | symbolic-links=0 14 | # Distinguish servers in a replication setup 15 | server-id = 2 16 | # MySQL's Binary Log File 17 | log_bin = /var/log/mysql/mysql-bin.log 18 | # Database we want to replicate 19 | binlog_do_db = tyrell_corp 20 | # Defines the location of the replica's relay log 21 | relay-log = /var/log/mysql/mysql-relay-bin.log 22 | -------------------------------------------------------------------------------- /0x14-mysql/5-mysql_backup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # backup and compress my databases 3 | 4 | # variables 5 | day=$(date +"%d") 6 | month=$(date +"%m") 7 | year=$(date +"%Y") 8 | file_name="$day-$month-$year.tar.gz" 9 | 10 | mysqldump --all-databases -u root --password="$1" > backup.sql 11 | tar -czvf "$file_name" backup.sql 12 | -------------------------------------------------------------------------------- /0x14-mysql/README.md: -------------------------------------------------------------------------------- 1 | # Mysql 2 | 3 | This project involved learning how to configure database servers in a 4 | primary-replica model. I configured the two servers provided to me by 5 | ALX in a MySQL primary-replica setup with a dummy database, and wrote 6 | a Bash script to automate generation of database backups. 7 | 8 | ## Tasks :page_with_curl: 9 | 10 | * [4-mysql_configuration_primary](./4-mysql_configuration_primary): The MySQL 11 | `my.conf` configuration file used to set up my first server as a primary database 12 | server on the database `tyrell_corp`. 13 | 14 | * [4-mysql_configuration_replica](./4-mysql_configuration_replica): The MySQL 15 | `my.conf` configuration file used to set up my second server as the replica 16 | database server on the database `tyrell_corp`. 17 | 18 | * [5-mysql_backup](./5-mysql_backup): Bash script that generates a compressed 19 | `tar.gz` archive from a MySQL dump. 20 | * Usage: `./5-mysql_backup ` 21 | * Generates a dump containing all MySQL databases on the root server. 22 | * Names the resulting tar archive in the format `day-month-year.tar.gz`. 23 | -------------------------------------------------------------------------------- /0x15-api/0-gather_data_from_an_API.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Returns to-do list information for a given employee ID.""" 3 | import requests 4 | import sys 5 | 6 | if __name__ == "__main__": 7 | url = "https://jsonplaceholder.typicode.com/" 8 | user = requests.get(url + "users/{}".format(sys.argv[1])).json() 9 | todos = requests.get(url + "todos", params={"userId": sys.argv[1]}).json() 10 | 11 | completed = [t.get("title") for t in todos if t.get("completed") is True] 12 | print("Employee {} is done with tasks({}/{}):".format( 13 | user.get("name"), len(completed), len(todos))) 14 | [print("\t {}".format(c)) for c in completed] 15 | -------------------------------------------------------------------------------- /0x15-api/1-export_to_CSV.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Exports to-do list information for a given employee ID to CSV format.""" 3 | import csv 4 | import requests 5 | import sys 6 | 7 | if __name__ == "__main__": 8 | user_id = sys.argv[1] 9 | url = "https://jsonplaceholder.typicode.com/" 10 | user = requests.get(url + "users/{}".format(user_id)).json() 11 | username = user.get("username") 12 | todos = requests.get(url + "todos", params={"userId": user_id}).json() 13 | 14 | with open("{}.csv".format(user_id), "w", newline="") as csvfile: 15 | writer = csv.writer(csvfile, quoting=csv.QUOTE_ALL) 16 | [writer.writerow( 17 | [user_id, username, t.get("completed"), t.get("title")] 18 | ) for t in todos] 19 | -------------------------------------------------------------------------------- /0x15-api/2-export_to_JSON.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Exports to-do list information for a given employee ID to JSON format.""" 3 | import json 4 | import requests 5 | import sys 6 | 7 | if __name__ == "__main__": 8 | user_id = sys.argv[1] 9 | url = "https://jsonplaceholder.typicode.com/" 10 | user = requests.get(url + "users/{}".format(user_id)).json() 11 | username = user.get("username") 12 | todos = requests.get(url + "todos", params={"userId": user_id}).json() 13 | 14 | with open("{}.json".format(user_id), "w") as jsonfile: 15 | json.dump({user_id: [{ 16 | "task": t.get("title"), 17 | "completed": t.get("completed"), 18 | "username": username 19 | } for t in todos]}, jsonfile) 20 | -------------------------------------------------------------------------------- /0x15-api/3-dictionary_of_list_of_dictionaries.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Exports to-do list information of all employees to JSON format.""" 3 | import json 4 | import requests 5 | 6 | if __name__ == "__main__": 7 | url = "https://jsonplaceholder.typicode.com/" 8 | users = requests.get(url + "users").json() 9 | 10 | with open("todo_all_employees.json", "w") as jsonfile: 11 | json.dump({ 12 | u.get("id"): [{ 13 | "task": t.get("title"), 14 | "completed": t.get("completed"), 15 | "username": u.get("username") 16 | } for t in requests.get(url + "todos", 17 | params={"userId": u.get("id")}).json()] 18 | for u in users}, jsonfile) 19 | -------------------------------------------------------------------------------- /0x15-api/README.md: -------------------------------------------------------------------------------- 1 | # API 2 | Email: Messsagelordwill@gmail.com 3 | ##This project was further practice in working with API's. I collected data from the 4 | [JSONPlaceholder REST API](https://jsonplaceholder.typicode.com/), and learned how 5 | to export it to either CSV or JSON format. 6 | 7 | ## Tasks :page_with_curl: 8 | 9 | * **0. Gather data from an API** 10 | * [0-gather_data_from_an_API.py](./0-gather_data_from_an_API.py): Python script 11 | that returns information on the to-do list progress of a given employee ID. 12 | * Usage: `python3 0-gather_data_from_an_API.py `. 13 | * Output: `Employee is done with tasks(<# completed tasks>/):` 14 | 15 | * **1. Export to CSV** 16 | * [1-export_to_CSV.py](./1-export_to_CSV.py): Python script exports to-do list 17 | information of a given employee ID to CSV format. 18 | * Usage: `python3 1-export_to_CSV.py ` 19 | * File name: `.csv`. 20 | * Format: `"","","",""`. 21 | 22 | * **2. Export to JSON** 23 | * [2-export_to_JSON.py](./2-export_to_JSON.py): Python script that exports 24 | to-do list information of a given employee ID to JSON format. 25 | * Usage: `python3 2-export_to_JSON.py ` 26 | * File name: `.json` 27 | * Format: `{ "": [ {"task": "", "completed": , "username": ""}}, ... ]}` 28 | 29 | * **3. Dictionary of list of dictionaries** 30 | * [3-dictionary_of_list_of_dictionaries.py](./3-dictionary_of_list_of_dictionaries.py): 31 | Python script that exports to-do list information for all employees to JSON format. 32 | * Usage: `python3 3-dictionary_of_list_of_dictionaries.py` 33 | * File name: `todo_all_employees.json` 34 | * Format: `{ "": [ {"username": "", "task": "", "completed": }, {"username": "", "task": "", "completed": }, ... ], "": [ {"username": "", "task": "", "completed": }, {"username": "", "task": "", "completed": }, ... ]}` 35 | -------------------------------------------------------------------------------- /0x16-api_advanced/0-subs.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Function to query subscribers on a given Reddit subreddit.""" 3 | import requests 4 | 5 | 6 | def number_of_subscribers(subreddit): 7 | """Return the total number of subscribers on a given subreddit.""" 8 | url = "https://www.reddit.com/r/{}/about.json".format(subreddit) 9 | headers = { 10 | "User-Agent": "linux:0x16.api.advanced:v1.0.0 (by /u/bdov_)" 11 | } 12 | response = requests.get(url, headers=headers, allow_redirects=False) 13 | if response.status_code == 404: 14 | return 0 15 | results = response.json().get("data") 16 | return results.get("subscribers") 17 | -------------------------------------------------------------------------------- /0x16-api_advanced/1-top_ten.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Function to print hot posts on a given Reddit subreddit.""" 3 | import requests 4 | 5 | 6 | def top_ten(subreddit): 7 | """Print the titles of the 10 hottest posts on a given subreddit.""" 8 | url = "https://www.reddit.com/r/{}/hot/.json".format(subreddit) 9 | headers = { 10 | "User-Agent": "linux:0x16.api.advanced:v1.0.0 (by /u/bdov_)" 11 | } 12 | params = { 13 | "limit": 10 14 | } 15 | response = requests.get(url, headers=headers, params=params, 16 | allow_redirects=False) 17 | if response.status_code == 404: 18 | print("None") 19 | return 20 | results = response.json().get("data") 21 | [print(c.get("data").get("title")) for c in results.get("children")] 22 | -------------------------------------------------------------------------------- /0x16-api_advanced/100-count.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Function to count words in all hot posts of a given Reddit subreddit.""" 3 | import requests 4 | 5 | 6 | def count_words(subreddit, word_list, instances={}, after="", count=0): 7 | """Prints counts of given words found in hot posts of a given subreddit. 8 | 9 | Args: 10 | subreddit (str): The subreddit to search. 11 | word_list (list): The list of words to search for in post titles. 12 | instances (obj): Key/value pairs of words/counts. 13 | after (str): The parameter for the next page of the API results. 14 | count (int): The parameter of results matched thus far. 15 | """ 16 | url = "https://www.reddit.com/r/{}/hot/.json".format(subreddit) 17 | headers = { 18 | "User-Agent": "linux:0x16.api.advanced:v1.0.0 (by /u/bdov_)" 19 | } 20 | params = { 21 | "after": after, 22 | "count": count, 23 | "limit": 100 24 | } 25 | response = requests.get(url, headers=headers, params=params, 26 | allow_redirects=False) 27 | try: 28 | results = response.json() 29 | if response.status_code == 404: 30 | raise Exception 31 | except Exception: 32 | print("") 33 | return 34 | 35 | results = results.get("data") 36 | after = results.get("after") 37 | count += results.get("dist") 38 | for c in results.get("children"): 39 | title = c.get("data").get("title").lower().split() 40 | for word in word_list: 41 | if word.lower() in title: 42 | times = len([t for t in title if t == word.lower()]) 43 | if instances.get(word) is None: 44 | instances[word] = times 45 | else: 46 | instances[word] += times 47 | 48 | if after is None: 49 | if len(instances) == 0: 50 | print("") 51 | return 52 | instances = sorted(instances.items(), key=lambda kv: (-kv[1], kv[0])) 53 | [print("{}: {}".format(k, v)) for k, v in instances] 54 | else: 55 | count_words(subreddit, word_list, instances, after, count) 56 | -------------------------------------------------------------------------------- /0x16-api_advanced/2-recurse.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Function to query a list of all hot posts on a given Reddit subreddit.""" 3 | import requests 4 | 5 | 6 | def recurse(subreddit, hot_list=[], after="", count=0): 7 | """Returns a list of titles of all hot posts on a given subreddit.""" 8 | url = "https://www.reddit.com/r/{}/hot/.json".format(subreddit) 9 | headers = { 10 | "User-Agent": "linux:0x16.api.advanced:v1.0.0 (by /u/bdov_)" 11 | } 12 | params = { 13 | "after": after, 14 | "count": count, 15 | "limit": 100 16 | } 17 | response = requests.get(url, headers=headers, params=params, 18 | allow_redirects=False) 19 | if response.status_code == 404: 20 | return None 21 | 22 | results = response.json().get("data") 23 | after = results.get("after") 24 | count += results.get("dist") 25 | for c in results.get("children"): 26 | hot_list.append(c.get("data").get("title")) 27 | 28 | if after is not None: 29 | return recurse(subreddit, hot_list, after, count) 30 | return hot_list 31 | -------------------------------------------------------------------------------- /0x16-api_advanced/README.md: -------------------------------------------------------------------------------- 1 | # API advanced 2 | 3 | I continued to practice querying API's in this advanced project, this time 4 | working with the Reddit API. 5 | 6 | ## Tests :heavy_check_mark: 7 | 8 | * [tests](./tests): Folder of test files for all tasks. Provided by Holberton 9 | School. 10 | 11 | ## Function Prototypes :floppy_disk: 12 | 13 | Prototypes for functions written in this project: 14 | 15 | | File | Prototype | 16 | | -------------- | --------------------------------------- | 17 | | `0-subs.py` | `def number_of_subscribers(subreddit)` | 18 | | `1-top_ten.py` | `def top_ten(subreddit)` | 19 | | `2-recurse.py` | `def recurse(subreddit, hot_list=[])` | 20 | | `100-count.py` | `def count_words(subreddit, word_list)` | 21 | 22 | ## Tasks :page_with_curl: 23 | 24 | * **0. How many subs?** 25 | * [0-subs.py](./0-subs.py): Python function that returns the total number of 26 | subscribers for a given subreddit. 27 | * Returns `0` if an invalid subreddit is given. 28 | 29 | * **1. Top Ten** 30 | * [1-top_ten.py](./1-top_ten.py): Python function that prints the top ten 31 | hottest posts for a given subreddit. 32 | * Prints `None` if an invalid subreddit is given. 33 | 34 | * **2. Recurse it!** 35 | * [2-recurse.py](./2-recurse.py): Python function that recursively returns a 36 | list of titles for all hot articles on a given subreddit. 37 | * Returns `None` if no results are found on the given subreddit. 38 | 39 | * **3. Count it!** 40 | * [100-count.py](./100-count.py): Python function that recursively prints a 41 | sorted count of given keywords parsed from titles of all hot articles on a given 42 | subreddit. 43 | * Keywords are case-insensitive and delimited by spaces. 44 | * Results are printed in descending order by count. 45 | * Words with identical counts are sorted alphabetically. 46 | * Words with no matches are skipped. 47 | * Results are based on the number of times a keyword appears - ie., 48 | `java java java` counts as three separate instances of `java`. 49 | -------------------------------------------------------------------------------- /0x16-api_advanced/tests/0-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | import sys 3 | 4 | 5 | if __name__ == '__main__': 6 | number_of_subscribers = __import__('0-subs').number_of_subscribers 7 | if len(sys.argv) < 2: 8 | print("Please pass an argument for the subreddit to search.") 9 | else: 10 | print("{:d}".format(number_of_subscribers(sys.argv[1]))) 11 | -------------------------------------------------------------------------------- /0x16-api_advanced/tests/1-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | import sys 3 | 4 | if __name__ == '__main__': 5 | top_ten = __import__('1-top_ten').top_ten 6 | if len(sys.argv) < 2: 7 | print("Please pass an argument for the subreddit to search.") 8 | else: 9 | top_ten(sys.argv[1]) 10 | -------------------------------------------------------------------------------- /0x16-api_advanced/tests/100-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Contains the count_words function""" 3 | import requests 4 | 5 | 6 | def count_words(subreddit, word_list, found_list=[], after=None): 7 | '''Prints counts of given words found in hot posts of a given subreddit. 8 | 9 | Args: 10 | subreddit (str): The subreddit to search. 11 | word_list (list): The list of words to search for in post titles. 12 | found_list (obj): Key/value pairs of words/counts. 13 | after (str): The parameter for the next page of the API results. 14 | ''' 15 | user_agent = {'User-agent': 'test45'} 16 | posts = requests.get('http://www.reddit.com/r/{}/hot.json?after={}' 17 | .format(subreddit, after), headers=user_agent) 18 | if after is None: 19 | word_list = [word.lower() for word in word_list] 20 | 21 | if posts.status_code == 200: 22 | posts = posts.json()['data'] 23 | aft = posts['after'] 24 | posts = posts['children'] 25 | for post in posts: 26 | title = post['data']['title'].lower() 27 | for word in title.split(' '): 28 | if word in word_list: 29 | found_list.append(word) 30 | if aft is not None: 31 | count_words(subreddit, word_list, found_list, aft) 32 | else: 33 | result = {} 34 | for word in found_list: 35 | if word.lower() in result.keys(): 36 | result[word.lower()] += 1 37 | else: 38 | result[word.lower()] = 1 39 | for key, value in sorted(result.items(), key=lambda item: item[1], 40 | reverse=True): 41 | print('{}: {}'.format(key, value)) 42 | else: 43 | return 44 | -------------------------------------------------------------------------------- /0x16-api_advanced/tests/2-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | import sys 3 | 4 | if __name__ == '__main__': 5 | recurse = __import__('2-recurse').recurse 6 | if len(sys.argv) < 2: 7 | print("Please pass an argument for the subreddit to search.") 8 | else: 9 | result = recurse(sys.argv[1]) 10 | if result is not None: 11 | print(len(result)) 12 | else: 13 | print("None") 14 | -------------------------------------------------------------------------------- /0x17-web_stack_debugging_3/0-strace_is_your_friend.pp: -------------------------------------------------------------------------------- 1 | # automated puppet fix (to find out why Apache is returning a 500 error) 2 | 3 | exec { 'Fix wordpress site': 4 | command => 'sudo sed -i "s/.phpp/.php/" /var/www/html/wp-settings.php', 5 | provider => shell, 6 | } 7 | -------------------------------------------------------------------------------- /0x17-web_stack_debugging_3/README.md: -------------------------------------------------------------------------------- 1 | ### 0x17. Web stack debugging #3 2 | -------------------------------------------------------------------------------- /0x18-webstack_monitoring/0-setup_datadog: -------------------------------------------------------------------------------- 1 | 1ceaf0c1f0ee88cf1bee1856da907a0c 2 | b230425118512569ad13f279797d83ec6573622b 3 | -------------------------------------------------------------------------------- /0x18-webstack_monitoring/2-setup_datadog: -------------------------------------------------------------------------------- 1 | srv-5ud-a2h -------------------------------------------------------------------------------- /0x18-webstack_monitoring/README.md: -------------------------------------------------------------------------------- 1 | # Webstack monitoring -------------------------------------------------------------------------------- /0x1A-application_server/2-app_server-nginx_config: -------------------------------------------------------------------------------- 1 | # Configures Nginx to serve the route /airbnb-onepage/ from AirBnB_clone_v2. 2 | 3 | server { 4 | # Listen on port 80 5 | listen 80 default_server; 6 | listen [::]:80 default_server ipv6only=on; 7 | 8 | # Use IP of server as domain name 9 | server_name 104.196.168.90; 10 | 11 | # Customize HTTP response header 12 | add_header X-Served-By 375-web-01; 13 | 14 | # Serve /airbnb-onepage/ route from AirBnB_clone_v2 15 | location = /airbnb-onepage/ { 16 | proxy_pass http://127.0.0.1:5000/airbnb-onepage/; 17 | } 18 | 19 | # 404 error page 20 | error_page 404 /404.html; 21 | location /404 { 22 | root /var/www/html; 23 | internal; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /0x1A-application_server/3-app_server-nginx_config: -------------------------------------------------------------------------------- 1 | # Configures Nginx to serve the /number_odd_or_even/ route on AirBnB_clone_v2. 2 | 3 | server { 4 | # Listen on port 80 5 | listen 80 default_server; 6 | listen [::]:80 default_server ipv6only=on; 7 | 8 | # Use server IP as domain name 9 | server_name 104.196.168.90; 10 | 11 | # Customize HTTP response header 12 | add_header X-Served-By 375-web-01; 13 | 14 | # Serve /airbnb-onepage/ route on AirBnB_clone_v2 15 | location = /airbnb-onepage/ { 16 | proxy_pass http://127.0.0.1:5000/airbnb-onepage/; 17 | } 18 | 19 | # Serve /number_odd_or_even/ route on AirBnB_clone_v2 20 | location ~ /airbnb-dynamic/number_odd_or_even/(\d+)$ { 21 | proxy_pass http://127.0.0.1:5001/number_odd_or_even/$1; 22 | } 23 | 24 | # 404 error page 25 | error_page 404 /404.html; 26 | location /404 { 27 | root /var/www/html; 28 | internal; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /0x1A-application_server/4-app_server-nginx_config: -------------------------------------------------------------------------------- 1 | # Configures Nginx to serve the AirBnB_clone_v3 API. 2 | 3 | server { 4 | # Listen on port 80 5 | listen 80 default_server; 6 | listen [::]:80 default_server ipv6only=on; 7 | 8 | # Use server IP as domain name 9 | server_name 104.196.168.90; 10 | 11 | # Customize HTTP response header 12 | add_header X-Served-By 375-web-01; 13 | 14 | # Serve /airbnb-onepage/ route on AirBnB_clone_v3 15 | location = /airbnb-onepage/ { 16 | proxy_pass http://127.0.0.1:5000/airbnb-onepage/; 17 | } 18 | 19 | # Serve /number_odd_or_even/ route on AirBnB_clone_v3 20 | location ~ /airbnb-dynamic/number_odd_or_even/(\d+)$ { 21 | proxy_pass http://127.0.0.1:5001/number_odd_or_even/$1; 22 | } 23 | 24 | # Serve API on AirBnB_clone_v3 25 | location /api { 26 | proxy_pass http://127.0.0.1:5002/api; 27 | } 28 | 29 | # 404 error page 30 | error_page 404 /404.html; 31 | location /404 { 32 | root /var/www/html; 33 | internal; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /0x1A-application_server/4-reload_gunicorn_no_downtime: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Gracefully reloads Gunicorn. 3 | 4 | ps aux | grep gunicorn | awk '{ print $2 }' | xargs kill -HUP 5 | -------------------------------------------------------------------------------- /0x1A-application_server/5-app_server-nginx_config: -------------------------------------------------------------------------------- 1 | # Configures Nginx to serve the complete AirBnB_clone_v4 application. 2 | 3 | server { 4 | # Listen on port 80. 5 | listen 80 default_server; 6 | listen [::]:80 default_server ipv6only=on; 7 | 8 | # Use server IP as domain name 9 | server_name 104.196.168.90; 10 | 11 | # Customize HTTP response header 12 | add_header X-Served-By 375-web-01; 13 | 14 | # Serve /airbnb-onepage/ route on AirBnB_clone_v2 15 | location = /airbnb-onepage/ { 16 | proxy_pass http://127.0.0.1:5000/airbnb-onepage/; 17 | } 18 | 19 | # Serve /number_odd_or_even/ route on AirBnB_clone_v2 20 | location ~ /airbnb-dynamic/number_odd_or_even/(\d+)$ { 21 | proxy_pass http://127.0.0.1:5001/number_odd_or_even/$1; 22 | } 23 | 24 | # Serve AirBnB_clone_v3 API 25 | location /api { 26 | proxy_pass http://127.0.0.1:5002/api; 27 | } 28 | 29 | # Configure /2-hbnb route of AirBnB_clone_v4 as root location 30 | location / { 31 | proxy_pass http://127.0.0.1:5003/2-hbnb; 32 | } 33 | 34 | # Serve static content for AirBnB_clone_v4 35 | location /static { 36 | proxy_pass http://127.0.0.1:5003; 37 | } 38 | 39 | # 404 error page 40 | error_page 404 /404.html; 41 | location /404 { 42 | root /var/www/html; 43 | internal; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /0x1A-application_server/README.md: -------------------------------------------------------------------------------- 1 | # Application server 2 | 3 | This was the application deployment project for our AirBnB clone. In this 4 | project, I configured Nginx on the web servers provided me by Holberton School 5 | to serve a WSGI Flask app running through Gunicorn. Additionally, I set up an 6 | Upstart script to keep the application running on server reboots. 7 | 8 | ## Tasks :page_with_curl: 9 | 10 | * **0. Set up development with Python** 11 | * In this task, I configured the file `web_flask/0-hello_route.py` from my 12 | [AirBnB_clone_v2](https://github.com/bdbaraban/AirBnB_clone_v2) to serve content 13 | on the route `/airbnb-onepage/`, running on port `5000`. 14 | 15 | * **1. Set up production with Gunicorn** 16 | * This task involved setting up a production environment, installing and configuring 17 | Gunicorn to serve the same file from task 0. 18 | 19 | * **2. Serve a page with Nginx** 20 | * [2-app_server-nginx_config](./2-app_server-nginx_config): Nginx configuration file 21 | proxying requests on the route `/airbnb-onepage/` to the Gunicorn app running on 22 | port `5000`. 23 | 24 | * **3. Add a route with query parameters** 25 | * [3-app_server-nginx_config](./3-app_server-nginx_config): Nginx configuration file 26 | proxying requests on the route `/airbnb-dynamic/number_odd_or_even/` to the 27 | Gunicorn app running on port `5000`. 28 | 29 | * **4. Let's do this for your API** 30 | * In this task, I configured the API from my [AirBnB_clone_v3](./https://github.com/Ostoyae/AirBnB_clone_v3) to run on Gunicorn. 31 | * [4-app_server-nginx_config](./4-app_server-nginx_config): Nginx configuration file 32 | that proxies requests on the AirBnB API to the corresponding Gunicorn app. 33 | 34 | * **5. Serve your AirBnB clone** 35 | * In this task, I configured the complete AirBnB app from [AirBnB_clone_v4](https://github.com/bdbaraban/AirBnB_clone_v4) to run on Gunicorn and be served through Nginx. 36 | * [5-app_server-nginx_config](./5-app_server-nginx_config): Nginx configuration file 37 | configured to serve the static assets from `web_dynamic/static/` on the Gunicorn AirBnB 38 | app. 39 | 40 | * **6. Deploy it** 41 | * [gunicorn.conf](./gunicorn.conf): Configuration file for an Upstart script that starts a 42 | Gunicorn process bounded to port 5003 that serves the content from task 5. 43 | * The Gunicorn process spawns three worker processes and logs errors to `/tmp/airbnb-error.log`, 44 | access to `/tmp/airbnb-access.log`. 45 | 46 | * **7. No service interruption** 47 | * [4-reload_gunicorn_no_downtime](./4-reload_gunicorn_no_downtime): Bash script that gracefully 48 | reloads Gunicorn. 49 | -------------------------------------------------------------------------------- /0x1A-application_server/gunicorn.conf: -------------------------------------------------------------------------------- 1 | description "Gunicorn application server running AirBnB_clone_v4" 2 | author "Brennan D Baraban" 3 | 4 | start on runlevel [2345] 5 | stop on runlevel [!2345] 6 | 7 | respawn 8 | setuid ubuntu 9 | setgid www-data 10 | 11 | chdir /home/ubuntu/AirBnB_clone_v4 12 | exec gunicorn --workers 3 --bind 0.0.0.0:5003 web_dynamic.2-hbnb:app >> /tmp/airbnb-access.log 2> /tmp/airbnb-error.logirbnb-access.log 13 | -------------------------------------------------------------------------------- /0x1B-web_stack_debugging_4/0-the_sky_is_the_limit_not.pp: -------------------------------------------------------------------------------- 1 | # Fix problem of high amount of requests 2 | 3 | exec {'replace': 4 | provider => shell, 5 | command => 'sudo sed -i "s/ULIMIT=\"-n 15\"/ULIMIT=\"-n 4096\"/" /etc/default/nginx', 6 | before => Exec['restart'], 7 | } 8 | 9 | exec {'restart': 10 | provider => shell, 11 | command => 'sudo service nginx restart', 12 | } 13 | -------------------------------------------------------------------------------- /0x1B-web_stack_debugging_4/1-user_limit.pp: -------------------------------------------------------------------------------- 1 | # Fix problem of high amount files opened 2 | 3 | exec {'replace-1': 4 | provider => shell, 5 | command => 'sudo sed -i "s/nofile 5/nofile 50000/" /etc/security/limits.conf', 6 | before => Exec['replace-2'], 7 | } 8 | 9 | exec {'replace-2': 10 | provider => shell, 11 | command => 'sudo sed -i "s/nofile 4/nofile 40000/" /etc/security/limits.conf', 12 | } -------------------------------------------------------------------------------- /0x1B-web_stack_debugging_4/README.md: -------------------------------------------------------------------------------- 1 | # Web stack debugging 4 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![image](https://user-images.githubusercontent.com/105258746/188767412-2ac881ad-4583-491c-9f86-fa210d23a9db.png) 2 | 3 | # ALX Software Engineering DevOps Track 4 | 5 | ## Description 6 | At ALX School `we do hard things`, the goal is not to be a good student rather the key goal is to be a good software Engineer. ALX_africa are on a mission to identify, develop and equip Africa’s next 3 million leaders. We have projects everyday that we have to push on GitHub in order for an automatic review to be done by `Ubuntu 20.04 LTS`. This repository contains directories each corresponding to a software engineering or DevOps project. These projects are part of the ALX Software Engineering year 1 curriculum. In these projects, we cover everything from the basics of the Linux Shell, Bash commands, Bash scripting, networking, APIs, and web-stack debugging to more advanced topics. 7 | 8 | ## Table of contents 9 | DIRECTORIES | DESCRIPTION 10 | --------- | ----------- 11 | [0x00-shell_basics](https://github.com/Lordwill1/alx-system_engineering-devops/tree/master/0x00-shell_basics) | Introduction to the basics of the Linux Shell 12 | [0x01-shell_permissions](https://github.com/Lordwill1/alx-system_engineering-devops/tree/master/0x01-shell_permissions) | Introduction to Shell permissions and the file system 13 | [0x02-shell_redirections](https://github.com/Lordwill1/alx-system_engineering-devops/tree/master/0x02-shell_redirections) | Introduction to Shell redirections 14 | [0x03-shell_variables_expansions](https://github.com/Lordwill1/alx-system_engineering-devops/tree/master/0x03-shell_variables_expansions) | Introduction to Shell variable expansions 15 | -------------------------------------------------------------------------------- /command_line_for_the_win/0-first_9_tasks.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lordwill1/alx-system_engineering-devops/b7aabfb4db4157146b2e329278d9e2390865d57d/command_line_for_the_win/0-first_9_tasks.jpg -------------------------------------------------------------------------------- /command_line_for_the_win/1-next_9_tasks.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lordwill1/alx-system_engineering-devops/b7aabfb4db4157146b2e329278d9e2390865d57d/command_line_for_the_win/1-next_9_tasks.jpg -------------------------------------------------------------------------------- /command_line_for_the_win/2-next_9_tasks.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Lordwill1/alx-system_engineering-devops/b7aabfb4db4157146b2e329278d9e2390865d57d/command_line_for_the_win/2-next_9_tasks.jpg -------------------------------------------------------------------------------- /command_line_for_the_win/README.md: -------------------------------------------------------------------------------- 1 | # Command_line_for_the_win 2 | ![the_bash_env](https://www.dataquest.io/wp-content/uploads/2019/07/command-line-courses-dataquest-1000x520-1-1.gif) 3 | 4 | ## Background Context 5 | _CMD CHALLENGE_ is a pretty cool game challenging you on Bash skills. Everything is done via the command line and the questions are becoming increasingly complicated. It’s a good training to improve your command line skills! 6 | 7 | This project is NOT mandatory at all. It is 100% optional. Doing any part of this project will add a project grade of over 100% to your average. Your score won’t get hurt if you don’t do it, but if your current average is greater than your score on this project, your average might go down. Have fun! 8 | 9 | ## Requirements 10 | * A `README.md` file, at the root of the folder of the project, is mandatory 11 | _This project will be manually reviewed._ 12 | * As each task is completed, the name of that task will turn green 13 | * Create a screenshot, showing that you completed the required levels 14 | * Push this screenshot with the right name to GitHub, in either the PNG or JPEG format 15 | --------------------------------------------------------------------------------