├── 0x00-shell_basics ├── .school.mgc.swp ├── 0-current_working_directory ├── 1-listit ├── 10-back ├── 100-lets_move ├── 101-clean_emacs ├── 102-tree ├── 103-commas ├── 11-lists ├── 12-file_type ├── 13-symbolic_link ├── 14-copy_html ├── 2-bring_me_home ├── 3-listfiles ├── 4-listmorefiles ├── 5-listfilesdigitonly ├── 6-firstdirectory ├── 7-movethatfile ├── 8-firstdelete ├── 9-firstdirdeletion ├── README.md └── 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 ├── .7-file.swp ├── 0-hello_world ├── 1-confused_smiley ├── 10-no_more_js ├── 100-empty_casks ├── 101-gifs ├── 102-acrostic ├── 103-the_biggest_fan ├── 11-directories ├── 12-newest_files ├── 13-unique ├── 14-findthatword ├── 15-countthatword ├── 16-whatsnext ├── 17-hidethisword ├── 18-letteronly ├── 19-AZ ├── 2-hellofile ├── 20-hiago ├── 21-reverse ├── 22-users_and_homes ├── 3-twofiles ├── 4-lastlines ├── 5-firstlines ├── 6-third_line ├── 7-file ├── 8-cwd_state ├── 9-duplicate_last_line └── README.md ├── 0x03-shell_variables_expansions ├── 0-alias ├── 1-hello_you ├── 10-love_exponent_breath ├── 100-decimal_to_hexadecimal ├── 101-rot13 ├── 102-odd ├── 103-water_and_stir ├── 11-binary_to_decimal ├── 12-combinations ├── 13-print_float ├── 2-path ├── 3-paths ├── 4-global_variables ├── 5-local_variables ├── 6-create_local_variable ├── 7-create_global_variable ├── 8-true_knowledge ├── 9-divide_and_rule └── README.md ├── 0x04-loops_conditions_and_parsing ├── 0-RSA_public_key.pub ├── 1-for_best_school ├── 10-fizzbuzz ├── 100-read_and_cut ├── 101-tell_the_story_of_passwd ├── 102-lets_parse_apache_logs ├── 103-dig_the-data ├── 2-while_best_school ├── 3-until_best_school ├── 4-if_9_say_hi ├── 5-4_bad_luck_8_is_your_chance ├── 6-superstitious_numbers ├── 7-clock ├── 8-for_ls ├── 9-to_file_or_not_to_file ├── README.md └── apache-access.log ├── 0x05-processes_and_signals ├── 0-what-is-my-pid ├── 1-list_your_processes ├── 100-process_and_pid_file ├── 101-manage_my_process ├── 102-zombie.c ├── 2-show_your_bash_pid ├── 3-show_your_bash_pid_made_easy ├── 4-to_infinity_and_beyond ├── 5-dont_stop_me_now ├── 6-stop_me_if_you_can ├── 67-stop_me_if_you_can ├── 7-highlander ├── 8-beheaded_process ├── README.md └── manage_my_process ├── 0x06-regular_expressions ├── 0-simply_match_school.rb ├── 1-repetition_token_0.rb ├── 100-textme.rb ├── 2-repetition_token_1.rb ├── 3-repetition_token_2.rb ├── 4-repetition_token_3.rb ├── 5-beginning_and_end.rb ├── 6-phone_number.rb ├── 7-OMG_WHY_ARE_YOU_SHOUTING.rb └── README.md ├── 0x07-networking_basics ├── 0-OSI_model ├── 1-types_of_network ├── 2-MAC_and_IP_address ├── 3-UDP_and_TCP ├── 4-TCP_and_UDP_ports ├── 5-is_the_host_on_the_network └── README.md ├── 0x08-networking_basics_2 ├── 0-change_your_home_IP ├── 1-show_attached_IPs ├── 100-port_listening_on_localhost └── README.md ├── 0x09-web_infrastructure_design ├── 0-simple_web_stack ├── 1-distributed_web_infrastructure ├── 2-secured_and_monitored_web_infrastructure ├── 3-scale_up └── README.md ├── 0x0A-configuration_management ├── 0-create_a_file.pp ├── 1-install_a_package.pp ├── 2-execute_a_command.pp └── README.md ├── 0x0B-ssh ├── .ssh │ └── authorized_keys ├── 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 ├── 0x12-web_stack_debugging_2 ├── 0-iamsomeoneelse ├── 1-run_nginx_as_nginx ├── 100-fix_in_7_lines_or_less └── README.md ├── 0x13-firewall ├── 0-block_all_incoming_traffic_but ├── 100-port_forwarding └── README.md ├── 0x14-mysql ├── 4-mysql_configuration_primary ├── 4-mysql_configuration_replica ├── 5-mysql_backup └── README.md ├── 0x15-api ├── 0-gather_data_from_an_API.py ├── 1-export_to_CSV.py ├── 2-export_to_JSON.py ├── 3-dictionary_of_list_of_dictionaries.py └── README.md ├── 0x16-api_advanced ├── 0-subs.py ├── 1-top_ten.py ├── 100-count.py ├── 2-recurse.py └── README.md ├── 0x17-web_stack_debugging_3 ├── 0-strace_is_your_friend.pp └── README.md ├── 0x18-webstack_monitoring ├── 2-setup_datadog └── 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 └── 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 ├── 2-next_9_tasks.jpg ├── 2-next_9_tasks.png └── README.md /0x00-shell_basics/.school.mgc.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sirtuns4real/alx-system_engineering-devops/387c62676a507452a5e2373100471eb4c11f9669/0x00-shell_basics/.school.mgc.swp -------------------------------------------------------------------------------- /0x00-shell_basics/0-current_working_directory: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | pwd 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/1-listit: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ls 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/10-back: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd - 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/100-lets_move: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | mv [[:upper:]]* /tmp/u 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/101-clean_emacs: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | rm *~ 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/102-tree: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | mkdir -p welcome/to/school 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/103-commas: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ls -pamv 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/11-lists: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ls -al . .. /boot 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/12-file_type: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | file /tmp/iamafile 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/13-symbolic_link: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ln -s /bin/ls __ls__ 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/14-copy_html: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cp -nu *.html .. 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/2-bring_me_home: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd /root 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/3-listfiles: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ls -l 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/4-listmorefiles: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ls -la 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/5-listfilesdigitonly: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ls -an 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/6-firstdirectory: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | mkdir -p /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 | rm -r /tmp/my_first_directory 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /0x00-shell_basics/school.mgc: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | -------------------------------------------------------------------------------- /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 -u -n 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/10-mirror_permissions: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chmod --referenc olleh hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/100-change_owner_and_group: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chown vincent:staff * 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/101-symbolic_link_permissions: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chown -h vincent:staff _hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/102-if_only: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chown --from=guillaume betty hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/103-Star_Wars: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | telnet towel.blinkenlights.nl 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/11-directories_permissions: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chmod a+x */ 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/12-directory_permissions: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | mkdir -m 751 my_dir 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/13-change_group: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chgrp school hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/2-groups: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | groups 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/3-new_owner: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 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 754 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 | readme 2 | -------------------------------------------------------------------------------- /0x02-shell_redirections/.7-file.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sirtuns4real/alx-system_engineering-devops/387c62676a507452a5e2373100471eb4c11f9669/0x02-shell_redirections/.7-file.swp -------------------------------------------------------------------------------- /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 . -type f -name "*.js" -delete 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/100-empty_casks: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | find . -empty | rev | cut -d "/" -f 1 | 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 -c 1 | paste -s -d '' 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/103-the_biggest_fan: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | tail -n +2 | cut -f -1 | sort -k 1 | uniq -c | sort -rnk 1 | head -n 11 | rev | cut -d ' ' -f -1 | rev 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/11-directories: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | find . -type d -not -name '.' | wc -l 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/12-newest_files: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ls -t1 | head -n 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 -i "root" /etc/passwd 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/15-countthatword: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | grep -c -i "bin" /etc/passwd 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/16-whatsnext: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | grep -i "root" -A 3 /etc/passwd 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/17-hidethisword: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | grep -i -v "bin" /etc/passwd 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/18-letteronly: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | grep -i "^[a-z]" /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 "cC" 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 -n 10 /etc/passwd 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/5-firstlines: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | head -n 10 /etc/passwd 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/6-third_line: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | head -n 3 iacta | tail -n 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 -n 1 iacta >> iacta 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/README.md: -------------------------------------------------------------------------------- 1 | script that parses web servers logs in TSV format as input and displays the 11 hosts or IP addresses which did the most requests 2 | -------------------------------------------------------------------------------- /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 | perl -lne 'print if $. %2==1' 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 "%0.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 | readme 2 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/0-RSA_public_key.pub: -------------------------------------------------------------------------------- 1 | ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDDABa1DMGu+d/Mv9jYok6Onkr/ATAMWvE5wORSVMSBxXgWkaY3A6Bkjj8Vo8lcb4mYEhZB4OHEnFa3qVX4wXQ8b3dzPdj40H99TvhHUdtV+ILBHKA7PFlUCGPBzKkH7N/t1g3WlEA9vD17kbnw75W2pNT2/WZ2qBsTO24KI/c9V3HehlFFUN1xCV5Wb//eS9byMP4NoSz7BVF3e9ufxhjGYBpsaCr1dkhSd5NzReisoK29Zx5gYAbWuecSA8JwY7UqXhgodvMkQeGRNb1os8gF2c0Qr5mL40mUdAjeVN5eMtVZT4OVLLAQdK32DV1TzLUMheXIzP9/RbAUIFqpPB3fVGIKVoVSp2DE22gPwzEKYItXgnefESS7HVsBgxHRZ1KD/v667CgVtfmTthP4vG1Uiq945ve9pwTdTXtP4yijdUxxB55pC1pALTVNvB9RjrMRXXFdXLv75Rskr/0IZd0xTARsfeYsFQiTxQ9EjVNgUMPIMwutitZAPH/A9Z1h6xQYaEzLIqhymyeoytO0Gllzfpu/cM+jkt9s2jfj43QFtLMn3MBDg4JBp8rW6giGoEjKIwGylqJo1tXUaWDEQtC4DqEm2udky8AEgZzySZL4Lwod+7y4EdVDuKUxHv+SLIHWRHvKU6ZQcqqtvNcjGd0AE5KN4XxcuBk2ErusVjFZqQ== root@a925b137a73b 2 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/1-for_best_school: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #A bash script that displays Best School 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 | #A bash script that displays Best School 10 times using while loop 3 | 4 | count=0 5 | 6 | while [ $count -lt 10 ] 7 | do 8 | echo "Best School" 9 | (( count++ )) 10 | done 11 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/3-until_best_school: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays "Best School" 10 times using an until loop. 3 | 4 | count=0 5 | 6 | until [ $count -eq 10 ] 7 | do 8 | echo "Best School" 9 | (( count++ )) 10 | done 11 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/4-if_9_say_hi: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays "Best School" 10 times using a while loop. 3 | # On the 9th iteration, displays "Hi" before "Best School". 4 | 5 | count=0 6 | 7 | while [ $count -lt 10 ] 8 | do 9 | if [ $count -eq 9 ] 10 | then 11 | echo "Hi" 12 | fi 13 | echo "Best School" 14 | (( count++ )) 15 | done 16 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/5-4_bad_luck_8_is_your_chance: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Loops from 1 to 10 and displays: 3 | # "bad luck" for the 4th iteration 4 | # "good luck" for the 8th iteration 5 | # "Best School" for all other iterations 6 | 7 | count=0 8 | 9 | while [ $count -lt 10 ] 10 | do 11 | if [ $count -eq 3 ] 12 | then 13 | echo "bad luck" 14 | elif [ $count -eq 7 ] 15 | then 16 | echo "good luck" 17 | else 18 | echo "Best School" 19 | fi 20 | (( count++ )) 21 | done 22 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/6-superstitious_numbers: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays numbers from 1 to 20 in addition to: 3 | # "bad luck from China" for the 4th iteration 4 | # "bad luck from Japan" for the 9th iteration 5 | # "bad luck from Italy" for the 17th loop iteration 6 | 7 | count=1 8 | 9 | while [ $count -le 20 ] 10 | do 11 | echo "$count" 12 | case $count in 13 | "4") echo "bad luck from China";; 14 | "9") echo "bad luck from Japan";; 15 | "17") echo "bad luck from Italy";; 16 | esac 17 | (( count++ )) 18 | done 19 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/7-clock: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays the time for 12 horus and 59 minutes. 3 | # Displays hours from 0 to 12 4 | # Displays minutes from 1 to 59 5 | 6 | hour=0 7 | 8 | while [ $hour -le 12 ] 9 | do 10 | echo "Hour: $hour" 11 | minute=1 12 | while [ $minute -le 59 ] 13 | do 14 | echo "$minute" 15 | (( minute++ )) 16 | done 17 | (( hour++ )) 18 | done 19 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/8-for_ls: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays the contents of the current directory in list format. 3 | # Only displays the part of the name after the first dash. 4 | 5 | list=$(ls) 6 | for i in $list; do 7 | echo "$i" | cut -d '-' -f2 8 | done 9 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/9-to_file_or_not_to_file: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays information about the `school` file. 3 | 4 | if [ -e "school" ] 5 | then 6 | echo "school file exists" 7 | if [ -s "school" ] 8 | then 9 | echo "school file is not empty" 10 | else 11 | echo "school file is empty" 12 | fi 13 | 14 | if [ -f "school" ] 15 | then 16 | echo "school is a regular file" 17 | fi 18 | else 19 | echo "school file does not exist" 20 | fi 21 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/README.md: -------------------------------------------------------------------------------- 1 | loop condition and parsing in bash scripts 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' SIGQUIT 24 | done 25 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/101-manage_my_process: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Manages the script manage_my_process. 3 | # When passed the argument `start`: 4 | # 1. Starts manage_my_process 5 | # 2. Creates a file containings its PID in /var/run/my_process.pid 6 | # 3. Displays "manage_my_process started" 7 | # When passed the argument `stop`: 8 | # 1. Stops manage_my_process 9 | # 2. Deletes the file /var/run/my_process.pid 10 | # 3. Displays "manage_my_process stopped" 11 | # When passed the argument `restart`: 12 | # 1. Stops manage_my_process 13 | # 2. Deletes the file /var/run/my_process.pid 14 | # 3. Starts manage_my_process 15 | # 4. Creates a file containing its PID in /var/run/my_process.pid 16 | # 5. Displays "manage_my_process restarted" 17 | # If any other or no arguments are passed, displays 18 | #+ "Usage: manage_my_process {start|stop|restart}" 19 | 20 | if [ "${1}" == "start" ] 21 | then 22 | ./manage_my_process & 23 | touch /var/run/my_process.pid 24 | echo "$!" > /var/run/my_process.pid 25 | echo "manage_my_process started" 26 | elif [ "${1}" == "stop" ] 27 | then 28 | echo "manage_my_process stopped" 29 | kill "$(cat /var/run/my_process.pid)" 30 | rm /var/run/my_process.pid 31 | elif [ "${1}" == "restart" ] 32 | then 33 | kill "$(cat /var/run/my_process.pid)" 34 | rm /var/run/my_process.pid 35 | ./manage_my_process & 36 | touch /var/run/my_process.pid 37 | echo "$!" > /var/run/my_process.pid 38 | echo "manage_my_process restarted" 39 | else 40 | echo "Usage: manage_my_process {start|stop|restart}" 41 | fi 42 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/102-zombie.c: -------------------------------------------------------------------------------- 1 | /* 2 | * File: 102-zombie.c 3 | * Auth: Brennan D Baraban 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | /** 13 | * infinite_while - Run an infinite while loop. 14 | * 15 | * Return: Always 0. 16 | */ 17 | int infinite_while(void) 18 | { 19 | while (1) 20 | { 21 | sleep(1); 22 | } 23 | return (0); 24 | } 25 | 26 | /** 27 | * main - Creates five zombie processes. 28 | * 29 | * Return: Always 0. 30 | */ 31 | int main(void) 32 | { 33 | pid_t pid; 34 | char count = 0; 35 | 36 | while (count < 5) 37 | { 38 | pid = fork(); 39 | if (pid > 0) 40 | { 41 | printf("Zombie process created, PID: %d\n", pid); 42 | sleep(1); 43 | count++; 44 | } 45 | else 46 | exit(0); 47 | } 48 | 49 | infinite_while(); 50 | 51 | return (EXIT_SUCCESS); 52 | } 53 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/2-show_your_bash_pid: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays a list of currently running processes containing the bash keyword. 3 | # shellcheck disable=SC2009 4 | 5 | ps -aux | grep bash 6 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/3-show_your_bash_pid_made_easy: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays the PID along with the process name, of 3 | #+ processes whose name contains the word "bash". 4 | 5 | pgrep bash -l 6 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/4-to_infinity_and_beyond: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays "To infinity and beyond" indefinitely with 3 | #+ a sleep 2 in between each iteration. 4 | 5 | while true 6 | do 7 | echo "To infinity and beyond" 8 | sleep 2 9 | done 10 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/5-dont_stop_me_now: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Kills the 4-to_infinity_and_beyond process 3 | 4 | kill "$(pgrep -f 4-to_infinity_and_beyond)" 5 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/6-stop_me_if_you_can: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Kills the 4-to_infinity_and_beyond process. 3 | 4 | pkill -f 4-to_infinity_and_beyond 5 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/67-stop_me_if_you_can: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Kills the 4-to_infinity_and_beyond process. 3 | 4 | pkill -f 7-highlander 5 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/7-highlander: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays "To infinity and beyond" indefinitely with 3 | #+ a sleep 2 in between each iteration. 4 | # Displays "I am invincible!!!" in between each iteration. 5 | 6 | while true 7 | do 8 | echo "To infinity and beyond" 9 | sleep 2 10 | trap 'echo "I am invincible!!!"' SIGTERM 11 | done 12 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/8-beheaded_process: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Kills the process 7-highlander. 3 | 4 | pkill -f -SIGKILL 7-highlander 5 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/README.md: -------------------------------------------------------------------------------- 1 | 0x05-processes_and_signals 2 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/manage_my_process: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Indefinitely writes "I am alive" to the file /tmp/my_process. 3 | # Pauses two seconds in between each message. 4 | 5 | while true 6 | do 7 | echo "I am alive!" >> /tmp/my_process 8 | sleep 2 9 | done 10 | -------------------------------------------------------------------------------- /0x06-regular_expressions/0-simply_match_school.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # A regex expression to that accepts one argument and pass it to a regular expression matching method 3 | 4 | puts ARGV[0].scan(/School/).join 5 | -------------------------------------------------------------------------------- /0x06-regular_expressions/1-repetition_token_0.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | #A Ruby script that accepts one argument and pass it to a regular expression matching method 3 | 4 | puts ARGV[0].scan(/hbt{2,5}n/).join 5 | -------------------------------------------------------------------------------- /0x06-regular_expressions/100-textme.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # script should output: [SENDER],[RECEIVER],[FLAGS] 3 | 4 | puts ARGV[0].scan(/\[from:(.*)\] \[to:(.*)\] \[flags:(.*?)\]/).join(",") 5 | -------------------------------------------------------------------------------- /0x06-regular_expressions/2-repetition_token_1.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # a Ruby script that accepts one argument and pass it to a regular expression matching method 3 | 4 | puts ARGV[0].scan(/hb?tn/).join 5 | -------------------------------------------------------------------------------- /0x06-regular_expressions/3-repetition_token_2.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # a Ruby script that accepts one argument and pass it to a regular expression matching method 3 | 4 | puts ARGV[0].scan(/hbt+n/).join 5 | -------------------------------------------------------------------------------- /0x06-regular_expressions/4-repetition_token_3.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | #create a Ruby script that accepts one argument and pass it to a regular expression matching method 3 | 4 | puts ARGV[0].scan(/hbt*n/).join 5 | -------------------------------------------------------------------------------- /0x06-regular_expressions/5-beginning_and_end.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # , create a Ruby script that accepts one argument and pass it to a regular expression matching method 3 | 4 | puts ARGV[0].scan(/^h.n$/).join 5 | -------------------------------------------------------------------------------- /0x06-regular_expressions/6-phone_number.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | #create a Ruby script that accepts one argument and pass it to a regular expression matching method 3 | 4 | puts ARGV[0].scan(/^\d{10,10}$/).join 5 | -------------------------------------------------------------------------------- /0x06-regular_expressions/7-OMG_WHY_ARE_YOU_SHOUTING.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | #create a Ruby script that accepts one argument and pass it to a regular expression matching method 3 | 4 | puts ARGV[0].scan(/[A-Z]+/).join 5 | -------------------------------------------------------------------------------- /0x06-regular_expressions/README.md: -------------------------------------------------------------------------------- 1 | 0x06-regular_expressions 2 | -------------------------------------------------------------------------------- /0x07-networking_basics/0-OSI_model: -------------------------------------------------------------------------------- 1 | 2 2 | 2 3 | -------------------------------------------------------------------------------- /0x07-networking_basics/1-types_of_network: -------------------------------------------------------------------------------- 1 | 3 2 | 2 3 | 1 4 | -------------------------------------------------------------------------------- /0x07-networking_basics/2-MAC_and_IP_address: -------------------------------------------------------------------------------- 1 | 2 2 | 1 3 | -------------------------------------------------------------------------------- /0x07-networking_basics/3-UDP_and_TCP: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 1 4 | -------------------------------------------------------------------------------- /0x07-networking_basics/4-TCP_and_UDP_ports: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays listening ports. Includes listening sockets as well 3 | # + as the PID and name of the program to which each socket belongs. 4 | 5 | netstat -l --program 6 | -------------------------------------------------------------------------------- /0x07-networking_basics/5-is_the_host_on_the_network: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Pings an IP address received as an argument 5 times. 3 | 4 | if [ $# -eq 0 ] 5 | then 6 | echo "Usage: 5-is_the_host_on_the_network {IP_ADDRESS}" 7 | else 8 | ping -c 5 "$1" 9 | fi 10 | -------------------------------------------------------------------------------- /0x07-networking_basics/README.md: -------------------------------------------------------------------------------- 1 | 0x07-networking_basics 2 | -------------------------------------------------------------------------------- /0x08-networking_basics_2/0-change_your_home_IP: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Configures an Ubuntu server as follows: 3 | # - localhost resolves to 127.0.0.2 4 | # - facebook.com resolves to 8.8.8.8 5 | 6 | cp /etc/hosts ~/hosts.new 7 | echo "127.0.0.2 localhost" > ~/hosts.new 8 | echo "8.8.8.8 facebook.com" >> ~/hosts.new 9 | cp -f ~/hosts.new /etc/hosts 10 | -------------------------------------------------------------------------------- /0x08-networking_basics_2/1-show_attached_IPs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays all acive IPv4 addresses on the machine. 3 | 4 | ifconfig | grep -Eo "inet (addr:)?([0-9]*\.){3}[0-9]*" | cut -b 11- 5 | -------------------------------------------------------------------------------- /0x08-networking_basics_2/100-port_listening_on_localhost: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Listens on port 98 on localhost. 3 | 4 | while true; do 5 | nc -l localhost 98 6 | done 7 | -------------------------------------------------------------------------------- /0x08-networking_basics_2/README.md: -------------------------------------------------------------------------------- 1 | 0x08-networking_basics_2 2 | -------------------------------------------------------------------------------- /0x09-web_infrastructure_design/0-simple_web_stack: -------------------------------------------------------------------------------- 1 | https://imgur.com/a/JnoU2Pa 2 | -------------------------------------------------------------------------------- /0x09-web_infrastructure_design/1-distributed_web_infrastructure: -------------------------------------------------------------------------------- 1 | https://imgur.com/a/weoVU8j 2 | -------------------------------------------------------------------------------- /0x09-web_infrastructure_design/2-secured_and_monitored_web_infrastructure: -------------------------------------------------------------------------------- 1 | https://imgur.com/a/iYaSz5J 2 | -------------------------------------------------------------------------------- /0x09-web_infrastructure_design/3-scale_up: -------------------------------------------------------------------------------- 1 | https://imgur.com/a/Jk4lHdn 2 | -------------------------------------------------------------------------------- /0x09-web_infrastructure_design/README.md: -------------------------------------------------------------------------------- 1 | 0x09-web_infrastructure_design 2 | -------------------------------------------------------------------------------- /0x0A-configuration_management/0-create_a_file.pp: -------------------------------------------------------------------------------- 1 | # Creates a file in tmp 2 | 3 | file { '/tmp/school': 4 | ensure => file, 5 | path => '/tmp/school', 6 | mode => '0744', 7 | owner => 'www-data', 8 | group => 'www-data', 9 | content => 'I love Puppet' 10 | } 11 | -------------------------------------------------------------------------------- /0x0A-configuration_management/1-install_a_package.pp: -------------------------------------------------------------------------------- 1 | # Installs flask, version 2.1.0. 2 | 3 | package { 'flask': 4 | ensure => '2.1.0', 5 | provider => 'pip3', 6 | } 7 | -------------------------------------------------------------------------------- /0x0A-configuration_management/2-execute_a_command.pp: -------------------------------------------------------------------------------- 1 | # Kills a process with puppet 2 | 3 | exec { 'pkill killmenow': 4 | path => '/usr/bin', 5 | command => 'pkill killmenow', 6 | provider => shell, 7 | returns => [0, 1] 8 | } 9 | -------------------------------------------------------------------------------- /0x0A-configuration_management/README.md: -------------------------------------------------------------------------------- 1 | 0x0A. Configuration management 2 | -------------------------------------------------------------------------------- /0x0B-ssh/.ssh/authorized_keys: -------------------------------------------------------------------------------- 1 | ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCw0Ij0w4dtt/ijhc8EKOL9a9BBLMvhVkHfWOkO9iLiRY5FaBc0HO6kOOoRINS7e3ym2RRb2xxcCXx7VtbzpWbVXDagIIa1dy+4z7QBm3HcbDLXLDM+0ZmKeCJBn1MKFJyKAMsKoGs3sv1L9cbAGvnplLCT39L+TIsxiLTxAIygq7J+A4DlD/WasMQMvWQvXMGjroNCZAetjf/iQF4UzaLwhbg6w90VC/6OvRscq+IgA755zIhcNc00g5MKXeHwyU7f0KAYGNUKkBV7+hh1ENrmgSADUfWCeudkVl7UB9tO2nLO/5JJkAxxoWPnorj7ngLYl/J1DSjgrrtmpTuU+Bzz root@31db4baebef8 2 | -------------------------------------------------------------------------------- /0x0B-ssh/0-use_a_private_key: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #A script that connects to serve through a private key 3 | 4 | ssh -i ~/.ssh/school ubuntu@<100.26.225.174 5 | -------------------------------------------------------------------------------- /0x0B-ssh/1-create_ssh_key_pair: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #Script to generate an SSh key 3 | 4 | ssh-keygen -t rsa -f school -b 4096 -N betty 5 | -------------------------------------------------------------------------------- /0x0B-ssh/100-puppet_ssh_config.pp: -------------------------------------------------------------------------------- 1 | # Seting up my client config file 2 | include stdlib 3 | 4 | file_line { 'Turn off passwd auth': 5 | ensure => present, 6 | path => '/etc/ssh/ssh_config', 7 | line => ' PasswordAuthentication no', 8 | replace => true, 9 | } 10 | 11 | file_line { 'Delare identity file': 12 | ensure => present, 13 | path => '/etc/ssh/ssh_config', 14 | line => ' IdentityFile ~/.ssh/school', 15 | replace => true, 16 | } 17 | -------------------------------------------------------------------------------- /0x0B-ssh/2-ssh_config: -------------------------------------------------------------------------------- 1 | #comingOpenSSH_8.2p1 Ubuntu-4ubuntu0.4, OpenSSL 1.1.1f 31 Mar 2020 2 | debug1: Reading configuration data /etc/ssh/ssh_config 3 | debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files 4 | debug1: /etc/ssh/ssh_config line 21: Applying options for * 5 | debug1: Connecting to 34.229.189.43 [34.229.189.43] port 22. 6 | debug1: Connection established. 7 | debug1: SELinux support disabled 8 | debug1: identity file /root/.ssh/id_rsa type -1 9 | debug1: identity file /root/.ssh/id_rsa-cert type -1 10 | debug1: identity file /root/.ssh/id_dsa type -1 11 | debug1: identity file /root/.ssh/id_dsa-cert type -1 12 | debug1: identity file /root/.ssh/id_ecdsa type -1 13 | debug1: identity file /root/.ssh/id_ecdsa-cert type -1 14 | debug1: identity file /root/.ssh/id_ecdsa_sk type -1 15 | debug1: identity file /root/.ssh/id_ecdsa_sk-cert type -1 16 | debug1: identity file /root/.ssh/id_ed25519 type -1 17 | debug1: identity file /root/.ssh/id_ed25519-cert type -1 18 | debug1: identity file /root/.ssh/id_ed25519_sk type -1 19 | debug1: identity file /root/.ssh/id_ed25519_sk-cert type -1 20 | debug1: identity file /root/.ssh/id_xmss type -1 21 | debug1: identity file /root/.ssh/id_xmss-cert type -1 22 | debug1: Local version string SSH-2.0-OpenSSH_8.2p1 Ubuntu-4ubuntu0.4 23 | debug1: Remote protocol version 2.0, remote software version OpenSSH_8.2p1 Ubuntu-4ubuntu0.5 24 | debug1: match: OpenSSH_8.2p1 Ubuntu-4ubuntu0.5 pat OpenSSH* compat 0x04000000 25 | debug1: Authenticating to 34.229.189.43:22 as 'ubuntu' 26 | debug1: SSH2_MSG_KEXINIT sent 27 | debug1: SSH2_MSG_KEXINIT received 28 | debug1: kex: algorithm: curve25519-sha256 29 | debug1: kex: host key algorithm: ecdsa-sha2-nistp256 30 | debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: compression: none 31 | debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: compression: none 32 | debug1: expecting SSH2_MSG_KEX_ECDH_REPLY 33 | debug1: Server host key: ecdsa-sha2-nistp256 SHA256:djGCCGNpKpeuvOZqny5/SN8mwOLjHzLFLFtmIUHj/Ig 34 | The authenticity of host '34.229.189.43 (34.229.189.43)' can't be established. 35 | ECDSA key fingerprint is SHA256:djGCCGNpKpeuvOZqny5/SN8mwOLjHzLFLFtmIUHj/Ig. 36 | Are you sure you want to continue connecting (yes/no/[fingerprint])? yes 37 | Warning: Permanently added '34.229.189.43' (ECDSA) to the list of known hosts. 38 | debug1: rekey out after 134217728 blocks 39 | debug1: SSH2_MSG_NEWKEYS sent 40 | debug1: expecting SSH2_MSG_NEWKEYS 41 | debug1: SSH2_MSG_NEWKEYS received 42 | debug1: rekey in after 134217728 blocks 43 | debug1: Will attempt key: /root/.ssh/id_rsa 44 | debug1: Will attempt key: /root/.ssh/id_dsa 45 | debug1: Will attempt key: /root/.ssh/id_ecdsa 46 | debug1: Will attempt key: /root/.ssh/id_ecdsa_sk 47 | debug1: Will attempt key: /root/.ssh/id_ed25519 48 | debug1: Will attempt key: /root/.ssh/id_ed25519_sk 49 | debug1: Will attempt key: /root/.ssh/id_xmss 50 | debug1: SSH2_MSG_EXT_INFO received 51 | debug1: kex_input_ext_info: server-sig-algs= 52 | debug1: SSH2_MSG_SERVICE_ACCEPT received 53 | debug1: Authentications that can continue: publickey 54 | debug1: Next authentication method: publickey 55 | debug1: Trying private key: /root/.ssh/id_rsa 56 | debug1: Trying private key: /root/.ssh/id_dsa 57 | debug1: Trying private key: /root/.ssh/id_ecdsa 58 | debug1: Trying private key: /root/.ssh/id_ecdsa_sk 59 | debug1: Trying private key: /root/.ssh/id_ed25519 60 | debug1: Trying private key: /root/.ssh/id_ed25519_sk 61 | debug1: Trying private key: /root/.ssh/id_xmss 62 | debug1: No more authentication methods to try. 63 | ubuntu@34.229.189.43: Permission denied (publickey) 64 | -------------------------------------------------------------------------------- /0x0B-ssh/README.md: -------------------------------------------------------------------------------- 1 | 0x0B. SSH 2 | -------------------------------------------------------------------------------- /0x0C-web_server/0-transfer_file: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Check if there are enough arguments 3 | 4 | if [ "$#" -lt 3 ] 5 | then 6 | echo "Usage: 0-transfer_file PATH_TO_FILE IP USERNAME PATH_TO_SSH_KEY" 7 | elif [ "$#" -eq 3 ] 8 | then 9 | scp -o StrictHostKeyChecking=no "$1" "$3@$2:~/" 10 | else 11 | scp -o StrictHostKeyChecking=no -i "$4" "$1" "$3@$2:~/" 12 | fi 13 | -------------------------------------------------------------------------------- /0x0C-web_server/1-install_nginx_web_server: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Script that installs Nginx server 3 | apt-get -y update 4 | apt-get -y install nginx 5 | echo "Hello World!" > /var/www/html/index.nginx-debian.html 6 | service nginx start 7 | -------------------------------------------------------------------------------- /0x0C-web_server/2-setup_a_domain_name: -------------------------------------------------------------------------------- 1 | sirtuns4real.tech 2 | -------------------------------------------------------------------------------- /0x0C-web_server/3-redirection: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Script that installs Nginx server and redirects /redirect_me 3 | apt-get -y update 4 | apt-get -y install nginx 5 | echo "Hello World!" > /var/www/html/index.nginx-sirtuns4real.html 6 | sed -i "s/server_name _;/server_name _;\n\trewrite ^\/redirect_me https:\/\/github.com\/luischaparroc permanent;/" /etc/nginx/sites-available/default 7 | service nginx start 8 | -------------------------------------------------------------------------------- /0x0C-web_server/4-not_found_page_404: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Script that installs Nginx server, redirects /redirect_me and customizes 404 not found 3 | apt-get -y update 4 | apt-get -y install nginx 5 | echo "Hello World!" > /var/www/html/index.nginx-debian.html 6 | echo "Ceci n'est pas une page" > /usr/share/nginx/html/custom_404.html 7 | sed -i "s/server_name _;/server_name _;\n\trewrite ^\/redirect_me https:\/\/github.com\/luischaparroc permanent;\n\n\terror_page 404 \/custom_404.html;\n\tlocation = \/custom_404.html {\n\t\troot \/usr\/share\/nginx\/html;\n\t\tinternal;\n\t}/" /etc/nginx/sites-available/default 8 | service nginx start 9 | -------------------------------------------------------------------------------- /0x0C-web_server/7-puppet_install_nginx_web_server.pp: -------------------------------------------------------------------------------- 1 | # Installs a Nginx server 2 | 3 | exec {'install': 4 | provider => shell, 5 | command => 'sudo apt-get -y update ; sudo apt-get -y install nginx ; echo "Hello World!" | sudo tee /var/www/html/index.nginx-debian.html ; sudo sed -i "s/server_name _;/server_name _;\n\trewrite ^\/redirect_me https:\/\/github.com\/luischaparroc permanent;/" /etc/nginx/sites-available/default ; sudo service nginx start', 6 | } 7 | -------------------------------------------------------------------------------- /0x0C-web_server/README.md: -------------------------------------------------------------------------------- 1 | 0x0C-web_server 2 | -------------------------------------------------------------------------------- /0x0D-web_stack_debugging_0/0-give_me_a_page: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # A Script that turns on an Apache Server container 3 | service apache2 start 4 | -------------------------------------------------------------------------------- /0x0D-web_stack_debugging_0/README.md: -------------------------------------------------------------------------------- 1 | 0x0D-web_stack_debugging_0 2 | -------------------------------------------------------------------------------- /0x0E-web_stack_debugging_1/0-nginx_likes_port_80: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # This bash script configures Nginx to run and listen on port 80 in an Ubuntu container. 3 | sudo rm /etc/nginx/sites-enabled/default 4 | sudo ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default 5 | sudo service nginx restart 6 | -------------------------------------------------------------------------------- /0x0E-web_stack_debugging_1/1-debugging_made_short: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Configure Nginx to run and listen on port 80 3 | sed -i 's/8080/80/g' /etc/nginx/sites-enabled/default 4 | service nginx restart 5 | echo "" > /run/nginx.pid 6 | -------------------------------------------------------------------------------- /0x0E-web_stack_debugging_1/README.md: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD 2 | 0x0E-web_stack_debugging_1 3 | ======= 4 | 0x0E. Web stack debugging #1 5 | >>>>>>> f7425f7324f6702c3619e9a01a03143c538c4a3a 6 | -------------------------------------------------------------------------------- /0x0F-load_balancer/0-custom_http_response_header: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # configure web-02 to be identical to web-01 3 | # The name of the custom HTTP header must be X-Served-By 4 | # The value of the custom HTTP header must be the hostname of the server Nginx is running on 5 | #!/usr/bin/env bash 6 | 7 | # Update package repositories 8 | sudo apt-get -y update 9 | 10 | # Install Nginx 11 | sudo apt-get -y install nginx 12 | 13 | # Allow Nginx HTTP traffic 14 | sudo ufw allow 'Nginx HTTP' 15 | 16 | # Create necessary directories and set permissions 17 | sudo mkdir -p /var/www/html /var/www/error 18 | sudo chmod -R 755 /var/www 19 | 20 | # Create index and 404 pages 21 | echo 'Hello World!' | sudo tee /var/www/html/index.html >/dev/null 22 | echo "Ceci n'est pas une page" | sudo tee /var/www/html/404.html >/dev/null 23 | 24 | # Configure Nginx with custom header 25 | server_config=$(cat </dev/null 48 | 49 | # Restart Nginx service 50 | sudo service nginx restart 51 | -------------------------------------------------------------------------------- /0x0F-load_balancer/1-install_load_balancer: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Installs, configures, and starts the load balancer 3 | # Update package lists 4 | sudo apt-get update 5 | 6 | # Install HAProxy 7 | sudo apt-get install haproxy -y 8 | 9 | # Configure HAProxy 10 | sudo tee /etc/haproxy/haproxy.cfg > /dev/null < 'apt-get -y update && apt-get -y install nginx && sed -i "/listen 80 default_server;/a add_header X-Served-By $HOSTNAME;" /etc/nginx/sites-available/default && service nginx restart', 4 | provider => shell, 5 | } 6 | -------------------------------------------------------------------------------- /0x0F-load_balancer/README.md: -------------------------------------------------------------------------------- 1 | 0x0F-load_balancer 2 | -------------------------------------------------------------------------------- /0x10-https_ssl/0-world_wide_web: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Display information about subdomains. 3 | 4 | domain_information () { 5 | line=$(dig "$2"."$1" | grep -A1 'ANSWER SECTION:' | tr '\t' '\n' | tail -2 | tr '\n' ' ') 6 | echo "$2 $line" | awk '{print "The subdomain " $1 " is a " $2 " record and points to " $3}' 7 | } 8 | 9 | if [ "$#" == 1 ] 10 | then 11 | domain_information "$1" "www" 12 | domain_information "$1" "lb-01" 13 | domain_information "$1" "web-01" 14 | domain_information "$1" "web-02" 15 | elif [ "$#" == 2 ] 16 | then 17 | domain_information "$1" "$2" 18 | fi 19 | -------------------------------------------------------------------------------- /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 beta-scribbles.tech 37 | frontend betascribbles.tech-http-frontend 38 | bind *:80 39 | http-request set-header X-Forwarded-Proto http 40 | default_backend beta-scribbles.tech-backend 41 | 42 | 43 | frontend beta-scribbles.tech-https-frontend 44 | bind *:443 ssl crt /etc/ssl/beta-scribbles.tech.pem 45 | http-request set-header X-Forwarded-Proto https 46 | default_backend beta-scribbles.tech-backend 47 | 48 | 49 | backend beta-scribbles.tech-backend 50 | balance roundrobin 51 | server 914-web-01 34.138.32.248:80 check 52 | server 914-web-02 3.226.74.205:80 check 53 | # end of parameters 54 | -------------------------------------------------------------------------------- /0x10-https_ssl/100-redirect_http_to_https: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /0x10-https_ssl/README.md: -------------------------------------------------------------------------------- 1 | 0x10. HTTPS SSL 2 | ![image](https://github.com/Sirtuns4real/alx-system_engineering-devops/assets/114403043/eea7ef7f-1655-426a-8715-015172fb8f5e) 3 | -------------------------------------------------------------------------------- /0x12-web_stack_debugging_2/0-iamsomeoneelse: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # This script runs whoami command under user passed as arg1 3 | su "$1" -s /bin/bash -c 'whoami' 4 | -------------------------------------------------------------------------------- /0x12-web_stack_debugging_2/1-run_nginx_as_nginx: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # This is a script that will fix container:: task 2 3 | pkill -f apache2 4 | chmod 644 /etc/nginx/nginx.conf 5 | sed -i "1i user nginx;" /etc/nginx/nginx.conf 6 | sed -i 's/80/8080/' /etc/nginx/sites-enabled/default 7 | sudo -u nginx service nginx restart 8 | -------------------------------------------------------------------------------- /0x12-web_stack_debugging_2/100-fix_in_7_lines_or_less: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # This script will also fix container:: task 2 3 | pkill -f apache2 4 | chmod 644 /etc/nginx/nginx.conf 5 | sed -Ei 's/\s*#?\s*user .*/user nginx;/' /etc/nginx/nginx.conf 6 | sed -Ei 's/(listen (\[::\]:)?80) /\180 /' /etc/nginx/sites-enabled/default 7 | sudo -u nginx service nginx restart 8 | -------------------------------------------------------------------------------- /0x12-web_stack_debugging_2/README.md: -------------------------------------------------------------------------------- 1 | 0x12. Web stack debugging #2 2 | -------------------------------------------------------------------------------- /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 | *nat 11 | :PREROUTING ACCEPT [0:0] 12 | -A PREROUTING -p tcp --dport 8080 -j REDIRECT --to-port 80 13 | COMMIT 14 | # Don't delete these required lines, otherwise there will be errors 15 | *filter 16 | :ufw-before-input - [0:0] 17 | :ufw-before-output - [0:0] 18 | :ufw-before-forward - [0:0] 19 | :ufw-not-local - [0:0] 20 | # End required lines 21 | 22 | 23 | # allow all on loopback 24 | -A ufw-before-input -i lo -j ACCEPT 25 | -A ufw-before-output -o lo -j ACCEPT 26 | 27 | # quickly process packets for which we already have a connection 28 | -A ufw-before-input -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT 29 | -A ufw-before-output -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT 30 | -A ufw-before-forward -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT 31 | 32 | # drop INVALID packets (logs these in loglevel medium and higher) 33 | -A ufw-before-input -m conntrack --ctstate INVALID -j ufw-logging-deny 34 | -A ufw-before-input -m conntrack --ctstate INVALID -j DROP 35 | 36 | # ok icmp codes for INPUT 37 | -A ufw-before-input -p icmp --icmp-type destination-unreachable -j ACCEPT 38 | -A ufw-before-input -p icmp --icmp-type time-exceeded -j ACCEPT 39 | -A ufw-before-input -p icmp --icmp-type parameter-problem -j ACCEPT 40 | -A ufw-before-input -p icmp --icmp-type echo-request -j ACCEPT 41 | 42 | # ok icmp code for FORWARD 43 | -A ufw-before-forward -p icmp --icmp-type destination-unreachable -j ACCEPT 44 | -A ufw-before-forward -p icmp --icmp-type time-exceeded -j ACCEPT 45 | -A ufw-before-forward -p icmp --icmp-type parameter-problem -j ACCEPT 46 | -A ufw-before-forward -p icmp --icmp-type echo-request -j ACCEPT 47 | 48 | # allow dhcp client to work 49 | -A ufw-before-input -p udp --sport 67 --dport 68 -j ACCEPT 50 | 51 | # 52 | # ufw-not-local 53 | # 54 | -A ufw-before-input -j ufw-not-local 55 | 56 | # if LOCAL, RETURN 57 | -A ufw-not-local -m addrtype --dst-type LOCAL -j RETURN 58 | 59 | # if MULTICAST, RETURN 60 | -A ufw-not-local -m addrtype --dst-type MULTICAST -j RETURN 61 | 62 | # if BROADCAST, RETURN 63 | -A ufw-not-local -m addrtype --dst-type BROADCAST -j RETURN 64 | 65 | # all other non-local packets are dropped 66 | -A ufw-not-local -m limit --limit 3/min --limit-burst 10 -j ufw-logging-deny 67 | -A ufw-not-local -j DROP 68 | 69 | # allow MULTICAST mDNS for service discovery (be sure the MULTICAST line above 70 | # is uncommented) 71 | -A ufw-before-input -p udp -d 224.0.0.251 --dport 5353 -j ACCEPT 72 | 73 | # allow MULTICAST UPnP for service discovery (be sure the MULTICAST line above 74 | # is uncommented) 75 | -A ufw-before-input -p udp -d 239.255.255.250 --dport 1900 -j ACCEPT 76 | 77 | # don't delete the 'COMMIT' line or these rules won't be processed 78 | COMMIT 79 | -------------------------------------------------------------------------------- /0x13-firewall/README.md: -------------------------------------------------------------------------------- 1 | 0x13-firewall 2 | -------------------------------------------------------------------------------- /0x14-mysql/4-mysql_configuration_primary: -------------------------------------------------------------------------------- 1 | [mysqld] 2 | pid-file = /var/run/mysqld/mysqld.pid 3 | socket = /var/run/mysqld/mysqld.sock 4 | datadir = /var/lib/mysql 5 | log-error = /var/log/mysql/error.log 6 | symbolic-links = 0 7 | server-id = 1 8 | log_bin = /var/log/mysql/mysql-bin.log 9 | binlog_do_db = tyrell_corp 10 | -------------------------------------------------------------------------------- /0x14-mysql/4-mysql_configuration_replica: -------------------------------------------------------------------------------- 1 | [mysqld] 2 | pid-file = /var/run/mysqld/mysqld.pid 3 | socket = /var/run/mysqld/mysqld.sock 4 | datadir = /var/lib/mysql 5 | log-error = /var/log/mysql/error.log 6 | bind-address = 0.0.0.0 7 | symbolic-links = 0 8 | server-id = 2 9 | log_bin = /var/log/mysql/mysql-bin.log 10 | relay_log = /var/log/mysql/mysql-relay-bin 11 | binlog_do_db = tyrell_corp 12 | -------------------------------------------------------------------------------- /0x14-mysql/5-mysql_backup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Generates a compressed archive of a MySQL dump. 3 | mysqldump -uroot -p"$1" --all-databases > backup.sql 4 | tar -cvzf "$(date +%d-%m-%Y)".tar.gz backup.sql 5 | -------------------------------------------------------------------------------- /0x14-mysql/README.md: -------------------------------------------------------------------------------- 1 | 0x14-mysql 2 | -------------------------------------------------------------------------------- /0x15-api/0-gather_data_from_an_API.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Script that 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 | """Script to export to-do list info 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 | """Script to export to-do list info 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 | """Script to export 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 | 0x15-api 2 | -------------------------------------------------------------------------------- /0x16-api_advanced/0-subs.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Function to query subscribers on a given Reddit subreddit.""" 3 | import requests 4 | 5 | 6 | def number_of_subscribers(subreddit): 7 | """Return the total number of subscribers on a given subreddit.""" 8 | url = "https://www.reddit.com/r/{}/about.json".format(subreddit) 9 | headers = { 10 | "User-Agent": "linux:0x16.api.advanced:v1.0.0 (by /u/bdov_)" 11 | } 12 | response = requests.get(url, headers=headers, allow_redirects=False) 13 | if response.status_code == 404: 14 | return 0 15 | results = response.json().get("data") 16 | return results.get("subscribers") 17 | -------------------------------------------------------------------------------- /0x16-api_advanced/1-top_ten.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Function to print hot posts on a given Reddit subreddit.""" 3 | import requests 4 | 5 | 6 | def top_ten(subreddit): 7 | """Print the titles of the 10 hottest posts on a given subreddit.""" 8 | url = "https://www.reddit.com/r/{}/hot/.json".format(subreddit) 9 | headers = { 10 | "User-Agent": "linux:0x16.api.advanced:v1.0.0 (by /u/bdov_)" 11 | } 12 | params = { 13 | "limit": 10 14 | } 15 | response = requests.get(url, headers=headers, params=params, 16 | allow_redirects=False) 17 | if response.status_code == 404: 18 | print("None") 19 | return 20 | results = response.json().get("data") 21 | [print(c.get("data").get("title")) for c in results.get("children")] 22 | -------------------------------------------------------------------------------- /0x16-api_advanced/100-count.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Function to count words in all hot posts of a given Reddit subreddit.""" 3 | import requests 4 | 5 | 6 | def count_words(subreddit, word_list, instances={}, after="", count=0): 7 | """Prints counts of given words found in hot posts of a given subreddit. 8 | 9 | Args: 10 | subreddit (str): The subreddit to search. 11 | word_list (list): The list of words to search for in post titles. 12 | instances (obj): Key/value pairs of words/counts. 13 | after (str): The parameter for the next page of the API results. 14 | count (int): The parameter of results matched thus far. 15 | """ 16 | url = "https://www.reddit.com/r/{}/hot/.json".format(subreddit) 17 | headers = { 18 | "User-Agent": "linux:0x16.api.advanced:v1.0.0 (by /u/bdov_)" 19 | } 20 | params = { 21 | "after": after, 22 | "count": count, 23 | "limit": 100 24 | } 25 | response = requests.get(url, headers=headers, params=params, 26 | allow_redirects=False) 27 | try: 28 | results = response.json() 29 | if response.status_code == 404: 30 | raise Exception 31 | except Exception: 32 | print("") 33 | return 34 | 35 | results = results.get("data") 36 | after = results.get("after") 37 | count += results.get("dist") 38 | for c in results.get("children"): 39 | title = c.get("data").get("title").lower().split() 40 | for word in word_list: 41 | if word.lower() in title: 42 | times = len([t for t in title if t == word.lower()]) 43 | if instances.get(word) is None: 44 | instances[word] = times 45 | else: 46 | instances[word] += times 47 | 48 | if after is None: 49 | if len(instances) == 0: 50 | print("") 51 | return 52 | instances = sorted(instances.items(), key=lambda kv: (-kv[1], kv[0])) 53 | [print("{}: {}".format(k, v)) for k, v in instances] 54 | else: 55 | count_words(subreddit, word_list, instances, after, count) 56 | -------------------------------------------------------------------------------- /0x16-api_advanced/2-recurse.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Function to query a list of all hot posts on a given Reddit subreddit.""" 3 | import requests 4 | 5 | 6 | def recurse(subreddit, hot_list=[], after="", count=0): 7 | """Returns a list of titles of all hot posts on a given subreddit.""" 8 | url = "https://www.reddit.com/r/{}/hot/.json".format(subreddit) 9 | headers = { 10 | "User-Agent": "linux:0x16.api.advanced:v1.0.0 (by /u/bdov_)" 11 | } 12 | params = { 13 | "after": after, 14 | "count": count, 15 | "limit": 100 16 | } 17 | response = requests.get(url, headers=headers, params=params, 18 | allow_redirects=False) 19 | if response.status_code == 404: 20 | return None 21 | 22 | results = response.json().get("data") 23 | after = results.get("after") 24 | count += results.get("dist") 25 | for c in results.get("children"): 26 | hot_list.append(c.get("data").get("title")) 27 | 28 | if after is not None: 29 | return recurse(subreddit, hot_list, after, count) 30 | return hot_list 31 | -------------------------------------------------------------------------------- /0x16-api_advanced/README.md: -------------------------------------------------------------------------------- 1 | 0x16-api_advanced 2 | -------------------------------------------------------------------------------- /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 | 0x17-web_stack_debugging_3 2 | -------------------------------------------------------------------------------- /0x18-webstack_monitoring/2-setup_datadog: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /0x18-webstack_monitoring/README.md: -------------------------------------------------------------------------------- 1 | 0x18-webstack_monitoring 2 | -------------------------------------------------------------------------------- /0x19-postmortem/README.md: -------------------------------------------------------------------------------- 1 | 0x19-postmortem 2 | 3 | Read my Postmortem at https://sirtuns.hashnode.dev/postmortem-web-stack-outage 4 | -------------------------------------------------------------------------------- /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 | 0x1A-application_server 2 | -------------------------------------------------------------------------------- /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 | 0x1B-web_stack_debugging_4 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Alx SYSTEM ENGINEERING DEVOPS PROJECTS 2 | -------------------------------------------------------------------------------- /command_line_for_the_win/0-first_9_tasks.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sirtuns4real/alx-system_engineering-devops/387c62676a507452a5e2373100471eb4c11f9669/command_line_for_the_win/0-first_9_tasks.jpg -------------------------------------------------------------------------------- /command_line_for_the_win/0-first_9_tasks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sirtuns4real/alx-system_engineering-devops/387c62676a507452a5e2373100471eb4c11f9669/command_line_for_the_win/0-first_9_tasks.png -------------------------------------------------------------------------------- /command_line_for_the_win/1-next_9_tasks.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sirtuns4real/alx-system_engineering-devops/387c62676a507452a5e2373100471eb4c11f9669/command_line_for_the_win/1-next_9_tasks.jpg -------------------------------------------------------------------------------- /command_line_for_the_win/1-next_9_tasks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sirtuns4real/alx-system_engineering-devops/387c62676a507452a5e2373100471eb4c11f9669/command_line_for_the_win/1-next_9_tasks.png -------------------------------------------------------------------------------- /command_line_for_the_win/2-next_9_tasks.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sirtuns4real/alx-system_engineering-devops/387c62676a507452a5e2373100471eb4c11f9669/command_line_for_the_win/2-next_9_tasks.jpg -------------------------------------------------------------------------------- /command_line_for_the_win/2-next_9_tasks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sirtuns4real/alx-system_engineering-devops/387c62676a507452a5e2373100471eb4c11f9669/command_line_for_the_win/2-next_9_tasks.png -------------------------------------------------------------------------------- /command_line_for_the_win/README.md: -------------------------------------------------------------------------------- 1 | command_line_for_the_win 2 | --------------------------------------------------------------------------------