├── 0x00-shell_basics ├── 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 └── school.mgc ├── 0x01-shell_permissions ├── 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 ├── sshkey └── sshkey.pub ├── 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 └── zombie ├── 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 ├── 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 └── todo_all_employees.json ├── 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-monitor_your_nginx_traffic └── README.md ├── 0x19-postmortem └── 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 ├── attack_is_the_best_defense ├── 0-sniffing ├── 1-dictionary_attack └── README.md └── command_line_for_the_win ├── 0-first_9_tasks.jpg ├── 0-first_9_tasks.png ├── 1-next_9_tasks.jpg ├── 1-next_9_tasks.png ├── 12dayscmdchallenge.jpg ├── 12dayscmdchallenge.png ├── 2-next_9_tasks.jpg ├── 2-next_9_tasks.png ├── 3-next_9_tasks.jpg ├── 3-next_9_tasks.png ├── 4-last_6_tasks.jpg ├── 4-last_6_tasks.png ├── README.md ├── oopscmdchallenge.jpg └── oopscmdchallenge.png /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 -xamp 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/11-lists: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ls -l -a . .. /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 -u *.html .. 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/2-bring_me_home: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/3-listfiles: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ls -l 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/4-listmorefiles: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ls -al 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 /tmp/my_first_directory/betty 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/9-firstdirdeletion: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | rmdir /tmp/my_first_directory 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/README.md: -------------------------------------------------------------------------------- 1 | # 0x00-shell_basics 2 | -------------------------------------------------------------------------------- /0x00-shell_basics/school.mgc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aysuarex/alx-system_engineering-devops/283a99104d8125884229beb21110f1277e220ac2/0x00-shell_basics/school.mgc -------------------------------------------------------------------------------- /0x01-shell_permissions/0-iam_betty: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | su betty 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/1-who_am_i: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | id -un 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 +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 | chown :school hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/2-groups: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | groups 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/3-new_owner: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 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 | 0. A script that switches the current user to the user betty. 2 | 1. A script that prints the effective username of the current user. 3 | 2. A script that prints all the groups the current user is part of. 4 | 3. A script that changes the owner of the file hello to the user betty. 5 | 4. A script that creates an empty file called hello. 6 | 5. A script that adds execute permission to the owner of the file hello. 7 | 6. A script that adds execute permission to the owner and the group owner, and read permission to other users, to the file hello. 8 | 7. A script that adds execution permission to the owner, the group owner and the other users, to the file hello. 9 | 8. A script that sets the permission to the file hello as follows: Owner: no permission at all. Group: no permission at all. Other users: all the permissions. The file hello will be in the working directory. 10 | 9. A script that sets the mode of the file hello to this: The file hello will be in the working directory. 11 | 10. A script that sets the mode of the file hello the same as olleh’s mode. The file olleh will be in the working directory. 12 | 11. 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. 13 | 12. A script that creates a directory called my_dir with permissions 751 in the working directory. 14 | 13. A script that changes the group owner to school for the file hello. 15 | -------------------------------------------------------------------------------- /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 >> iacta 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/README.md: -------------------------------------------------------------------------------- 1 | Write a script that prints “Hello, World”, followed by a new line to the standard output 2 | 3 | Write a script that displays a confused smiley "(Ôo)'. 4 | 5 | Display the content of the /etc/passwd file 6 | 7 | Display the content of /etc/passwd and /etc/hosts 8 | 9 | Display the last 10 lines of /etc/passwd 10 | 11 | Display the first 10 lines of /etc/passwd 12 | 13 | Write a script that displays the third line of the file iacta. The file iacta will be in the working directory. You’re not allowed to use sed. 14 | 15 | Write a shell script that creates a file named exactly *\'"Best School"'\*$?*****:) containing the text Best School ending by a new line. 16 | 17 | Write a script that writes into the file ls_cwd_content the result of the command ls -la. If the file ls_cwd_content already exists, it should be overwritten. If the file ls_cwd_content does not exist, create it. 18 | 19 | Write a script that duplicates the last line of the file iacta. The file iacta will be in the working directory. 20 | 21 | Write a script that deletes all the regular files (not the directories) with a .js extension that are present in the current directory and all its subfolders. 22 | 23 | Write a script that counts the number of directories and sub-directories in the current directory. The current and parent directories should not be taken into account. Hidden directories should be counted. 24 | 25 | Create a script that displays the 10 newest files in the current directory. Requirements: One file per line. Sorted from the newest to the oldest. 26 | 27 | Create a script that takes a list of words as input and prints only words that appear exactly once. Input format: One line, one word. Output format: One line, one word. Words should be sorted 28 | 29 | Display lines containing the pattern “root” from the file /etc/passwd 30 | 31 | Display the number of lines that contain the pattern “bin” in the file /etc/passwd 32 | 33 | Display lines containing the pattern “root” and 3 lines after them in the file /etc/passwd 34 | 35 | Display all the lines in the file /etc/passwd that do not contain the pattern “bin”. 36 | 37 | Display all lines of the file /etc/ssh/sshd_config starting with a letter. include capital letters as well 38 | 39 | Replace all characters A and c from input to Z and e respectively. 40 | 41 | Create a script that removes all letters c and C from input. 42 | 43 | Write a script that reverse its input. 44 | 45 | Write a script that displays all users and their home directories, sorted by users. Based on the the /etc/passwd file 46 | 47 | Write a command that finds all empty files and directories in the current directory and all sub-directories. Only the names of the files and directories should be displayed (not the entire path). Hidden files should be listed. One file name per line. The listing should end with a new line. You are not allowed to use basename, grep, egrep, fgrep or rgrep. 48 | 49 | Write a script that lists all the files with a .gif extension in the current directory and all its sub-directories. Hidden files should be listed. Only regular files (not directories) should be listed. The names of the files should be displayed without their extensions. The files should be sorted by byte values, but case-insensitive (file aaa should be listed before file bbb, file .b should be listed before file a, and file Rona should be listed after file jay). One file name per line. The listing should end with a new line. You are not allowed to use basename, grep, egrep, fgrep or rgrep. 50 | 51 | An acrostic is a poem (or other form of writing) in which the first letter (or syllable, or word) of each line (or paragraph, or other recurring feature in the text) spells out a word, message or the alphabet. The word comes from the French acrostiche from post-classical Latin acrostichis). As a form of constrained writing, an acrostic can be used as a mnemonic device to aid memory retrieval. Read more. Create a script that decodes acrostics that use the first letter of each line.. . The ‘decoded’ message has to end with a new line. You are not allowed to use grep, egrep, fgrep or rgrep. 52 | 53 | Write a script that parses web servers logs in TSV format as input and displays the 11 hosts or IP addresses which did the most requests. Order by number of requests, most active host or IP at the top. You are not allowed to use grep, egrep, fgrep or rgrep. 54 | -------------------------------------------------------------------------------- /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 | 0. Create a script that creates an alias. Name: ls Value: rm * 2 | 1. Create a script that prints hello user, where user is the current Linux user. 3 | 2. Add /action to the PATH. /action should be the last directory the shell looks into when looking for a program. 4 | 3. Create a script that counts the number of directories in the PATH. 5 | 4. Create a script that lists environment variables. 6 | 5. Create a script that lists all local variables and environment variables, and functions. 7 | 6. Create a script that creates a new local variable. Name: BEST Value: School 8 | 7. Create a script that creates a new global variable. Name: BEST Value: School 9 | 8. Write 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. 10 | 9. Write a script that prints the result of POWER divided by DIVIDE, followed by a new line. POWER and DIVIDE are environment variables 11 | 10. Write a script that displays the result of BREATH to the power LOVE. BREATH and LOVE are environment variables. The script should display the result, followed by a new line 12 | 11. Write a script that converts a number from base 2 to base 10. The number in base 2 is stored in the environment variable BINARY. The script should display the number in base 10, followed by a new line. 13 | 12. Create a script that prints all possible combinations of two letters, except oo. Letters are lower cases, from a to z. One combination per line. The output should be alpha ordered, starting with aa. Do not print oo. Your script file should contain maximum 64 characters 14 | 13. Write a script that prints a number with two decimal places, followed by a new line. The number will be stored in the environment variable NUM. 15 | 14. Write a script that converts a number from base 10 to base 16. The number in base 10 is stored in the environment variable DECIMAL. The script should display the number in base 16, followed by a new line 16 | 15. Write a script that encodes and decodes text using the rot13 encryption. Assume ASCII. 17 | 16. Write a script that prints every other line from the input, starting with the first line. 18 | 17. Write a shell script that adds the two numbers stored in the environment variables WATER and STIR and prints the result. WATER is in base water. STIR is in base stir. The result should be in base bestchol. 19 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/0-RSA_public_key.pub: -------------------------------------------------------------------------------- 1 | ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDsAvyXngIVrXyUfBdZ8vfhxaA18HIQWgRhw+gdN4wAfRJpz+jyCM+jXzoTEQHxNJlbGxlEcTPanMMjHhkJm7i8QHduhNUHa44VYGLBsc1bSLa5t0yDaZP8cRkPrZXKOaVLnirViUqP+sJjwWpkpDFgbnwjgaHYhJpZg/bXxLImIPD+cJkMQnsUQ60X03HDA+VBjMAhOrEwKPXtiiYey0O4UDOcMmo9gX6vwootUnK5x94opDS3BpCIEuqRkInDA5sUdfMjUYkkb4ShuZJhaU+1ulR1+XO+6sRJ9qbG7dTFCLDrGkgX5OzcdFkCkhTlF45skpcKIkCDpbQrX66QjGBlWT8L+99dm+ibOoInCb197TMEJTobtjDlXki2lst5Q+kV3eaAS2CrIm9NvbMxrTpH49XbwGGIPTlQb4DwIbQ7kHAeemtlUKEmCr/Z/27yhTOpDHX3cKcNpsxEbG9/NhV7XrIAxFR+ZhRbmJI1MplbtOFES2iD6CHUBzuv/f897w0= root@6757aad14428 2 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/1-for_best_school: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays 'Best School' in stdout 10 times 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' in stdout 10 times using a while loop 3 | 4 | index=0 5 | 6 | while [ $index -lt 10 ] 7 | do 8 | echo "Best School" 9 | ((index++)) 10 | done 11 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/3-until_best_school: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays 'Best School' in stdout 10 times using the until loop 3 | 4 | index=0 5 | 6 | until [ $index -eq 10 ] 7 | do 8 | echo "Best School" 9 | ((index++)) 10 | done 11 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/4-if_9_say_hi: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays 'Best School'. Displays Hi on the 9th iteration 3 | 4 | index=0 5 | 6 | while [ $index -lt 10 ] 7 | do 8 | if [ $index -eq 9 ] 9 | then 10 | echo "Hi" 11 | fi 12 | echo "Best School" 13 | (( index++ )) 14 | done 15 | -------------------------------------------------------------------------------- /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 file `school`. 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 | # Loops, conditions and parsing 2 | 3 | In this project, I began working loops and conditionals statements in Bash. 4 | 5 | ## Helper File :raised_hands: 6 | 7 | * [apache-access.log](./apache-access.log): An Apache access log file parsed in 8 | tasks `102` and `103`. 9 | 10 | ## Tasks :page_with_curl: 11 | 12 | * **0. Create a SSH RSA key pair** 13 | * [0-RSA_public_key.pub](./0-RSA_public_key.pub): A public SSH key uploaded for the 14 | purposes of ALX. 15 | 16 | * **1. For Best School loop** 17 | * [1-for_best_school](./1-for_best_school): Bash script that displays 18 | `Best School` 10 times using a `for` loop. 19 | 20 | * **2. While Best School loop** 21 | * [2-while_best_school](./2-while_best_school): Bash script that 22 | displays `Best School` 10 times using a `while` loop. 23 | 24 | * **3. Until Best School loop** 25 | * [3-until_best_school](./3-until_best_school): Bash script that displays 26 | `Best School` 10 times using an `until` loop. 27 | 28 | * **4. If 9, say Hi!** 29 | * [4-if_9_say_hi](./4-if_9_say_hi): Bash script that displays `Best School` 30 | 10 times using a `while` loop. 31 | * For the 9th iteration, displays `Best School` and then `Hi` on a 32 | new line. 33 | * Uses an `if` statement. 34 | 35 | * **5. 4 bad luck, 8 is your chance** 36 | * [5-4_bad_luck_8_is_your_chance](./5-4_bad_luck_8_is_your_chance): Bash script that loops 37 | from 1 to 10 using a `while` loop and: 38 | * Displays `bad luck` on the 4th iteration. 39 | * Displays `good luck` on the 8th iteration. 40 | * Displays `Best School` for all other iterations. 41 | * Uses the `if`, `elif`, and `else` statements. 42 | 43 | * **6. Superstitious numbers** 44 | * [6-superstitious_numbers](./6-superstitious_numbers): Bash script that displays 45 | numbers from `1` to `20` using a `while` loop and: 46 | * Displays `4` and then `bad luck from China` for the 4th iteration. 47 | * Displays `9` and then `bad luck from Japan` for the 9th iteration. 48 | * Displays `17` and then `bad luck from Italy` for the 17th iteration. 49 | * Uses a `case` statement. 50 | 51 | * **7. Clock** 52 | * [7-clock](./7-clock): Bash script that displays the time for 12 hours and 59 minutes. 53 | * Displays hours from `0` to `12`. 54 | * Displays minutes from `0` to `59`. 55 | 56 | * **8. For ls** 57 | * [8-for_ls](./8-for_ls): Bash script that displays the contents of the current directory 58 | in list format. 59 | * Only the part of the name after the first dash is displayed. 60 | 61 | * **9. To file, or not to file** 62 | * [9-to_file_or_not_to_file](./9-to_file_or_not_to_file): Bash script that gives information 63 | about the `bestschool` file. 64 | * If the file exists, displays: `school file exists`. 65 | * If the file does not exist, displays: `school file does not exist`. 66 | * If the file exists and is empty, displays: `school file is empty`. 67 | * If the file exists and is not empty, displays: `school file is not 68 | empty`. 69 | * If the file exists and is a regular file, displays: `school file 70 | is a regular file`. 71 | * Otherwise, displays nothing. 72 | 73 | * **10. FizzBuzz** 74 | * [10-fizzbuzz](./10-fizzbuzz): Bash script that displays numbers from 75 | `1` to `100` in list format. 76 | * Displays `FizzBuzz` when the number is a multiple of 3 and 5. 77 | * Displays `Fizz` when the number is a multiple of 3. 78 | * Displays `Buzz` when the number is a multiple of 5. 79 | * Otherwise, displays the number. 80 | 81 | * **11. Read and cut** 82 | * [100-read_and_cut](./100-read_and_cut): Bash script that displays the contents of the 83 | `/etc/passwd` file. 84 | * Displays only the username, user id, and user home directory path for each line. 85 | 86 | * **12. Tell the story of passwd** 87 | * [101-tell_the_story_of_passwd](./101-tell_the_story_of_passwd): Bash script that 88 | tells stories based on the contents of the `/etc/passwd` file. 89 | * Displays content from the file in the format: `The user USERNAME is part of 90 | the GROUP_ID gang, lives in HOME_DIRECTORY and rides COMMAND/SHELL. USER ID's 91 | place is protected by the passcode PASSWORD, more info about the user here: USER ID INFO`. 92 | 93 | * **13. Let's parse Apache logs** 94 | * [102-lets_parse_apache_logs](./102-lets_parse_apache_logs): Bash script that displays 95 | the visitor IP along with the HTTP status code for logs read from an Apache log access file. 96 | * Displays content in the format `IP HTTP_CODE`. 97 | * Uses `awk`. 98 | 99 | * **14. Dig the data** 100 | * [103-dig_the-data](./103-dig_the-data): Bash script that reads content from an 101 | Apace log access file and groups visitors by IP and HTTP status code. 102 | * Displays the grouped number of visitors to an IP address in the format 103 | `OCCURRENCE_NUMBER IP HTTP_CODE`. 104 | * Logs are grouped in order of greatest to lowest number of visitors. 105 | * Uses `awk`. 106 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/sshkey: -------------------------------------------------------------------------------- 1 | -----BEGIN OPENSSH PRIVATE KEY----- 2 | b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABlwAAAAdzc2gtcn 3 | NhAAAAAwEAAQAAAYEAvpYmjs0XIVgb/FqdfrAH2CjLw1+QQN8Zvw3RNRNKrc8oWFLaxQqy 4 | qF0yqzQYYG4bCrp6kXjtkShrCY84pDQFBDeqTB13Udzdlk2ij3r0Gmx4ynMubS6qsEdiYy 5 | nxNN5Rw2ouLpxlJSnVhDBnxHyMyMpUTU0Gis7A7/2zwxTZXQVCZ5SYipYHMGK2duiC0fjy 6 | +9mn5Y40EJqeMjz/necxP6LcBpEh7rpBI97zE+U/6gMiyDCL110jt1Co89Zat3KKEtuqVO 7 | mtIMbxFqlhRlBcbhiA5OKsFmEKQSHSUAxHOPWUG38vRO15y5Z41p8PFVOl6NS+CSy1vpNs 8 | Gmz9lXC0mtJ+DSjtj1AU0arbpQx9uijLgt8/fSyZJzKMf0rEL5HEqG+9pL39DD/7eyYkr2 9 | 74y4D8sSWtBo1hoJXGPOHRJS9xvn6SiuP7S0rMzSHtb8+bDkCin40vQjguBfmE+XEWPQD9 10 | 8snjAlhABIDE2kSmRhTk8HJg5MS+qqyNAHckc3mPAAAFgGwp1C9sKdQvAAAAB3NzaC1yc2 11 | EAAAGBAL6WJo7NFyFYG/xanX6wB9goy8NfkEDfGb8N0TUTSq3PKFhS2sUKsqhdMqs0GGBu 12 | Gwq6epF47ZEoawmPOKQ0BQQ3qkwdd1Hc3ZZNoo969BpseMpzLm0uqrBHYmMp8TTeUcNqLi 13 | 6cZSUp1YQwZ8R8jMjKVE1NBorOwO/9s8MU2V0FQmeUmIqWBzBitnbogtH48vvZp+WONBCa 14 | njI8/53nMT+i3AaRIe66QSPe8xPlP+oDIsgwi9ddI7dQqPPWWrdyihLbqlTprSDG8RapYU 15 | ZQXG4YgOTirBZhCkEh0lAMRzj1lBt/L0TtecuWeNafDxVTpejUvgkstb6TbBps/ZVwtJrS 16 | fg0o7Y9QFNGq26UMfbooy4LfP30smScyjH9KxC+RxKhvvaS9/Qw/+3smJK9u+MuA/LElrQ 17 | aNYaCVxjzh0SUvcb5+korj+0tKzM0h7W/Pmw5Aop+NL0I4LgX5hPlxFj0A/fLJ4wJYQASA 18 | xNpEpkYU5PByYOTEvqqsjQB3JHN5jwAAAAMBAAEAAAGABNeJuT0KpmU3qMygjbRpLpuyuY 19 | 72+j7wx4LRWtjXn9zQeJX6SuE/srlTbTgQmnqRo08jiAibeIGfXonN9ZYAvp+vaumgu2qy 20 | Enx8ccq84uL4mqQcfNefrITTwhMxtpcjWqSa8cI1a6FJdGdKa5qCdSN2ytP3I5WnHzHB3G 21 | XuM8fLbRhAW9z958PKQPEdSbpaaf2Yn2NifT2AYWRdViSmgqhfkKclRoxi1Ud3w3yiiA52 22 | VsGs+9a47pJVCITcnyaAwjNeBav5GkGQx+idQlzz0ZAkSQoIm+Nh1RmfGQcvLWFbz0xGQm 23 | 7zG2VxfMvJGEsWE3u39QkZom9JwK6iqvSljiCoTFTqX7St/yBt1+duhiVEl7udEDSDZAKY 24 | OmGydHdRDVuEVnS+KglmBNBCIMHDTQWbHvjRTPFaJpgkWk7f/Fb3DBTS+l7XobQcKCtphP 25 | rqRto3Bc+7TGQhNxoYOaT8bOarxIfzjqlUoo+GvzcWDiJOQdz0JiLF/+Z9QVZJs8MxAAAA 26 | wCIsHE4cKIeMF3BjaPz2/+ovrKvIH/ekYWHk/quNP4uacLsS6CZc2X4UBHhZOCW8Bgu5LV 27 | AjsYPAW0C0oICH0SfUHhKd7mQqGdu32dvufjXJPYJZjsiadq19ukGkIV8rVKsXEDMFuFbd 28 | GhJqXTpN0Y9V6K7p+icbspsoFupEN47u5m8IhOI4PvxRqKLv97Wyt7JRjwY3G2mO2EfvEt 29 | tJGR1iU04J0iCOsaQl7Of09KDEuKKXNfjTrEs9D68QICpmUwAAAMEA+tw/K4xF6mtr++5b 30 | NrQrSsd9w0x5MbMhSt2REHlvf6tJmr9zG9pb1S8PlKwo7W2kWPwNFgXWKnJaeiMKvdHzQd 31 | pUWdfI6lSgEGIYKSdeuv7VJb3WI6x4116VsXe+/Bk1Pw1qVi8QquwrisjC03JLyjAGtMkZ 32 | d0MhBrWTRUKEHniuxTGQHyPevV72ANvWIumsxgSnM1qBonsF0bSGXkr8Ih7P3EUFz1K1bU 33 | nNJevK1hmn7eJs10dm/YLKiBRz4jHJAAAAwQDCfcUZ/X7a7M/BfhyDM03PhtlvpQNlOAYZ 34 | 3iHIXv7/eSgdaT1byACK2HAjxWeauYO0KfWP0W/fBOcx1YDR4gVXZi9kGdZJzEynshbryR 35 | J0M9fERH+r+kTTIs2aBVKq+QTGoAcMleaSSc9Kk1vcT7Gmnal7N8mQa3LjBH48xsU6iVhC 36 | 9/l5J5ZlrW+9bQndDWfv52/PaCrqFwJ/tweQWoVxRz9G/p+ag+GhzIXQDGZln9kyp6EqaE 37 | Hkvy8za5n1PJcAAAALaHBAQXlzdWFyZXg= 38 | -----END OPENSSH PRIVATE KEY----- 39 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/sshkey.pub: -------------------------------------------------------------------------------- 1 | ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC+liaOzRchWBv8Wp1+sAfYKMvDX5BA3xm/DdE1E0qtzyhYUtrFCrKoXTKrNBhgbhsKunqReO2RKGsJjzikNAUEN6pMHXdR3N2WTaKPevQabHjKcy5tLqqwR2JjKfE03lHDai4unGUlKdWEMGfEfIzIylRNTQaKzsDv/bPDFNldBUJnlJiKlgcwYrZ26ILR+PL72afljjQQmp4yPP+d5zE/otwGkSHuukEj3vMT5T/qAyLIMIvXXSO3UKjz1lq3cooS26pU6a0gxvEWqWFGUFxuGIDk4qwWYQpBIdJQDEc49ZQbfy9E7XnLlnjWnw8VU6Xo1L4JLLW+k2wabP2VcLSa0n4NKO2PUBTRqtulDH26KMuC3z99LJknMox/SsQvkcSob72kvf0MP/t7JiSvbvjLgPyxJa0GjWGglcY84dElL3G+fpKK4/tLSszNIe1vz5sOQKKfjS9COC4F+YT5cRY9AP3yyeMCWEAEgMTaRKZGFOTwcmDkxL6qrI0AdyRzeY8= hp@Aysuarex 2 | -------------------------------------------------------------------------------- /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' SIGQUITgit 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 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | /** 8 | * infinite_while - Run an infinite while loop. 9 | * 10 | * Return: Always 0. 11 | */ 12 | int infinite_while(void) 13 | { 14 | while (1) 15 | { 16 | sleep(1); 17 | } 18 | return (0); 19 | } 20 | 21 | /** 22 | * main - Creates five zombie processes. 23 | * 24 | * Return: Always 0. 25 | */ 26 | int main(void) 27 | { 28 | pid_t pid; 29 | char count = 0; 30 | 31 | while (count < 5) 32 | { 33 | pid = fork(); 34 | if (pid > 0) 35 | { 36 | printf("Zombie process created, PID: %d\n", pid); 37 | sleep(1); 38 | count++; 39 | } 40 | else 41 | exit(0); 42 | } 43 | 44 | infinite_while(); 45 | 46 | return (EXIT_SUCCESS); 47 | } 48 | -------------------------------------------------------------------------------- /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 4 | with `ps`, `pgrep`, `pkill`, `pkill`, `exit`, and `trap`. 5 | 6 | ## Tasks :page_with_curl: 7 | 8 | * **0. What is my PID** 9 | * [0-what-is-my-pid](./0-what-is-my-pid): Bash script that displays its own PID. 10 | 11 | * **1. List your processes** 12 | * [1-list_your_processes](./1-list_your_processes): Bash script that displays a 13 | list of currently running processes. 14 | * Shows all processes for all users, including those not featuring a TTY. 15 | * Processes are displayed in a user-oriented hierarchy. 16 | 17 | * **2. Show your Bash PID** 18 | * [2-show_your_bash_pid](./2-show_your_bash_pid): Bash script that displays lines 19 | containing the `bash` keyword based on the script defined in `1-list_your_processes`. 20 | 21 | * **3. Show your Bash PID made easy** 22 | * [3-show_your_bash_pid_made_easy](./3-show_your_bash_pid_made_easy): Bash script 23 | that displays the PID along with the process name of processes who name contains the 24 | word `bash`. 25 | 26 | * **4. To infinity and beyond** 27 | * [4-to_infinity_and_beyond](./4-to_infinity_and_beyond): Bash script that displays 28 | `To infinity and beyond` indefinitely with a `sleep 2` in between each iteration. 29 | 30 | * **5. Don't stop me now!** 31 | * [5-dont_stop_me_now](./5-dont_stop_me_now): Bash script that kills the 32 | [4-to_infinity_and_beyond](./4-to_infinity_and_beyond) process using `kill`. 33 | 34 | * **6. Stop me if you can** 35 | * [6-stop_me_if_you_can](./6-stop_me_if_you_can): Bash script that kills the 36 | [4-to_infinity_and_beyond](./4-to_infinity_and_beyond) process using `pkill`. 37 | 38 | * **7. Highlander** 39 | * [7-highlander](./7-highlander): Bash script that displays `To infinity and beyond` 40 | indefinitely with a `sleep 2` in between each iteration. 41 | * Displays `I am invincible!!!` upon receiving a `SIGTERM` signal. 42 | 43 | * **8. Beheaded process** 44 | * [8-beheaded_process](./8-beheaded_process): Bash script that kills the process 45 | [7-highlander](./7-highlander). 46 | 47 | * **9. Process and PID file** 48 | * [100-process_and_pid_file](./100-process_and_pid_file): Bash script that creates the file 49 | `/var/run/holbertonscript.pid` containing its PID and displays `To infinity and 50 | beyond` indefinitely. 51 | * Displays `I hate the kill command` upon receiving a `SIGTERM` signal. 52 | * Displays `Y U no love me?!` upon receiving a `SIGINT` signal. 53 | * Deletes the file `/var/run/holbertonscript.pid` and terminates itself 54 | upon receiving the `SIGQUIT` or `SIGTERM` signal. 55 | 56 | * **10. Manage my process** 57 | * [manage_my_process](./manage_my_process): Bash script that writes `I am alive!` to the file 58 | `/tmp/my_process` indefinitely. 59 | * Sleeps two seconds in between each write. 60 | * [101-manage_my_process](./101-manage_my_process): Bash script that manages the 61 | [manage_my_process](./manage_my_process) script. 62 | * When passed the argument `start`: 63 | * Starts [manage_my_process](./manage_my_process). 64 | * Creates a file containing its PID in `/var/run/my_process.pid`. 65 | * Displays `manage_my_process started`. 66 | * When passed the argument `stop`: 67 | * Stops [manage_my_process](./manage_my_process). 68 | * Deletes the file `/var/run/my_process.pid`. 69 | * Displays `manage_my_process stopped`. 70 | * When passed the argument `restart`: 71 | * Stops [manage_my_process](./manage_my_process). 72 | * Deletes the file `/var/run/my_process.pid`. 73 | * Starts `manage_my_process`. 74 | * Creates a file containing its PID in `/var/run/my_process.pid`. 75 | * Displays `manage_my_process started`. 76 | * Otherwise, displays `Usage: manage_my_process {start|stop|restart}`. 77 | 78 | * **11. Zombie** 79 | * [102-zombie.c](./102-zombie.c): C program that creates five zombie processes. 80 | * For every zombie created, displays `Zombie process created, PID: 81 | `. 82 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/zombie: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aysuarex/alx-system_engineering-devops/283a99104d8125884229beb21110f1277e220ac2/0x05-processes_and_signals/zombie -------------------------------------------------------------------------------- /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. I practiced building 4 | them using Ruby's Oniguruma library. 5 | 6 | All code in this directory was tested using [Rubular](https://rubular.com/). Rubular is a Ruby-based regular expression editor. It's a handy way to test regular expressions as you write them. 7 | 8 | ## Tasks :page_with_curl: 9 | 10 | _Note: Each Ruby script in the project matches regular expressions based on an 11 | argument passed to it via the command line._ 12 | 13 | * **0. Simply matching School** 14 | * [0-simply_match_school.rb](./0-simply_match_school.rb): Ruby script that 15 | matches the regular expression `School`. 16 | 17 | * **1. Repetition Token #0** 18 | * [1-repetition_token_0.rb](./1-repetition_token_0.rb): Ruby script that matches 19 | the regular expression `hbn` with between 2-5 `t`'s in between `hb` and `n`. 20 | 21 | * **2. Repetition Token #1** 22 | * [2-repetition_token_1.rb](./2-repetition_token_1.rb): Ruby script that matches 23 | the regular expression `hn` with 0 or 1 occurrences of `b` and 0 or 1 24 | occurrences of `t` in between `h` and `n`. 25 | 26 | * **3. Repetition Token #2** 27 | * [3-repetition_token_2.rb](./3-repetition_token_2.rb): Ruby script that matches 28 | the regular expression `hbn` with 1 or more `t`'s in between `hb` and `n`. 29 | 30 | * **4. Repetition Token #3** 31 | * [4-repetition_token_3.rb](./4-repetition_token_3.rb): Ruby script that matches the 32 | regular expression `hbn` with 0 or more `t`'s in between `hb` and `n`. 33 | 34 | * **5. Not quite HBTN yet** 35 | * [5-beginning_and_end.rb](./5-beginning_and_end.rb): Ruby script that matches a 36 | regular expression starting with `h` and ending with `n` with any single character in between. 37 | 38 | * **6. Call me maybe** 39 | * [6-phone_number.rb](./6-phone_number.rb): Ruby script that matches a regular expression 40 | representing a 10-digit phone number. 41 | 42 | * **7. OMG WHY ARE YOU SHOUTING?** 43 | * [7-OMG_WHY_ARE_YOU_SHOUTING.rb](./7-OMG_WHY_ARE_YOU_SHOUTING.rb): Ruby script that 44 | matches regular expressions of uppercase letters. 45 | 46 | * **8. Textme** 47 | * [100-textme.rb](./100-textme.rb): Ruby script that runs statistics on TextMe app text 48 | message transcations. 49 | * Output: `[SENDER],[RECEIVER],[FLAGS]` where 50 | * `[SENDER]` is the sender phone number or name (including country code 51 | if present). 52 | * `[RECEIVER]` is the receiver phone number or name (including country code 53 | if present). 54 | * `[FLAGS]` is the flags that were used. 55 | -------------------------------------------------------------------------------- /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 too 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 a string 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 4 | project, I answered a few quiz-like questions and wrote a couple bash scripts 5 | while learning about the OSI model, LAN and WAN networks, and TCP/UDP data 6 | transfer protocols. 7 | 8 | ## Tasks :page_with_curl: 9 | 10 | * **0. OSI model** 11 | * [0-OSI_model](./0-OSI_model): Text file answering the following questions: 12 | * What is the OSI model? 13 | 1. Set of specifications that network hardware manufacturers must respect 14 | 2. The OSI model is a conceptual model that characterizes the communication 15 | functions of a telecommunication system without regard to their underlying 16 | internal structure and technology. 17 | 3. The OSI model is a model that characterizes the communication functions 18 | of a telecommunication system with a strong regard for their underlying 19 | internal structure and technology. 20 | * How is the OSI model organized? 21 | 1. Alphabetically 22 | 2. From the lowest to the highest level 23 | 3. Randomly 24 | 25 | * **1. Types of network** 26 | * [1-types_of_network](./1-types_of_network): Text file answering the following questions: 27 | * What type of network a computer in local is connected to? 28 | 1. Internet 29 | 2. WAN 30 | 3. LAN 31 | * What type of network could connect an office in one building to another 32 | office in a building a few streets away? 33 | 1. Internet 34 | 2. WAN 35 | 3. LAN 36 | * What network do you use when you browse www.google.com from your 37 | smartphone (not connected to the Wifi)? 38 | 1. Internet 39 | 2. WAN 40 | 3. LAN 41 | 42 | * **2. MAC and IP address** 43 | * [2-MAC_and_IP_address](./2-MAC_and_IP_address): Text file answering the following questions: 44 | * What is a MAC address? 45 | 1. The name of a network interface 46 | 2. The unique identifier of a network interface 47 | 3. A network interface 48 | * What is an IP address? 49 | 1. Is to devices connected to a network what postal address is to houses 50 | 2. The unique identifier of a network interface 51 | 3. Is a number that network devices use to connect to networks 52 | 53 | * **3. UDP and TCP** 54 | * [3-UDP_and_TCP](./3-UDP_and_TCP): Text file answering the following questions 55 | (boxes refer to an image provided by ALX): 56 | * Which statement is correct for the TCP box: 57 | 1. It is a protocol that is transferring data in a slow way but surely 58 | 2. It is a protocol that is transferring data in a fast way and might loss 59 | data along in the process 60 | * Which statement is correct for the UDP box: 61 | 1. It is a protocol that is transferring data in a slow way but surely 62 | 2. It is a protocol that is transferring data in a fast way and might loss 63 | data along in the process 64 | * Which statement is correct for the TCP worker: 65 | 1. Have you received boxes x, y, z? 66 | 2. May I increase the rate at which I am sending you boxes? 67 | 68 | * **4. TCP and UDP ports** 69 | * [4-TCP_and_UDP_ports](./4-TCP_and_UDP_ports): Bash script that displays listening ports. 70 | * Only shows listening sockets. 71 | * Displays the PID and name of the program to which each socket belongs. 72 | 73 | * **5. Is the host on the network** 74 | * [5-is_the_host_on_the_network](./5-is_the_host_on_the_network): Bash script that 75 | pings an IP address received as an argument 5 times. 76 | * Usage: `5-is_the_host_on_the_network {IP_ADDRESS}`. 77 | -------------------------------------------------------------------------------- /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 | sed -i 's/127.*$/127.0.0.2 localhost\n8.8.8.8 facebook.com/' ~/hosts.new 8 | cp -f ~/hosts.new /etc/hosts 9 | -------------------------------------------------------------------------------- /0x08-networking_basics_2/1-show_attached_IPs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays all acive IPv4 addresses. 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 | This project was the second of two introducing networking. I continued to learn 4 | about IP addresses while practicing manipulating them with Bash scripts. 5 | 6 | ## Tasks :page_with_curl: 7 | 8 | * **0. Change your home IP** 9 | * [0-change_your_home_IP](./0-change_your_home_IP): Bash script that configures 10 | an Ubuntu server as follows: 11 | * `localhost` resolves to `127.0.0.2` 12 | * `facebook.com` resolves to `8.8.8.8` 13 | 14 | * **1. Show attached IPs** 15 | * [1-show_attached_IPs](./1-show_attached_IPs): Bash script that displays all active IPv4 16 | IP's on the machine. 17 | 18 | * **2. Port listening on localhost** 19 | * [100-port_listening_on_localhost](./100-port_listening_on_localhost): Bash script that 20 | listens on port `98` on `localhost`. 21 | -------------------------------------------------------------------------------- /0x09-web_infrastructure_design/0-simple_web_stack: -------------------------------------------------------------------------------- 1 | https://imgbox.com/RIYItCxY 2 | -------------------------------------------------------------------------------- /0x09-web_infrastructure_design/1-distributed_web_infrastructure: -------------------------------------------------------------------------------- 1 | https://imgbox.com/tZG9v50W 2 | -------------------------------------------------------------------------------- /0x09-web_infrastructure_design/2-secured_and_monitored_web_infrastructure: -------------------------------------------------------------------------------- 1 | https://imgbox.com/PIg8uwrh 2 | -------------------------------------------------------------------------------- /0x09-web_infrastructure_design/3-scale_up: -------------------------------------------------------------------------------- 1 | https://imgbox.com/wcGCHDW1 2 | -------------------------------------------------------------------------------- /0x09-web_infrastructure_design/README.md: -------------------------------------------------------------------------------- 1 | # Web Infrastructure Design 2 | 3 | Project done during **Full Stack Software Engineering studies** at **ALX**. It aims to learn about how to design a Web Infrastructure. 4 | 5 | ## Key concepts 6 | * Network basics 7 | * Server 8 | * Web server 9 | * Application server 10 | * DNS & DNS record types 11 | * Load Balancer 12 | * Monitoring 13 | * Database 14 | * Single point of failure 15 | * HTTP & HTTPS 16 | * Firewall 17 | 18 | ## File Descriptions 19 | 20 | Each file contains a link to an image hosted on Imgbox. These images are based on the following requirements:
21 | 22 | ### [0-simple_web_stack](0-simple_web_stack) 23 | 24 | On a whiteboard, design a one server web infrastructure that hosts the website that is reachable via `www.foobar.com.` Start your explanation by having a user wanting to access your website.
25 | 26 | You must use: 27 | 28 | * 1 physical server 29 | 30 | * 1 web server (Nginx) 31 | 32 | * 1 application server 33 | 34 | * 1 application files (your code base) 35 | 36 | * 1 database (MySQL) 37 | 38 | * 1 domain name `foobar.com` configured with a `www` record that points to your server IP `8.8.8.8` 39 | 40 | ### [1-distributed_web_infrastructure](1-distributed_web_infrastructure) 41 | 42 | On a whiteboard, design a three servers web infrastructure that host the website `www.foobar.com`.
43 | 44 | You must add to [0-simple_web_stack](0-simple_web_stack): 45 | 46 | * 2 physical servers 47 | 48 | * 1 web server (Nginx) 49 | 50 | * 1 application server 51 | 52 | * 1 load-balancer (HAproxy) 53 | 54 | * 1 application files (your code base) 55 | 56 | * 1 database (MySQL) 57 | 58 | ### [2-secured_and_monitored_web_infrastructure](2-secured_and_monitored_web_infrastructure) 59 | 60 | On a whiteboard, design a three servers web infrastructure that host the website `www.foobar.com`, it must be secured, serve encrypted traffic and be monitored.
61 | 62 | You must add to [1-distributed_web_infrastructure](1-distributed_web_infrastructure): 63 | 64 | * 3 firewalls 65 | 66 | * 1 SSL certificate to serve `www.foobar.com` over HTTPS 67 | 68 | * 3 monitoring clients (data collector for Sumologic or other monitoring services) 69 | 70 | ### [3-scale_up](3-scale_up) 71 | 72 | You must add to [2-secured_and_monitored_web_infrastructure](2-secured_and_monitored_web_infrastructure): 73 | 74 | * 1 physical server 75 | 76 | * 1 load-balancer (HAproxy) configured as cluster with the other one 77 | 78 | * Split components (web server, application server, database) with their own server 79 | 80 | ## Files 81 | 82 | | Filename | Description | 83 | | -------- | ----------- | 84 | | [`0-simple_web_stack`](./0-simple_web_stack) | Web Infrastructure Design with a LAMP stack. This contains: 1 server, 1 web server, 1 application server, 1 database and 1 domain name | 85 | | [`1-distributed_web_infrastructure`](./1-distributed_web_infrastructure) | Web Infrastructure Design, based on `0-simple_web_stack` that contains some additional components: 1 server, 1 web server, 1 application server, 1 load-balancer, 1 set of application files, 1 database | 86 | | [`2-secured_and_monitored_web_infrastructure`](2-secured_and_monitored_web_infrastructure) | Web Infrastructure Design, based on `1-distributed_web_infrastructure` that contains some additional components: 3 firewalls, 1 SSL certificate, 3 monitoring clients | 87 | | [`3-scale_up`](3-scale_up) | Web Infrastructure Design, based on `2-secured_and_monitored_web_infrastructure` that contains some additional components: 1 server, 1 load-balancer | 88 | -------------------------------------------------------------------------------- /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 35.172.230.83 with key in ~/.ssh/school 3 | 4 | ssh -i ~/.ssh/school ubuntu@35.172.230.83 5 | -------------------------------------------------------------------------------- /0x0B-ssh/1-create_ssh_key_pair: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Creates RSA key pair 3 | 4 | ssh-keygen -b 4096 -f school -t rsa -N betty -------------------------------------------------------------------------------- /0x0B-ssh/100-puppet_ssh_config.pp: -------------------------------------------------------------------------------- 1 | # Setting 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 | ALX-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/school` and to refuse authentication using a password. 19 | -------------------------------------------------------------------------------- /0x0C-web_server/0-transfer_file: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # transfer a file from our client to a server 3 | if [ $# -lt 3 ]; 4 | then 5 | echo "Usage: 0-transfer_file PATH_TO_FILE IP USERNAME PATH_TO_SSH_KEY"; 6 | exit; 7 | fi; 8 | 9 | if [ $# -ge 4 ]; 10 | then 11 | scp -o StrictHostKeyChecking=no -i "$4" "$1" "$3"@"$2":~/ 12 | else 13 | scp -o StrictHostKeyChecking=no "$1" "$3"@"$2":~/ 14 | fi; 15 | -------------------------------------------------------------------------------- /0x0C-web_server/1-install_nginx_web_server: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # installs nginx and configure it to listen on port 80 3 | # print "Hello World" 4 | 5 | sudo apt-get -y update 6 | sudo apt-get -y install nginx 7 | echo 'Hello World!' > /var/www/html/index.nginx-debian.html 8 | sudo service nginx start 9 | -------------------------------------------------------------------------------- /0x0C-web_server/2-setup_a_domain_name: -------------------------------------------------------------------------------- 1 | aysuarex.tech -------------------------------------------------------------------------------- /0x0C-web_server/3-redirection: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #Configure a new Nginx server so that /redirect_me is redirecting to another page 3 | 4 | sudo apt-get -y update 5 | sudo apt-get -y install nginx 6 | sudo ufw allow 'Nginx HTTP' 7 | echo "Hello World" | sudo tee /var/www/html/index 8 | sudo sed -i '/listen 80 default_server/a rewrite ^/redirect_me https://www.youtube.com/ permanent;' /etc/nginx/sites-available/default 9 | sudo service nginx restart 10 | -------------------------------------------------------------------------------- /0x0C-web_server/4-not_found_page_404: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Install nginx on your web-01 server 3 | apt-get -y update 4 | apt-get -y install nginx 5 | echo "Hello World!" | sudo tee /var/www/html/index.html > /dev/null 6 | sed -i "46i rewrite ^/redirect_me https://www.youtube.com/watch?v=QH2-TGUlwu4 permanent;" /etc/nginx/sites-available/default 7 | echo "Ceci n'est pas une page" | sudo tee /var/www/html/custom_404.html > /dev/null 8 | sed -i "46i error_page 404 /custom_404.html;" /etc/nginx/sites-available/default 9 | service nginx restart -------------------------------------------------------------------------------- /0x0C-web_server/7-puppet_install_nginx_web_server.pp: -------------------------------------------------------------------------------- 1 | # add stable version of nginx 2 | exec { 'add nginx stable repo': 3 | command => 'sudo add-apt-repository ppa:nginx/stable', 4 | path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', 5 | } 6 | 7 | # update software packages list 8 | exec { 'update packages': 9 | command => 'apt-get update', 10 | path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', 11 | } 12 | 13 | # install nginx 14 | package { 'nginx': 15 | ensure => 'installed', 16 | } 17 | 18 | # allow HTTP 19 | exec { 'allow HTTP': 20 | command => "ufw allow 'Nginx HTTP'", 21 | path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', 22 | onlyif => '! dpkg -l nginx | egrep \'îi.*nginx\' > /dev/null 2>&1', 23 | } 24 | 25 | # change folder rights 26 | exec { 'chmod www folder': 27 | command => 'chmod -R 755 /var/www', 28 | path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', 29 | } 30 | 31 | # create index file 32 | file { '/var/www/html/index.html': 33 | content => "Hello World!\n", 34 | } 35 | 36 | # create index file 37 | file { '/var/www/html/404.html': 38 | content => "Ceci n'est pas une page\n", 39 | } 40 | 41 | # add redirection and error page 42 | file { 'Nginx default config file': 43 | ensure => file, 44 | path => '/etc/nginx/sites-enabled/default', 45 | content => 46 | "server { 47 | listen 80 default_server; 48 | listen [::]:80 default_server; 49 | root /var/www/html; 50 | # Add index.php to the list if you are using PHP 51 | index index.html index.htm index.nginx-debian.html; 52 | server_name _; 53 | location / { 54 | # First attempt to serve request as file, then 55 | # as directory, then fall back to displaying a 404. 56 | try_files \$uri \$uri/ =404; 57 | } 58 | error_page 404 /404.html; 59 | location /404.html { 60 | internal; 61 | } 62 | 63 | if (\$request_filename ~ redirect_me){ 64 | rewrite ^ https://www.youtube.com/watch?v=QH2-TGUlwu4 permanent; 65 | } 66 | } 67 | ", 68 | } 69 | # restart nginx 70 | exec { 'restart service': 71 | command => 'service nginx restart', 72 | path => '/usr/bin:/usr/sbin:/bin', 73 | } 74 | 75 | # start service nginx 76 | service { 'nginx': 77 | ensure => running, 78 | require => Package['nginx'], 79 | } 80 | -------------------------------------------------------------------------------- /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 `Hello World`. 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 | -------------------------------------------------------------------------------- /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 | ## Task :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 | # fix nginx listening on port 80 3 | # Go to sites-enabled folder for Nginx 4 | cd /etc/nginx/sites-enabled/ || exit; 5 | # Delete the default file 6 | rm default; 7 | # Create symbolic link to the deafult file in sites-available 8 | ln -s /etc/nginx/sites-available/default default; 9 | # Restart Nginx 10 | service nginx restart 11 | -------------------------------------------------------------------------------- /0x0E-web_stack_debugging_1/1-debugging_made_short: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #Sets nginx for listening to 80 port 3 | sed -i "s/8080/80/" /etc/nginx/sites-enabled/default 4 | sudo service nginx restart 5 | kill -9 "$(cat /var/run/nginx.pid)" 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 | # Installs Nginx with the following configurations: 3 | #+ Listens on port 80. 4 | #+ Returns a page containing "Hello World" when queried 5 | #+ at the root with a curl GET request. 6 | #+ Configures /redirect_me as a "301 Moved Permanently". 7 | #+ Includes a custom 404 page containing "Ceci n'est pas une page". 8 | #+ Contains a custom HTTP header named X-Served-By. 9 | #+ The value of the HTTP header is the hostname of the running server. 10 | 11 | apt-get update 12 | apt-get install -y nginx 13 | 14 | mkdir -p /var/www/html 15 | touch /var/www/html/index.html 16 | echo "Hello World" > /var/www/html/index.html 17 | touch /var/www/html/404.html 18 | echo "Ceci n'est pas une page" > /var/www/html/404.html 19 | 20 | printf %s "server { 21 | listen 80 default_server; 22 | listen [::]:80 default_server; 23 | add_header X-Served-By $HOSTNAME; 24 | root /var/www/html; 25 | index index.html index.htm; 26 | 27 | location /redirect_me { 28 | return 301 http://cuberule.com/; 29 | } 30 | 31 | error_page 404 /404.html; 32 | location /404 { 33 | root /var/www/html; 34 | internal; 35 | } 36 | }" > /etc/nginx/sites-available/default 37 | 38 | service nginx restart 39 | -------------------------------------------------------------------------------- /0x0F-load_balancer/1-install_load_balancer: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Configure Nginx so that its HTTP response contains 3 | # a custom header 4 | # 5 | balancer="\ 6 | frontend haproxy_balancer 7 | bind *:80 8 | mode http 9 | default_backend webservers 10 | 11 | backend webservers 12 | balance roundrobin 13 | server 26071-web-01 44.210.150.159:80 check 14 | server 26071-web-02 35.173.47.15:80 check 15 | " 16 | # Update packages 17 | apt-get -y update 18 | apt-get -y upgrade 19 | 20 | # Add HAProxy PPA 21 | apt-get -y install software-properties-common 22 | add-apt-repository -y ppa:vbernat/haproxy-2.5 23 | apt-get -y update 24 | 25 | # Install HAProxy 26 | apt-get -y install haproxy 27 | cp -a /etc/haproxy/haproxy.cfg{,.orig} 28 | echo "$balancer" >> /etc/haproxy/haproxy.cfg 29 | service haproxy restart 30 | -------------------------------------------------------------------------------- /0x0F-load_balancer/2-puppet_custom_http_response_header.pp: -------------------------------------------------------------------------------- 1 | # Automation: creates a custom HTTP header response with Puppet. 2 | exec { 'command': 3 | command => 'apt-get -y update; 4 | apt-get -y install nginx; 5 | sudo sed -i "/listen 80 default_server;/a add_header X-Served-By $HOSTNAME;" /etc/nginx/sites-available/default; 6 | service nginx restart', 7 | provider => shell, 8 | } 9 | -------------------------------------------------------------------------------- /0x0F-load_balancer/README.md: -------------------------------------------------------------------------------- 1 | # Load balancer 2 | 3 | In this project, I continued to build up the configuration of the web server 4 | issued in project 0x0B. I was issued two additional servers, one to replicate 5 | the Nginx configuration of my original server, and another to set up an HAproxy 6 | load balancer on to manage both web servers. 7 | 8 | ## Tasks :page_with_curl: 9 | 10 | * **0. Double the number of webservers** 11 | * [0-custom_http_response_header](./0-custom_http_response-header): Bash 12 | script that installs and configures Nginx on a server with a custom HTTP 13 | response header. 14 | * The name of the HTTP header is `X-Served-By`. 15 | * The value of the HTTP header is the hostname of the server. 16 | 17 | * **1. Install your load balancer** 18 | * [1-install_load_balancer](./1-install_load_balancer): Bash script that 19 | installs and configures HAproxy version 1.5 on a server. 20 | * Enables management via the init script. 21 | * Requests are distributed using a round-robin algorithm. 22 | -------------------------------------------------------------------------------- /0x10-https_ssl/0-world_wide_web: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Takes a subdomain and a domain and returns information about the subdomain 3 | 4 | print_info () { 5 | dig "$1" | grep -A1 'ANSWER SECTION:' | sed -r "s/$1./$2/g" | awk -F" " ' NR==2 { print "The subdomain " $1 " is a " $4 " record and points to " $5 }' 6 | } 7 | 8 | if [ "$#" -eq 2 ] 9 | then 10 | print_info "$2.$1" "$2" 11 | else 12 | print_info "www.$1" "www" 13 | print_info "lb-01.$1" "lb-01" 14 | print_info "web-01.$1" "web-01" 15 | print_info "web-02.$1" "web-02" 16 | fi 17 | -------------------------------------------------------------------------------- /0x10-https_ssl/1-haproxy_ssl_termination: -------------------------------------------------------------------------------- 1 | global 2 | log /dev/log local0 3 | log /dev/log local1 notice 4 | chroot /var/lib/haproxy 5 | stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners 6 | stats timeout 30s 7 | user haproxy 8 | group haproxy 9 | daemon 10 | 11 | # Default SSL material locations 12 | ca-base /etc/ssl/certs 13 | crt-base /etc/ssl/private 14 | 15 | # See: https://ssl-config.mozilla.org/#server=haproxy&server-version=2.0.3&config=intermediate 16 | ssl-default-bind-ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384 17 | ssl-default-bind-ciphersuites TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256 18 | ssl-default-bind-options ssl-min-ver TLSv1.2 no-tls-tickets 19 | 20 | defaults 21 | log global 22 | mode http 23 | option httplog 24 | option dontlognull 25 | timeout connect 5000 26 | timeout client 50000 27 | timeout server 50000 28 | errorfile 400 /etc/haproxy/errors/400.http 29 | errorfile 403 /etc/haproxy/errors/403.http 30 | errorfile 408 /etc/haproxy/errors/408.http 31 | errorfile 500 /etc/haproxy/errors/500.http 32 | errorfile 502 /etc/haproxy/errors/502.http 33 | errorfile 503 /etc/haproxy/errors/503.http 34 | errorfile 504 /etc/haproxy/errors/504.http 35 | 36 | # start of parameters for aysuarex.tech 37 | frontend aysuarex.tech-http-frontend 38 | bind *:80 39 | http-request set-header X-Forwarded-Proto http 40 | default_backend aysuarex.tech-backend 41 | 42 | 43 | frontend aysuarex.tech-https-frontend 44 | bind *:443 ssl crt /etc/ssl/aysuarex.tech.pem 45 | http-request set-header X-Forwarded-Proto https 46 | default_backend aysuarex.tech-backend 47 | 48 | 49 | backend aysuarex.tech-backend 50 | balance roundrobin 51 | server 914-web-01 44.210.150.159:80 check 52 | server 914-web-02 35.173.47.15:80 check 53 | # end of parameters 54 | -------------------------------------------------------------------------------- /0x10-https_ssl/100-redirect_http_to_https: -------------------------------------------------------------------------------- 1 | global 2 | log /dev/log local0 3 | log /dev/log local1 notice 4 | chroot /var/lib/haproxy 5 | stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners 6 | stats timeout 30s 7 | user haproxy 8 | group haproxy 9 | daemon 10 | 11 | tune.ssl.default-dh-param 2048 12 | 13 | # Default SSL material locations 14 | ca-base /etc/ssl/certs 15 | crt-base /etc/ssl/private 16 | 17 | # See: https://ssl-config.mozilla.org/#server=haproxy&server-version=2.0.3&config=intermediate 18 | ssl-default-bind-ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384 19 | ssl-default-bind-ciphersuites TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256 20 | ssl-dh-param-file /etc/haproxy/dhparams.pem 21 | ssl-default-bind-options ssl-min-ver TLSv1.2 no-tls-tickets 22 | 23 | defaults 24 | log global 25 | mode http 26 | option httplog 27 | option dontlognull 28 | timeout connect 5000 29 | timeout client 50000 30 | timeout server 50000 31 | errorfile 400 /etc/haproxy/errors/400.http 32 | errorfile 403 /etc/haproxy/errors/403.http 33 | errorfile 408 /etc/haproxy/errors/408.http 34 | errorfile 500 /etc/haproxy/errors/500.http 35 | errorfile 502 /etc/haproxy/errors/502.http 36 | errorfile 503 /etc/haproxy/errors/503.http 37 | errorfile 504 /etc/haproxy/errors/504.http 38 | 39 | listen 19018-lb-01 40 | bind *:80 41 | bind *:443 ssl crt /etc/letsencrypt/live/www.aysuarex.tech/aysuarex.pem 42 | mode http 43 | redirect scheme https code 301 if !{ ssl_fc } 44 | balance roundrobin 45 | option forwardfor 46 | server 19018-web-01 44.210.150.159:80 check 47 | server 19018-web-02 35.173.47.15:80 check 48 | -------------------------------------------------------------------------------- /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 | * **0. World wide web** 10 | * [0-world_wide_web](./0-world_wide_web): Bash script that displays 11 | information about subdomains on my configured servers. 12 | * Usage: `./0-world_wide_web ` 13 | * Output: `The subdomain [SUB_DOMAIN] is a [RECORD_TYPE] record and 14 | points to [DESTINATION]` 15 | * If no `subdomain` parameter is passed, displays information about the 16 | subdomains `www`, `lb-01`, `web-01` and `web-02`, in that order. 17 | 18 | * **1. HAproxy SSL termination** 19 | * [1-haproxy_ssl_termination](./1-haproxy_ssl_termination): HAproxy 20 | configuration file that accepts encrypted SSL traffic for the subdomain 21 | `www.` on TCP port 443. 22 | 23 | * **2. No loophole in your website traffic** 24 | * [100-redirect_http_to_https](./100-redirect_http_to_https): HAproxy 25 | configuration file that automatically redirects HTTP traffic to HTTPS. 26 | -------------------------------------------------------------------------------- /0x11-what_happens_when_your_type_google_com_in_your_browser_and_press_enter/0-blog_post: -------------------------------------------------------------------------------- 1 | https://medium.com/@aysuarex/what-happens-when-you-type-google-com-in-your-browser-and-press-enter-cb51bee7c637 2 | -------------------------------------------------------------------------------- /0x11-what_happens_when_your_type_google_com_in_your_browser_and_press_enter/1-what_happen_when_diagram: -------------------------------------------------------------------------------- 1 | https://imgbox.com/19dkbksY 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/--- 2 | -------------------------------------------------------------------------------- /0x11-what_happens_when_your_type_google_com_in_your_browser_and_press_enter/README.md: -------------------------------------------------------------------------------- 1 | # 0x11. What happens when you type google.com in your browser and press Enter 2 | 3 | In this project, I was asked to write an article to explain all about the web 2.0 infrastructure. Understanding this concept is very important for me as a Fullstack Software Engineer. Reviewing and encapsulating networking knowledge and skills I had been learning 4 | and practicing over the last month, in this project, I wrote a blog post 5 | answering the classic interview question - "What happens when you type a URL into a browser and hit `Enter`?" 6 | 7 | ## Task Responses :page_with_curl: 8 | 9 | * **0. What happens when...** 10 | * [0-blog_post](./0-blog_post): Text file containing the link to my blog post. 11 | 12 | * **1. Everything's better with a pretty diagram** 13 | * [1-what_happen_when_diagram](./1-what_happen_when_diagram): Text file 14 | containing the link to a diagram put together to visualize the networking 15 | process described in my blog. 16 | 17 | ## Project Questions and Requirements :☑️ 18 | 19 | ### Task 0 20 | 21 | This question is a classic and still widely used interview question for many types of software engineering position. It is used to assess a candidate’s general knowledge of how the web stack works on top of the internet. One important guideline to begin answering this question is that you should ask your interviewer whether they would like you to focus in on one specific area of the workflow. For a front-end position they may want you to talk at length about how the DOM is rendering. For an SRE position they may want you to go into the load balancing mechanism.\ 22 | This question is a good test of whether you understand DNS. Many software engineering candidates struggle with this concept, so if you do well on this question, you are already way ahead of the curve. If you take this project seriously and write an excellent article, it may be something that will grab the attention of future employers.\ 23 | Write a blog post explaining what happens when you type https://www.google.com in your browser and press Enter. 24 | 25 | Requirements, your post must cover: 26 | - DNS request 27 | - TCP/IP 28 | - Firewall 29 | - HTTPS/SSL 30 | - Load-balancer 31 | - Web server 32 | - Application server 33 | - Database 34 | 35 | Click [here](http://---) to read my article. 36 | 37 | ### Task 1 38 | Add a schema to your blog post illustrating the flow of the request created when you type https://www.google.com in your browser and press Enter.\ 39 | The diagram should show: 40 | - DNS resolution 41 | - that the request hitting server IP on the appropriate port 42 | - that the traffic is encrypted 43 | - that the traffic goes through a firewall 44 | - that the request is distributed via a load balancer 45 | - that the web server answers the request by serving a web page 46 | - that the application server generates the web page 47 | - that the application server request data from the database 48 | 49 | I hosted the diagram image [here](https://imgbox/...) 50 | -------------------------------------------------------------------------------- /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 | #!/usr/bin/env bash 2 | # Configures a ufw firewall to block all incoming traffic 3 | #+ except for TCP ports 22, 443 and 80. 4 | 5 | apt-get install ufw 6 | sed -i 's/IPV6=.*/IPV6=yes/' /etc/default/ufw 7 | ufw disable 8 | ufw enable 9 | ufw default deny incoming 10 | ufw default allow outgoing 11 | ufw allow 22/tcp 12 | ufw allow 443/tcp 13 | ufw allow 80/tcp 14 | -------------------------------------------------------------------------------- /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 | * **1. 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 | # Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. 2 | # 3 | # This program is free software; you can redistribute it and/or modify 4 | # it under the terms of the GNU General Public License, version 2.0, 5 | # as published by the Free Software Foundation. 6 | # 7 | # This program is also distributed with certain software (including 8 | # but not limited to OpenSSL) that is licensed under separate terms, 9 | # as designated in a particular file or component or in included license 10 | # documentation. The authors of MySQL hereby grant you an additional 11 | # permission to link the program and your derivative works with the 12 | # separately licensed software that they have included with MySQL. 13 | # 14 | # This program is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License, version 2.0, for more details. 18 | # 19 | # You should have received a copy of the GNU General Public License 20 | # along with this program; if not, write to the Free Software 21 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | 23 | # 24 | # The MySQL Server configuration file. 25 | # 26 | # For explanations see 27 | # http://dev.mysql.com/doc/mysql/en/server-system-variables.html 28 | 29 | [mysqld] 30 | pid-file = /var/run/mysqld/mysqld.pid 31 | socket = /var/run/mysqld/mysqld.sock 32 | datadir = /var/lib/mysql 33 | log-error = /var/log/mysql/error.log 34 | 35 | 36 | # By default we only accept connections from localhost 37 | #--disabled inorder to enable mysql replication 38 | #bind-address = 127.0.0.1 39 | 40 | # Disabling symbolic-links is recommended to prevent assorted security risks 41 | symbolic-links=0 42 | 43 | # setting server id 44 | server-id = 1 45 | 46 | # setting the base name & location of mysql bunary log file 47 | log_bin = /var/log/mysql/mysql-bin.log 48 | 49 | # name of database to replicate 50 | binlog_do_db = tyrell_corp -------------------------------------------------------------------------------- /0x14-mysql/4-mysql_configuration_replica: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. 2 | # 3 | # This program is free software; you can redistribute it and/or modify 4 | # it under the terms of the GNU General Public License, version 2.0, 5 | # as published by the Free Software Foundation. 6 | # 7 | # This program is also distributed with certain software (including 8 | # but not limited to OpenSSL) that is licensed under separate terms, 9 | # as designated in a particular file or component or in included license 10 | # documentation. The authors of MySQL hereby grant you an additional 11 | # permission to link the program and your derivative works with the 12 | # separately licensed software that they have included with MySQL. 13 | # 14 | # This program is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License, version 2.0, for more details. 18 | # 19 | # You should have received a copy of the GNU General Public License 20 | # along with this program; if not, write to the Free Software 21 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | 23 | # 24 | # The MySQL Server configuration file. 25 | # 26 | # For explanations see 27 | # http://dev.mysql.com/doc/mysql/en/server-system-variables.html 28 | 29 | [mysqld] 30 | pid-file = /var/run/mysqld/mysqld.pid 31 | socket = /var/run/mysqld/mysqld.sock 32 | datadir = /var/lib/mysql 33 | log-error = /var/log/mysql/error.log 34 | 35 | # By default we only accept connections from localhost 36 | # bind-address = 127.0.0.1 37 | 38 | # setting server id 39 | server-id = 2 40 | 41 | # Disabling symbolic-links is recommended to prevent assorted security risks 42 | symbolic-links=0 43 | 44 | # setting the base name & location of mysql bunary log file 45 | log_bin = /var/log/mysql/mysql-bin.log 46 | 47 | # name of database to replicate 48 | binlog_do_db = tyrell_corp 49 | 50 | # setting location of the replica's relay log file 51 | relay-log = /var/log/mysql/mysql-relay-bin.log 52 | -------------------------------------------------------------------------------- /0x14-mysql/5-mysql_backup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # backup and compress my databases 3 | mysqldump --all-databases -u root --password="$1" > backup.sql 4 | day=$(date +"%d") 5 | month=$(date +"%m") 6 | year=$(date +"%Y") 7 | file_name="$day-$month-$year.tar.gz" 8 | tar -czvf "$file_name" backup.sql 9 | -------------------------------------------------------------------------------- /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 | 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 | -------------------------------------------------------------------------------- /0x15-api/todo_all_employees.json: -------------------------------------------------------------------------------- 1 | {"1": [{"task": "delectus aut autem", "completed": false, "username": "Bret"}, {"task": "quis ut nam facilis et officia qui", "completed": false, "username": "Bret"}, {"task": "fugiat veniam minus", "completed": false, "username": "Bret"}, {"task": "et porro tempora", "completed": true, "username": "Bret"}, {"task": "laboriosam mollitia et enim quasi adipisci quia provident illum", "completed": false, "username": "Bret"}, {"task": "qui ullam ratione quibusdam voluptatem quia omnis", "completed": false, "username": "Bret"}, {"task": "illo expedita consequatur quia in", "completed": false, "username": "Bret"}, {"task": "quo adipisci enim quam ut ab", "completed": true, "username": "Bret"}, {"task": "molestiae perspiciatis ipsa", "completed": false, "username": "Bret"}, {"task": "illo est ratione doloremque quia maiores aut", "completed": true, "username": "Bret"}, {"task": "vero rerum temporibus dolor", "completed": true, "username": "Bret"}, {"task": "ipsa repellendus fugit nisi", "completed": true, "username": "Bret"}, {"task": "et doloremque nulla", "completed": false, "username": "Bret"}, {"task": "repellendus sunt dolores architecto voluptatum", "completed": true, "username": "Bret"}, {"task": "ab voluptatum amet voluptas", "completed": true, "username": "Bret"}, {"task": "accusamus eos facilis sint et aut voluptatem", "completed": true, "username": "Bret"}, {"task": "quo laboriosam deleniti aut qui", "completed": true, "username": "Bret"}, {"task": "dolorum est consequatur ea mollitia in culpa", "completed": false, "username": "Bret"}, {"task": "molestiae ipsa aut voluptatibus pariatur dolor nihil", "completed": true, "username": "Bret"}, {"task": "ullam nobis libero sapiente ad optio sint", "completed": true, "username": "Bret"}], "2": [{"task": "suscipit repellat esse quibusdam voluptatem incidunt", "completed": false, "username": "Antonette"}, {"task": "distinctio vitae autem nihil ut molestias quo", "completed": true, "username": "Antonette"}, {"task": "et itaque necessitatibus maxime molestiae qui quas velit", "completed": false, "username": "Antonette"}, {"task": "adipisci non ad dicta qui amet quaerat doloribus ea", "completed": false, "username": "Antonette"}, {"task": "voluptas quo tenetur perspiciatis explicabo natus", "completed": true, "username": "Antonette"}, {"task": "aliquam aut quasi", "completed": true, "username": "Antonette"}, {"task": "veritatis pariatur delectus", "completed": true, "username": "Antonette"}, {"task": "nesciunt totam sit blanditiis sit", "completed": false, "username": "Antonette"}, {"task": "laborum aut in quam", "completed": false, "username": "Antonette"}, {"task": "nemo perspiciatis repellat ut dolor libero commodi blanditiis omnis", "completed": true, "username": "Antonette"}, {"task": "repudiandae totam in est sint facere fuga", "completed": false, "username": "Antonette"}, {"task": "earum doloribus ea doloremque quis", "completed": false, "username": "Antonette"}, {"task": "sint sit aut vero", "completed": false, "username": "Antonette"}, {"task": "porro aut necessitatibus eaque distinctio", "completed": false, "username": "Antonette"}, {"task": "repellendus veritatis molestias dicta incidunt", "completed": true, "username": "Antonette"}, {"task": "excepturi deleniti adipisci voluptatem et neque optio illum ad", "completed": true, "username": "Antonette"}, {"task": "sunt cum tempora", "completed": false, "username": "Antonette"}, {"task": "totam quia non", "completed": false, "username": "Antonette"}, {"task": "doloremque quibusdam asperiores libero corrupti illum qui omnis", "completed": false, "username": "Antonette"}, {"task": "totam atque quo nesciunt", "completed": true, "username": "Antonette"}], "3": [{"task": "aliquid amet impedit consequatur aspernatur placeat eaque fugiat suscipit", "completed": false, "username": "Samantha"}, {"task": "rerum perferendis error quia ut eveniet", "completed": false, "username": "Samantha"}, {"task": "tempore ut sint quis recusandae", "completed": true, "username": "Samantha"}, {"task": "cum debitis quis accusamus doloremque ipsa natus sapiente omnis", "completed": true, "username": "Samantha"}, {"task": "velit soluta adipisci molestias reiciendis harum", "completed": false, "username": "Samantha"}, {"task": "vel voluptatem repellat nihil placeat corporis", "completed": false, "username": "Samantha"}, {"task": "nam qui rerum fugiat accusamus", "completed": false, "username": "Samantha"}, {"task": "sit reprehenderit omnis quia", "completed": false, "username": "Samantha"}, {"task": "ut necessitatibus aut maiores debitis officia blanditiis velit et", "completed": false, "username": "Samantha"}, {"task": "cupiditate necessitatibus ullam aut quis dolor voluptate", "completed": true, "username": "Samantha"}, {"task": "distinctio exercitationem ab doloribus", "completed": false, "username": "Samantha"}, {"task": "nesciunt dolorum quis recusandae ad pariatur ratione", "completed": false, "username": "Samantha"}, {"task": "qui labore est occaecati recusandae aliquid quam", "completed": false, "username": "Samantha"}, {"task": "quis et est ut voluptate quam dolor", "completed": true, "username": "Samantha"}, {"task": "voluptatum omnis minima qui occaecati provident nulla voluptatem ratione", "completed": true, "username": "Samantha"}, {"task": "deleniti ea temporibus enim", "completed": true, "username": "Samantha"}, {"task": "pariatur et magnam ea doloribus similique voluptatem rerum quia", "completed": false, "username": "Samantha"}, {"task": "est dicta totam qui explicabo doloribus qui dignissimos", "completed": false, "username": "Samantha"}, {"task": "perspiciatis velit id laborum placeat iusto et aliquam odio", "completed": false, "username": "Samantha"}, {"task": "et sequi qui architecto ut adipisci", "completed": true, "username": "Samantha"}], "4": [{"task": "odit optio omnis qui sunt", "completed": true, "username": "Karianne"}, {"task": "et placeat et tempore aspernatur sint numquam", "completed": false, "username": "Karianne"}, {"task": "doloremque aut dolores quidem fuga qui nulla", "completed": true, "username": "Karianne"}, {"task": "voluptas consequatur qui ut quia magnam nemo esse", "completed": false, "username": "Karianne"}, {"task": "fugiat pariatur ratione ut asperiores necessitatibus magni", "completed": false, "username": "Karianne"}, {"task": "rerum eum molestias autem voluptatum sit optio", "completed": false, "username": "Karianne"}, {"task": "quia voluptatibus voluptatem quos similique maiores repellat", "completed": false, "username": "Karianne"}, {"task": "aut id perspiciatis voluptatem iusto", "completed": false, "username": "Karianne"}, {"task": "doloribus sint dolorum ab adipisci itaque dignissimos aliquam suscipit", "completed": false, "username": "Karianne"}, {"task": "ut sequi accusantium et mollitia delectus sunt", "completed": false, "username": "Karianne"}, {"task": "aut velit saepe ullam", "completed": false, "username": "Karianne"}, {"task": "praesentium facilis facere quis harum voluptatibus voluptatem eum", "completed": false, "username": "Karianne"}, {"task": "sint amet quia totam corporis qui exercitationem commodi", "completed": true, "username": "Karianne"}, {"task": "expedita tempore nobis eveniet laborum maiores", "completed": false, "username": "Karianne"}, {"task": "occaecati adipisci est possimus totam", "completed": false, "username": "Karianne"}, {"task": "sequi dolorem sed", "completed": true, "username": "Karianne"}, {"task": "maiores aut nesciunt delectus exercitationem vel assumenda eligendi at", "completed": false, "username": "Karianne"}, {"task": "reiciendis est magnam amet nemo iste recusandae impedit quaerat", "completed": false, "username": "Karianne"}, {"task": "eum ipsa maxime ut", "completed": true, "username": "Karianne"}, {"task": "tempore molestias dolores rerum sequi voluptates ipsum consequatur", "completed": true, "username": "Karianne"}], "5": [{"task": "suscipit qui totam", "completed": true, "username": "Kamren"}, {"task": "voluptates eum voluptas et dicta", "completed": false, "username": "Kamren"}, {"task": "quidem at rerum quis ex aut sit quam", "completed": true, "username": "Kamren"}, {"task": "sunt veritatis ut voluptate", "completed": false, "username": "Kamren"}, {"task": "et quia ad iste a", "completed": true, "username": "Kamren"}, {"task": "incidunt ut saepe autem", "completed": true, "username": "Kamren"}, {"task": "laudantium quae eligendi consequatur quia et vero autem", "completed": true, "username": "Kamren"}, {"task": "vitae aut excepturi laboriosam sint aliquam et et accusantium", "completed": false, "username": "Kamren"}, {"task": "sequi ut omnis et", "completed": true, "username": "Kamren"}, {"task": "molestiae nisi accusantium tenetur dolorem et", "completed": true, "username": "Kamren"}, {"task": "nulla quis consequatur saepe qui id expedita", "completed": true, "username": "Kamren"}, {"task": "in omnis laboriosam", "completed": true, "username": "Kamren"}, {"task": "odio iure consequatur molestiae quibusdam necessitatibus quia sint", "completed": true, "username": "Kamren"}, {"task": "facilis modi saepe mollitia", "completed": false, "username": "Kamren"}, {"task": "vel nihil et molestiae iusto assumenda nemo quo ut", "completed": true, "username": "Kamren"}, {"task": "nobis suscipit ducimus enim asperiores voluptas", "completed": false, "username": "Kamren"}, {"task": "dolorum laboriosam eos qui iure aliquam", "completed": false, "username": "Kamren"}, {"task": "debitis accusantium ut quo facilis nihil quis sapiente necessitatibus", "completed": true, "username": "Kamren"}, {"task": "neque voluptates ratione", "completed": false, "username": "Kamren"}, {"task": "excepturi a et neque qui expedita vel voluptate", "completed": false, "username": "Kamren"}], "6": [{"task": "explicabo enim cumque porro aperiam occaecati minima", "completed": false, "username": "Leopoldo_Corkery"}, {"task": "sed ab consequatur", "completed": false, "username": "Leopoldo_Corkery"}, {"task": "non sunt delectus illo nulla tenetur enim omnis", "completed": false, "username": "Leopoldo_Corkery"}, {"task": "excepturi non laudantium quo", "completed": false, "username": "Leopoldo_Corkery"}, {"task": "totam quia dolorem et illum repellat voluptas optio", "completed": true, "username": "Leopoldo_Corkery"}, {"task": "ad illo quis voluptatem temporibus", "completed": true, "username": "Leopoldo_Corkery"}, {"task": "praesentium facilis omnis laudantium fugit ad iusto nihil nesciunt", "completed": false, "username": "Leopoldo_Corkery"}, {"task": "a eos eaque nihil et exercitationem incidunt delectus", "completed": true, "username": "Leopoldo_Corkery"}, {"task": "autem temporibus harum quisquam in culpa", "completed": true, "username": "Leopoldo_Corkery"}, {"task": "aut aut ea corporis", "completed": true, "username": "Leopoldo_Corkery"}, {"task": "magni accusantium labore et id quis provident", "completed": false, "username": "Leopoldo_Corkery"}, {"task": "consectetur impedit quisquam qui deserunt non rerum consequuntur eius", "completed": false, "username": "Leopoldo_Corkery"}, {"task": "quia atque aliquam sunt impedit voluptatum rerum assumenda nisi", "completed": false, "username": "Leopoldo_Corkery"}, {"task": "cupiditate quos possimus corporis quisquam exercitationem beatae", "completed": false, "username": "Leopoldo_Corkery"}, {"task": "sed et ea eum", "completed": false, "username": "Leopoldo_Corkery"}, {"task": "ipsa dolores vel facilis ut", "completed": true, "username": "Leopoldo_Corkery"}, {"task": "sequi quae est et qui qui eveniet asperiores", "completed": false, "username": "Leopoldo_Corkery"}, {"task": "quia modi consequatur vero fugiat", "completed": false, "username": "Leopoldo_Corkery"}, {"task": "corporis ducimus ea perspiciatis iste", "completed": false, "username": "Leopoldo_Corkery"}, {"task": "dolorem laboriosam vel voluptas et aliquam quasi", "completed": false, "username": "Leopoldo_Corkery"}], "7": [{"task": "inventore aut nihil minima laudantium hic qui omnis", "completed": true, "username": "Elwyn.Skiles"}, {"task": "provident aut nobis culpa", "completed": true, "username": "Elwyn.Skiles"}, {"task": "esse et quis iste est earum aut impedit", "completed": false, "username": "Elwyn.Skiles"}, {"task": "qui consectetur id", "completed": false, "username": "Elwyn.Skiles"}, {"task": "aut quasi autem iste tempore illum possimus", "completed": false, "username": "Elwyn.Skiles"}, {"task": "ut asperiores perspiciatis veniam ipsum rerum saepe", "completed": true, "username": "Elwyn.Skiles"}, {"task": "voluptatem libero consectetur rerum ut", "completed": true, "username": "Elwyn.Skiles"}, {"task": "eius omnis est qui voluptatem autem", "completed": false, "username": "Elwyn.Skiles"}, {"task": "rerum culpa quis harum", "completed": false, "username": "Elwyn.Skiles"}, {"task": "nulla aliquid eveniet harum laborum libero alias ut unde", "completed": true, "username": "Elwyn.Skiles"}, {"task": "qui ea incidunt quis", "completed": false, "username": "Elwyn.Skiles"}, {"task": "qui molestiae voluptatibus velit iure harum quisquam", "completed": true, "username": "Elwyn.Skiles"}, {"task": "et labore eos enim rerum consequatur sunt", "completed": true, "username": "Elwyn.Skiles"}, {"task": "molestiae doloribus et laborum quod ea", "completed": false, "username": "Elwyn.Skiles"}, {"task": "facere ipsa nam eum voluptates reiciendis vero qui", "completed": false, "username": "Elwyn.Skiles"}, {"task": "asperiores illo tempora fuga sed ut quasi adipisci", "completed": false, "username": "Elwyn.Skiles"}, {"task": "qui sit non", "completed": false, "username": "Elwyn.Skiles"}, {"task": "placeat minima consequatur rem qui ut", "completed": true, "username": "Elwyn.Skiles"}, {"task": "consequatur doloribus id possimus voluptas a voluptatem", "completed": false, "username": "Elwyn.Skiles"}, {"task": "aut consectetur in blanditiis deserunt quia sed laboriosam", "completed": true, "username": "Elwyn.Skiles"}], "8": [{"task": "explicabo consectetur debitis voluptates quas quae culpa rerum non", "completed": true, "username": "Maxime_Nienow"}, {"task": "maiores accusantium architecto necessitatibus reiciendis ea aut", "completed": true, "username": "Maxime_Nienow"}, {"task": "eum non recusandae cupiditate animi", "completed": false, "username": "Maxime_Nienow"}, {"task": "ut eum exercitationem sint", "completed": false, "username": "Maxime_Nienow"}, {"task": "beatae qui ullam incidunt voluptatem non nisi aliquam", "completed": false, "username": "Maxime_Nienow"}, {"task": "molestiae suscipit ratione nihil odio libero impedit vero totam", "completed": true, "username": "Maxime_Nienow"}, {"task": "eum itaque quod reprehenderit et facilis dolor autem ut", "completed": true, "username": "Maxime_Nienow"}, {"task": "esse quas et quo quasi exercitationem", "completed": false, "username": "Maxime_Nienow"}, {"task": "animi voluptas quod perferendis est", "completed": false, "username": "Maxime_Nienow"}, {"task": "eos amet tempore laudantium fugit a", "completed": false, "username": "Maxime_Nienow"}, {"task": "accusamus adipisci dicta qui quo ea explicabo sed vero", "completed": true, "username": "Maxime_Nienow"}, {"task": "odit eligendi recusandae doloremque cumque non", "completed": false, "username": "Maxime_Nienow"}, {"task": "ea aperiam consequatur qui repellat eos", "completed": false, "username": "Maxime_Nienow"}, {"task": "rerum non ex sapiente", "completed": true, "username": "Maxime_Nienow"}, {"task": "voluptatem nobis consequatur et assumenda magnam", "completed": true, "username": "Maxime_Nienow"}, {"task": "nam quia quia nulla repellat assumenda quibusdam sit nobis", "completed": true, "username": "Maxime_Nienow"}, {"task": "dolorem veniam quisquam deserunt repellendus", "completed": true, "username": "Maxime_Nienow"}, {"task": "debitis vitae delectus et harum accusamus aut deleniti a", "completed": true, "username": "Maxime_Nienow"}, {"task": "debitis adipisci quibusdam aliquam sed dolore ea praesentium nobis", "completed": true, "username": "Maxime_Nienow"}, {"task": "et praesentium aliquam est", "completed": false, "username": "Maxime_Nienow"}], "9": [{"task": "ex hic consequuntur earum omnis alias ut occaecati culpa", "completed": true, "username": "Delphine"}, {"task": "omnis laboriosam molestias animi sunt dolore", "completed": true, "username": "Delphine"}, {"task": "natus corrupti maxime laudantium et voluptatem laboriosam odit", "completed": false, "username": "Delphine"}, {"task": "reprehenderit quos aut aut consequatur est sed", "completed": false, "username": "Delphine"}, {"task": "fugiat perferendis sed aut quidem", "completed": false, "username": "Delphine"}, {"task": "quos quo possimus suscipit minima ut", "completed": false, "username": "Delphine"}, {"task": "et quis minus quo a asperiores molestiae", "completed": false, "username": "Delphine"}, {"task": "recusandae quia qui sunt libero", "completed": false, "username": "Delphine"}, {"task": "ea odio perferendis officiis", "completed": true, "username": "Delphine"}, {"task": "quisquam aliquam quia doloribus aut", "completed": false, "username": "Delphine"}, {"task": "fugiat aut voluptatibus corrupti deleniti velit iste odio", "completed": true, "username": "Delphine"}, {"task": "et provident amet rerum consectetur et voluptatum", "completed": false, "username": "Delphine"}, {"task": "harum ad aperiam quis", "completed": false, "username": "Delphine"}, {"task": "similique aut quo", "completed": false, "username": "Delphine"}, {"task": "laudantium eius officia perferendis provident perspiciatis asperiores", "completed": true, "username": "Delphine"}, {"task": "magni soluta corrupti ut maiores rem quidem", "completed": false, "username": "Delphine"}, {"task": "et placeat temporibus voluptas est tempora quos quibusdam", "completed": false, "username": "Delphine"}, {"task": "nesciunt itaque commodi tempore", "completed": true, "username": "Delphine"}, {"task": "omnis consequuntur cupiditate impedit itaque ipsam quo", "completed": true, "username": "Delphine"}, {"task": "debitis nisi et dolorem repellat et", "completed": true, "username": "Delphine"}], "10": [{"task": "ut cupiditate sequi aliquam fuga maiores", "completed": false, "username": "Moriah.Stanton"}, {"task": "inventore saepe cumque et aut illum enim", "completed": true, "username": "Moriah.Stanton"}, {"task": "omnis nulla eum aliquam distinctio", "completed": true, "username": "Moriah.Stanton"}, {"task": "molestias modi perferendis perspiciatis", "completed": false, "username": "Moriah.Stanton"}, {"task": "voluptates dignissimos sed doloribus animi quaerat aut", "completed": false, "username": "Moriah.Stanton"}, {"task": "explicabo odio est et", "completed": false, "username": "Moriah.Stanton"}, {"task": "consequuntur animi possimus", "completed": false, "username": "Moriah.Stanton"}, {"task": "vel non beatae est", "completed": true, "username": "Moriah.Stanton"}, {"task": "culpa eius et voluptatem et", "completed": true, "username": "Moriah.Stanton"}, {"task": "accusamus sint iusto et voluptatem exercitationem", "completed": true, "username": "Moriah.Stanton"}, {"task": "temporibus atque distinctio omnis eius impedit tempore molestias pariatur", "completed": true, "username": "Moriah.Stanton"}, {"task": "ut quas possimus exercitationem sint voluptates", "completed": false, "username": "Moriah.Stanton"}, {"task": "rerum debitis voluptatem qui eveniet tempora distinctio a", "completed": true, "username": "Moriah.Stanton"}, {"task": "sed ut vero sit molestiae", "completed": false, "username": "Moriah.Stanton"}, {"task": "rerum ex veniam mollitia voluptatibus pariatur", "completed": true, "username": "Moriah.Stanton"}, {"task": "consequuntur aut ut fugit similique", "completed": true, "username": "Moriah.Stanton"}, {"task": "dignissimos quo nobis earum saepe", "completed": true, "username": "Moriah.Stanton"}, {"task": "quis eius est sint explicabo", "completed": true, "username": "Moriah.Stanton"}, {"task": "numquam repellendus a magnam", "completed": true, "username": "Moriah.Stanton"}, {"task": "ipsam aperiam voluptates qui", "completed": false, "username": "Moriah.Stanton"}]} -------------------------------------------------------------------------------- /0x16-api_advanced/0-subs.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 3 | Contains the number_of_subscribers function 4 | """ 5 | 6 | import requests 7 | 8 | 9 | def number_of_subscribers(subreddit): 10 | """returns the number of subscribers for a given subreddit""" 11 | if subreddit is None or type(subreddit) is not str: 12 | return 0 13 | r = requests.get('http://www.reddit.com/r/{}/about.json'.format(subreddit), 14 | headers={'User-Agent': '0x16-api_advanced:project:\ 15 | v1.0.0 (by /u/firdaus_cartoon_jr)'}).json() 16 | subs = r.get("data", {}).get("subscribers", 0) 17 | return subs 18 | -------------------------------------------------------------------------------- /0x16-api_advanced/1-top_ten.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Contains top_ten function""" 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": "0x16-api_advanced:project:\ 11 | v1.0.0 (by /u/firdaus_cartoon_jr)" 12 | } 13 | params = { 14 | "limit": 10 15 | } 16 | response = requests.get(url, headers=headers, params=params, 17 | allow_redirects=False) 18 | if response.status_code == 404: 19 | print("None") 20 | return 21 | results = response.json().get("data") 22 | [print(c.get("data").get("title")) for c in results.get("children")] 23 | -------------------------------------------------------------------------------- /0x16-api_advanced/100-count.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ Module for a function that queries the Reddit API recursively.""" 3 | 4 | 5 | import requests 6 | 7 | 8 | def count_words(subreddit, word_list, after='', word_dict={}): 9 | """ A function that queries the Reddit API parses the title of 10 | all hot articles, and prints a sorted count of given keywords 11 | (case-insensitive, delimited by spaces. 12 | Javascript should count as javascript, but java should not). 13 | If no posts match or the subreddit is invalid, it prints nothing. 14 | """ 15 | 16 | if not word_dict: 17 | for word in word_list: 18 | if word.lower() not in word_dict: 19 | word_dict[word.lower()] = 0 20 | 21 | if after is None: 22 | wordict = sorted(word_dict.items(), key=lambda x: (-x[1], x[0])) 23 | for word in wordict: 24 | if word[1]: 25 | print('{}: {}'.format(word[0], word[1])) 26 | return None 27 | 28 | url = 'https://www.reddit.com/r/{}/hot/.json'.format(subreddit) 29 | header = {'user-agent': 'redquery'} 30 | parameters = {'limit': 100, 'after': after} 31 | response = requests.get(url, headers=header, params=parameters, 32 | allow_redirects=False) 33 | 34 | if response.status_code != 200: 35 | return None 36 | 37 | try: 38 | hot = response.json()['data']['children'] 39 | aft = response.json()['data']['after'] 40 | for post in hot: 41 | title = post['data']['title'] 42 | lower = [word.lower() for word in title.split(' ')] 43 | 44 | for word in word_dict.keys(): 45 | word_dict[word] += lower.count(word) 46 | 47 | except Exception: 48 | return None 49 | 50 | count_words(subreddit, word_list, aft, word_dict) -------------------------------------------------------------------------------- /0x16-api_advanced/2-recurse.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Contains recurse function""" 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": "0x16-api_advanced:project:\ 11 | v1.0.0 (by /u/firdaus_cartoon_jr)" 12 | } 13 | params = { 14 | "after": after, 15 | "count": count, 16 | "limit": 100 17 | } 18 | response = requests.get(url, headers=headers, params=params, 19 | allow_redirects=False) 20 | if response.status_code == 404: 21 | return None 22 | 23 | results = response.json().get("data") 24 | after = results.get("after") 25 | count += results.get("dist") 26 | for c in results.get("children"): 27 | hot_list.append(c.get("data").get("title")) 28 | 29 | if after is not None: 30 | return recurse(subreddit, hot_list, after, count) 31 | return hot_list 32 | -------------------------------------------------------------------------------- /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 ALX. 9 | 10 | ## Function Prototypes :floppy_disk: 11 | 12 | Prototypes for functions written in this project: 13 | 14 | | File | Prototype | 15 | | -------------- | --------------------------------------- | 16 | | `0-subs.py` | `def number_of_subscribers(subreddit)` | 17 | | `1-top_ten.py` | `def top_ten(subreddit)` | 18 | | `2-recurse.py` | `def recurse(subreddit, hot_list=[])` | 19 | | `100-count.py` | `def count_words(subreddit, word_list)` | 20 | 21 | ## Tasks :page_with_curl: 22 | 23 | * **0. How many subs?** 24 | * [0-subs.py](./0-subs.py): Python function that returns the total number of 25 | subscribers for a given subreddit. 26 | * Returns `0` if an invalid subreddit is given. 27 | 28 | * **1. Top Ten** 29 | * [1-top_ten.py](./1-top_ten.py): Python function that prints the top ten 30 | hottest posts for a given subreddit. 31 | * Prints `None` if an invalid subreddit is given. 32 | 33 | * **2. Recurse it!** 34 | * [2-recurse.py](./2-recurse.py): Python function that recursively returns a 35 | list of titles for all hot articles on a given subreddit. 36 | * Returns `None` if no results are found on the given subreddit. 37 | 38 | * **3. Count it!** 39 | * [100-count.py](./100-count.py): Python function that recursively prints a 40 | sorted count of given keywords parsed from titles of all hot articles on a given 41 | subreddit. 42 | * Keywords are case-insensitive and delimited by spaces. 43 | * Results are printed in descending order by count. 44 | * Words with identical counts are sorted alphabetically. 45 | * Words with no matches are skipped. 46 | * Results are based on the number of times a keyword appears - ie., 47 | `java java java` counts as three separate instances of `java`. 48 | -------------------------------------------------------------------------------- /0x16-api_advanced/tests/0-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 3 | 0-main 4 | """ 5 | import sys 6 | 7 | if __name__ == '__main__': 8 | number_of_subscribers = __import__('0-subs').number_of_subscribers 9 | if len(sys.argv) < 2: 10 | print("Please pass an argument for the subreddit to search.") 11 | else: 12 | print("{:d}".format(number_of_subscribers(sys.argv[1]))) 13 | -------------------------------------------------------------------------------- /0x16-api_advanced/tests/1-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 3 | 1-main 4 | """ 5 | import sys 6 | 7 | if __name__ == '__main__': 8 | top_ten = __import__('1-top_ten').top_ten 9 | if len(sys.argv) < 2: 10 | print("Please pass an argument for the subreddit to search.") 11 | else: 12 | top_ten(sys.argv[1]) 13 | -------------------------------------------------------------------------------- /0x16-api_advanced/tests/100-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 3 | 100-main 4 | """ 5 | import sys 6 | 7 | if __name__ == '__main__': 8 | count_words = __import__('100-count').count_words 9 | if len(sys.argv) < 3: 10 | print("Usage: {} ".format(sys.argv[0])) 11 | print("Ex: {} programming 'python java javascript'".format(sys.argv[0])) 12 | else: 13 | result = count_words(sys.argv[1], [x for x in sys.argv[2].split()]) 14 | -------------------------------------------------------------------------------- /0x16-api_advanced/tests/2-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 3 | 2-main 4 | """ 5 | import sys 6 | 7 | if __name__ == '__main__': 8 | recurse = __import__('2-recurse').recurse 9 | if len(sys.argv) < 2: 10 | print("Please pass an argument for the subreddit to search.") 11 | else: 12 | result = recurse(sys.argv[1]) 13 | if result is not None: 14 | print(len(result)) 15 | else: 16 | print("None") 17 | -------------------------------------------------------------------------------- /0x17-web_stack_debugging_3/0-strace_is_your_friend.pp: -------------------------------------------------------------------------------- 1 | # Fixes bad `phpp` extensions to `php` in the WordPress file `wp-settings.php`. 2 | 3 | exec { 'fix-wordpress': 4 | command => 'sed -i s/phpp/php/g /var/www/html/wp-settings.php', 5 | path => '/usr/local/bin/:/bin/' 6 | } 7 | -------------------------------------------------------------------------------- /0x17-web_stack_debugging_3/README.md: -------------------------------------------------------------------------------- 1 | # Web stack debugging #3 2 | 3 | This was the fourth 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. Strace is your friend** 12 | * [0-strace_is_your_friend.pp](./0-strace_is_your_friend.pp): Puppet manifest 13 | that fixes a typo error causing a WordPress application being served by an Apache 14 | web server to fail. 15 | * Usage: `puppet apply 0-strace_is_your_friend.pp` 16 | -------------------------------------------------------------------------------- /0x18-webstack_monitoring/0-monitor_your_nginx_traffic: -------------------------------------------------------------------------------- 1 | suMaSD0Wx3DPAZ 2 | 7RCGZINfJojNUWDfqFgR4LNPrWbfItz4AIWJFY4UbdyxJSqf3poffvSDItdXzHPK 3 | -------------------------------------------------------------------------------- /0x18-webstack_monitoring/README.md: -------------------------------------------------------------------------------- 1 | # Webstack monitoring 2 | 3 | This project invovled setting up Sumo Logic accounts to monitor server traffic 4 | on my three HBnB servers. 5 | 6 | ## Tasks :page_with_curl: 7 | 8 | * **0. Monitor your Nginx traffic** 9 | * [0-monitor_your_nginx_traffic](./0-monitor_your_nginx_traffic): Text file containing 10 | my Sumo Logic access key. 11 | * First line: `Access ID` 12 | * Second line: `Access Key` 13 | 14 | * **1. Monitor your server** 15 | * For this task, I configured Sumo Logic to monitor my server's memory, CPU, network 16 | and disk. 17 | -------------------------------------------------------------------------------- /0x19-postmortem/README.md: -------------------------------------------------------------------------------- 1 | # Postmortem 2 | 3 | Upon the release of ALX's System Engineering & DevOps project 0x19, 4 | approximately 06:00 West African Time (WAT) here in Nigeria, an outage occurred on an isolated 5 | Ubuntu 14.04 container running an Apache web server. GET requests on the server led to 6 | `500 Internal Server Error`'s, when the expected response was an HTML file defining a 7 | simple Holberton WordPress site. 8 | 9 | ## Debugging Process 10 | 11 | Bug debugger Brennan (BDB... as in my actual initials... made that up on the spot, pretty 12 | good, huh?) encountered the issue upon opening the project and being, well, instructed to 13 | address it, roughly 19:20 PST. He promptly proceeded to undergo solving the problem. 14 | 15 | 1. Checked running processes using `ps aux`. Two `apache2` processes - `root` and `www-data` - 16 | were properly running. 17 | 18 | 2. Looked in the `sites-available` folder of the `/etc/apache2/` directory. Determined that 19 | the web server was serving content located in `/var/www/html/`. 20 | 21 | 3. In one terminal, ran `strace` on the PID of the `root` Apache process. In another, curled 22 | the server. Expected great things... only to be disappointed. `strace` gave no useful 23 | information. 24 | 25 | 4. Repeated step 3, except on the PID of the `www-data` process. Kept expectations lower this 26 | time... but was rewarded! `strace` revelead an `-1 ENOENT (No such file or directory)` error 27 | occurring upon an attempt to access the file `/var/www/html/wp-includes/class-wp-locale.phpp`. 28 | 29 | 5. Looked through files in the `/var/www/html/` directory one-by-one, using Vim pattern 30 | matching to try and locate the erroneous `.phpp` file extension. Located it in the 31 | `wp-settings.php` file. (Line 137, `require_once( ABSPATH . WPINC . '/class-wp-locale.php' );`). 32 | 33 | 6. Removed the trailing `p` from the line. 34 | 35 | 7. Tested another `curl` on the server. 200 A-ok! 36 | 37 | 8. Wrote a Puppet manifest to automate fixing of the error. 38 | 39 | ## Summation 40 | 41 | In short, a typo. Gotta love'em. In full, the WordPress app was encountering a critical 42 | error in `wp-settings.php` when tyring to load the file `class-wp-locale.phpp`. The correct 43 | file name, located in the `wp-content` directory of the application folder, was 44 | `class-wp-locale.php`. 45 | 46 | Patch involved a simple fix on the typo, removing the trailing `p`. 47 | 48 | ## Prevention 49 | 50 | This outage was not a web server error, but an application error. To prevent such outages 51 | moving forward, please keep the following in mind. 52 | 53 | * Test! Test test test. Test the application before deploying. This error would have arisen 54 | and could have been addressed earlier had the app been tested. 55 | 56 | * Status monitoring. Enable some uptime-monitoring service such as 57 | [UptimeRobot](./https://uptimerobot.com/) to alert instantly upon outage of the website. 58 | 59 | Note that in response to this error, I wrote a Puppet manifest 60 | [0-strace_is_your_friend.pp](https://github.com/bdbaraban/holberton-system_engineering-devops/blob/master/0x17-web_stack_debugging_3/0-strace_is_your_friend.pp) 61 | to automate fixing of any such identitical errors should they occur in the future. The manifest 62 | replaces any `phpp` extensions in the file `/var/www/html/wp-settings.php` with `php`. 63 | 64 | But of course, it will never occur again, because we're programmers, and we never make 65 | errors! :wink: 66 | -------------------------------------------------------------------------------- /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 ALX 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/aysuarex/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/Tijani1402/AirBnB_clone_v31) 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/aysuarex/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 | # Increases the amount of traffic an Nginx server can handle. 2 | 3 | # Increase the ULIMIT of the default file 4 | exec { 'fix--for-nginx': 5 | command => 'sed -i "s/15/4096/" /etc/default/nginx', 6 | path => '/usr/local/bin/:/bin/' 7 | } -> 8 | 9 | # Restart Nginx 10 | exec { 'nginx-restart': 11 | command => 'nginx restart', 12 | path => '/etc/init.d/' 13 | } 14 | -------------------------------------------------------------------------------- /0x1B-web_stack_debugging_4/1-user_limit.pp: -------------------------------------------------------------------------------- 1 | # Enable the user holberton to login and open files without error. 2 | 3 | # Increase hard file limit for Holberton user. 4 | exec { 'increase-hard-file-limit-for-holberton-user': 5 | command => 'sed -i "/holberton hard/s/5/50000/" /etc/security/limits.conf', 6 | path => '/usr/local/bin/:/bin/' 7 | } 8 | 9 | # Increase soft file limit for Holberton user. 10 | exec { 'increase-soft-file-limit-for-holberton-user': 11 | command => 'sed -i "/holberton soft/s/4/50000/" /etc/security/limits.conf', 12 | path => '/usr/local/bin/:/bin/' 13 | } 14 | -------------------------------------------------------------------------------- /0x1B-web_stack_debugging_4/README.md: -------------------------------------------------------------------------------- 1 | # Web stack debugging #4 2 | 3 | This was the fifth 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. Sky is the limit, let's bring that limit higher** 12 | * [0-the_sky_is_the_limit_not.pp](./0-the_sky_is_the_limit_not.pp): Puppet manifest 13 | that increases the amount of traffic an Apache web server can effectively handle. 14 | 15 | * **1. User limit** 16 | * [1-user_limit.pp](./1-user_limit.pp): Puppet manifest that changes the operating system 17 | configuration so that it is possible to login with the user `holberton` and open a file 18 | without error. 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # System engineering & Devops 2 | 3 | Module of **System engineering** and **Devops**, carried out during **Full Stack Software Engineering studies** at **[ALX](https://www.alxafrica.com/)**. 4 | 5 | ## Projects 6 | All of the following folders are projects done during the studies: 7 | 8 | | Project name | Description | 9 | | ------------ | ----------- | 10 | | [`0x00-shell_basics`](https://github.com/aysuarex/alx-system_engineering-devops/tree/master/0x00-shell_basics) | It aims to learn about basics commands, navigation, files and directories in **Shell** | 11 | | [`0x01-shell_permissions`](https://github.com/aysuarex/alx-system_engineering-devops/tree/master/0x01-shell_permissions) | It aims to learn about man pages, permissions (owner, group and other) of files and directories in **Shell** | 12 | | [`0x02-shell_redirections`](https://github.com/aysuarex/alx-system_engineering-devops/tree/master/0x02-shell_redirections) | It aims to learn about how to handle standard input and output and how to combine commands and filters with redirections in **Shell** | 13 | | [`0x03-shell_variable_expansions`](https://github.com/aysuarex/alx-system_engineering-devops/tree/master/0x03-shell_variables_expansions) | It aims to learn about alias builtin, help builtin, local, global and reserved variables (PATH, HOME and PS1), special parameters `$?` and single an double quotes in **Shell** | 14 | | [`0x04-loops_conditions_and_parsing`](https://github.com/aysuarex/alx-system_engineering-devops/tree/master/0x04-loops_conditions_and_parsing) | It aims to learn about loops (`while`, `until` and `for`), condition statements (`if`, `else`, `elif` and `case`), shebangs and how to create SSH keys with **Bash** | 15 | | [`0x05-processes_and_signals`](https://github.com/aysuarex/alx-system_engineering-devops/tree/master/0x05-processes_and_signals) | It aims to learn about PID, processes and commands that handles them (`ps`, `pgrep`, `pkill`, `kill`, etc) in **Bash** | 16 | | [`0x06-regular_expressions`](https://github.com/aysuarex/alx-system_engineering-devops/edit/master/0x06-regular_expressions) | It aims to learn about how to build a regular expression | 17 | | [`0x07-networking_basics`](https://github.com/aysuarex/alx-system_engineering-devops/edit/master/0x07-networking_basics) | It aims to learn about what is an OSI model, LAN, WAN, IP address, localhost, subnet and TCP/UDP | 18 | | [`0x08-networking_basics_2`](https://github.com/aysuarex/alx-system_engineering-devops/edit/master/0x08-networking_basics_2) | It aims to learn about what is localhost/127.0.0.1, what is 0.0.0.0, what is `/etc/hosts` and how to display the machine's active network interfaces | 19 | | [`0x09-web_infrastructure_design`](https://github.com/aysuarex/alx-system_engineering-devops/edit/master/0x09-web_infrastructure_design) | It aims to learn about how to design a Web Infrastructure | 20 | | [`0x0A-configuration_management`](https://github.com/aysuarex/alx-system_engineering-devops/edit/master/0x0A-configuration_management) | It aims to learn about server configuration management using **Puppet** | 21 | | [`0x0B-ssh`](https://github.com/aysuarex/alx-system_engineering-devops/edit/master/0x0B-ssh) | It aims to learn about what is a SSH, how to create an SSH RSA key pair and how to connect to a remote host using SSH | 22 | | [`0x0C-web_server`](https://github.com/aysuarex/alx-system_engineering-devops/edit/master/0x0C-web_server) | It aims to learn about the roles of `web servers` and their processes (parent and child), and DNS roles | 23 | | [`0x0D-web_stack_debugging_0`](https://github.com/aysuarex/alx-system_engineering-devops/tree/master/0x0D-web_stack_debugging_0) | It aims to learn about how to debug a webstack | 24 | | [`0x0E-web_stack_debugging_1`](https://github.com/aysuarex/alx-system_engineering-devops/tree/master/0x0E-web_stack_debugging_1) | It aims to provide further knowledge on how to debug a webstack | 25 | | [`0x0F-load_balancer`](https://github.com/aysuarex/alx-system_engineering-devops/tree/master/0x0F-load_balancer) | It aims to learn about how to setup and use a load balancer distributing network load across multiple servers | 26 | | [`0x10-https_ssl`](https://github.com/aysuarex/alx-system_engineering-devops/tree/master/0x10-https_ssl) | This aims to learn about SSL certificates and authentication | 27 | | [`0x11-what_happens_when_your_type_google_com_in_your_browser_and_press_enter`](https://github.com/aysuarex/alx-system_engineering-devops/tree/master/0x11-what_happens_when_your_type_google_com_in_your_browser_and_press_enter) | This aims to write an article explaining the intricacies of what happens when one makes a google search | 28 | | [`0x12-web_stack_debugging_2`](https://github.com/aysuarex/alx-system_engineering-devops/tree/master/0x12-web_stack_debugging_2) | This aims to provide further knowledge of what was previously learned in webstack debugging | 29 | | [`0x13-firewall`](https://github.com/aysuarex/alx-system_engineering-devops/tree/master/0x13-firewall) | This aims to learm about firewalls and how to set them up for servers | 30 | | [`0x14-mysql`](https://github.com/aysuarex/alx-system_engineering-devops/tree/master/0x14-mysql) | This aims to learn how to incorporate the use of MySQL in this module | 31 | | [`0x15-api`](https://github.com/aysuarex/alx-system_engineering-devops/tree/master/0x15-api) | This aims to learn how to incorporate the use of api in this module | 32 | | [`Command Line For The Win`](https://github.com/aysuarex/alx-system_engineering-devops/tree/master/command_line_for_the_win) | This aims to gain mastery of command line commands across different difficulties | 33 | | [`Attack Is The Best Defense`](https://github.com/aysuarex/alx-system_engineering-devops/tree/master/attack_is_the_best_defense) | .. | 34 | 35 | ## Author : 36 | * **[Suara Ayomide](https://twitter.com/Aysuarex)** <[Aysuarex](https://github.com/Aysuarex)> 37 | 38 | ## Acknowledgements :pray: 39 | 40 | All work contained in this project was completed as part of the curriculum for the ALX-SE programme. ALX Africa is an online full-stack software engineering program that prepares students for careers in the tech industry using project-based peer learning. For more information, visit [this link](https://www.alxafrica.com//): 41 | 42 | 43 |

44 | ALX Africa Logo 47 |

48 | -------------------------------------------------------------------------------- /attack_is_the_best_defense/0-sniffing: -------------------------------------------------------------------------------- 1 | mypassword9898! -------------------------------------------------------------------------------- /attack_is_the_best_defense/1-dictionary_attack: -------------------------------------------------------------------------------- 1 | password123 -------------------------------------------------------------------------------- /attack_is_the_best_defense/README.md: -------------------------------------------------------------------------------- 1 | # Attack is the best defense 2 | 3 | ## Tools 4 | 5 | * wireshark 6 | * telnet 7 | * tcpdump 8 | * docker 9 | * hydra 10 | 11 | ## 0-0-sniffing 12 | 13 | ### what is this 14 | 15 | Security is a vast topic, and network security is an important part of it. A lot of very sensitive information goes over networks that are used by many people, and some people might have bad intentions. Traffic going through a network can be intercepted by a malicious machine pretending to be another network device. Once the traffic is redirected to the malicious machine, the hacker can keep a copy of it and analyze it for potential interesting information. It is important to note that the traffic must then be forwarded to the actual device it was supposed to go (so that users and the system keep going as if nothing happened). 16 | 17 | Any information that is not encrypted and sniffed by an attacker can be seen by the attacker - that could be your email password or credit card information. While today’s network security is much stronger than it used to be, there are still some legacy systems that are using unencrypted communication means. A popular one is telnet. 18 | 19 | In this project, we will not go over ARP spoofing, but we’ll start by sniffing unencrypted traffic and getting information out of it. 20 | 21 | Sendgrid offers is an emailing service that provides state of the art secure system to send emails, but also supports a legacy unsecured way: telnet. You can create an account for free, which is what I did, and send an email using telnet 22 | 23 | I wrote the script user_authenticating_into_server that performs the authentication steps that I just showed above. Your mission is to execute user_authenticating_into_server locally on your machine and, using tcpdump, sniff the network to find my password. Once you find it, paste the password in your answer file. This script will not work on a Docker container or Mac OS, use your Ubuntu vagrant machine or any other Linux machine. 24 | 25 | You can download the script user_authenticating_into_server [here](https://s3.amazonaws.com/intranet-projects-files/holbertonschool-sysadmin_devops/264/user_authenticating_into_server) 26 | 27 | ### solution 28 | 29 | * The code in ASCII = bXlwYXNzd29yZDk4OTgh7 30 | 31 | * user name : mylogin 32 | 33 | ### Packet 34 | 35 | ```packet 36 | 0000 d8 b6 b7 a1 1f 63 cc b0 da 2a bf b6 08 00 45 10 .....c...*....E. 37 | 0010 00 4a 40 f2 40 00 40 06 62 67 c0 a8 01 07 12 c5 .J@.@.@.bg...... 38 | 0020 c2 d0 b5 12 02 4b 67 8b 60 d1 67 35 59 20 80 18 .....Kg.`.g5Y .. 39 | 0030 01 f5 a3 88 00 00 01 01 08 0a 21 35 2c 39 b2 84 ..........!5,9.. 40 | 0040 5c 4c 62 58 6c 77 59 58 4e 7a 64 32 39 79 5a 44 \LbXlwYXNzd29yZD 41 | 0050 6b 34 4f 54 67 68 0d 0a k4OTgh.. 42 | ``` 43 | 44 | ## 1-dictionary_attack 45 | 46 | Password-based authentication systems can be easily broken by using a dictionary attack (you’ll have to find your own password dictionary). Let’s try it on an SSH account. 47 | 48 | * Install Docker on your machine Ubuntu Vagrant machine 49 | * Pull and run the Docker image sylvainkalache/264-1 with the command docker run -p 2222:22 -d -ti sylvainkalache/264-1 50 | * Find a password dictionary (you might need multiple of them) 51 | * Install and use hydra to try to brute force the account sylvain via SSH on the Docker container 52 | * Because the Docker container is running locally, hydra should access the SSH account via IP 127.0.0.1 and port 2222 53 | * Hint: the password is 11 characters long 54 | -------------------------------------------------------------------------------- /command_line_for_the_win/0-first_9_tasks.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aysuarex/alx-system_engineering-devops/283a99104d8125884229beb21110f1277e220ac2/command_line_for_the_win/0-first_9_tasks.jpg -------------------------------------------------------------------------------- /command_line_for_the_win/0-first_9_tasks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aysuarex/alx-system_engineering-devops/283a99104d8125884229beb21110f1277e220ac2/command_line_for_the_win/0-first_9_tasks.png -------------------------------------------------------------------------------- /command_line_for_the_win/1-next_9_tasks.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aysuarex/alx-system_engineering-devops/283a99104d8125884229beb21110f1277e220ac2/command_line_for_the_win/1-next_9_tasks.jpg -------------------------------------------------------------------------------- /command_line_for_the_win/1-next_9_tasks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aysuarex/alx-system_engineering-devops/283a99104d8125884229beb21110f1277e220ac2/command_line_for_the_win/1-next_9_tasks.png -------------------------------------------------------------------------------- /command_line_for_the_win/12dayscmdchallenge.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aysuarex/alx-system_engineering-devops/283a99104d8125884229beb21110f1277e220ac2/command_line_for_the_win/12dayscmdchallenge.jpg -------------------------------------------------------------------------------- /command_line_for_the_win/12dayscmdchallenge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aysuarex/alx-system_engineering-devops/283a99104d8125884229beb21110f1277e220ac2/command_line_for_the_win/12dayscmdchallenge.png -------------------------------------------------------------------------------- /command_line_for_the_win/2-next_9_tasks.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aysuarex/alx-system_engineering-devops/283a99104d8125884229beb21110f1277e220ac2/command_line_for_the_win/2-next_9_tasks.jpg -------------------------------------------------------------------------------- /command_line_for_the_win/2-next_9_tasks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aysuarex/alx-system_engineering-devops/283a99104d8125884229beb21110f1277e220ac2/command_line_for_the_win/2-next_9_tasks.png -------------------------------------------------------------------------------- /command_line_for_the_win/3-next_9_tasks.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aysuarex/alx-system_engineering-devops/283a99104d8125884229beb21110f1277e220ac2/command_line_for_the_win/3-next_9_tasks.jpg -------------------------------------------------------------------------------- /command_line_for_the_win/3-next_9_tasks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aysuarex/alx-system_engineering-devops/283a99104d8125884229beb21110f1277e220ac2/command_line_for_the_win/3-next_9_tasks.png -------------------------------------------------------------------------------- /command_line_for_the_win/4-last_6_tasks.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aysuarex/alx-system_engineering-devops/283a99104d8125884229beb21110f1277e220ac2/command_line_for_the_win/4-last_6_tasks.jpg -------------------------------------------------------------------------------- /command_line_for_the_win/4-last_6_tasks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aysuarex/alx-system_engineering-devops/283a99104d8125884229beb21110f1277e220ac2/command_line_for_the_win/4-last_6_tasks.png -------------------------------------------------------------------------------- /command_line_for_the_win/README.md: -------------------------------------------------------------------------------- 1 | # Command Line For The Win 2 | 3 | These are screenshots from my progress in the [CMDCHALLENGE](https://cmdchallenge.com/). 4 | 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 repository contains projects from all three categories of the command-line challenge: 8 | - The [cmdchallenge](https://cmdchallenge.com/) with 42 tasks 9 | - The [oops.cmdchallenge](https://oops.cmdchallenge.com/) with 5 tasks 10 | - and The [12days.cmdchallenge](https://12days.cmdchallenge.com/) with 12 tasks 11 | 12 | 13 | I have provided the screenshots both in .png and .jpg format 14 | -------------------------------------------------------------------------------- /command_line_for_the_win/oopscmdchallenge.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aysuarex/alx-system_engineering-devops/283a99104d8125884229beb21110f1277e220ac2/command_line_for_the_win/oopscmdchallenge.jpg -------------------------------------------------------------------------------- /command_line_for_the_win/oopscmdchallenge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aysuarex/alx-system_engineering-devops/283a99104d8125884229beb21110f1277e220ac2/command_line_for_the_win/oopscmdchallenge.png --------------------------------------------------------------------------------