├── 0x00-shell_basics ├── 0-current_working_directory ├── 1-listit ├── 10-back ├── 11-lists ├── 12-file_type ├── 13-symbolic_link ├── 14-copy_html ├── 15-lets_move ├── 16-clean_emacs ├── 17-tree ├── 18-commas ├── 2-bring_me_home ├── 3-listfiles ├── 4-listmorefiles ├── 5-listfilesdigitonly ├── 6-firstdirectory ├── 7-movethatfile ├── 8-firstdelete ├── 9-firstdirdeletion ├── README.md └── holberton.mgc ├── 0x01-shell_permissions ├── 0-iam_betty ├── 1-who_am_i ├── 10-mirror_permissions ├── 100-Star_Wars ├── 101-man_holberton ├── 11-directories_permissions ├── 12-directory_permissions ├── 13-change_group ├── 14-change_owner_and_group ├── 15-symbolic_link_permissions ├── 16-if_only ├── 2-groups ├── 3-new_owner ├── 4-empty ├── 5-execute ├── 6-multiple_permissions ├── 7-everybody ├── 8-James_Bond ├── 9-John_Doe └── README.md ├── 0x02-shell_redirections ├── 0-hello_world ├── 1-confused_smiley ├── 10-no_more_js ├── 100-empty_casks ├── 101-gifs ├── 102-acrostic ├── 103-the_biggest_fan ├── 11-directories ├── 12-newest_files ├── 13-unique ├── 14-findthatword ├── 15-countthatword ├── 16-whatsnext ├── 17-hidethisword ├── 18-letteronly ├── 19-AZ ├── 2-hellofile ├── 20-hiago ├── 21-reverse ├── 22-users_and_homes ├── 3-twofiles ├── 4-lastlines ├── 5-firstlines ├── 6-third_line ├── 7-file ├── 8-cwd_state ├── 9-duplicate_last_line └── README.md ├── 0x03-shell_variables_expansions ├── 0-alias ├── 1-hello_you ├── 10-love_exponent_breath ├── 100-rot13 ├── 101-odd ├── 102-water_and_stir ├── 11-binary_to_decimal ├── 12-combinations ├── 13-print_float ├── 14-decimal_to_hexadecimal ├── 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_holberton_school ├── 10-fizzbuzz ├── 100-read_and_cut ├── 101-tell_the_story_of_passwd ├── 102-lets_parse_apache_logs ├── 103-dig_the-data ├── 2-while_holberton_school ├── 3-until_holberton_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-kill_me_now ├── 6-kill_me_now_made_easy ├── 7-highlander ├── 8-beheaded_process ├── README.md └── manage_my_process ├── 0x06-regular_expressions ├── 0-simply_match_holberton.rb ├── 1-repetition_token_0.rb ├── 100-textme.rb ├── 101-passed_linkedin_regex_challenge.jpg ├── 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-localhost ├── 1-wildcard ├── 2-change_your_home_IP ├── 3-show_attached_IPs ├── 4-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-ssh ├── 0-use_a_private_key ├── 1-create_ssh_key_pair ├── 2-ssh_config └── README.md ├── 0x0B-web_server ├── 0-transfer_file ├── 1-install_nginx_web_server ├── 2-setup_a_domain_name ├── 3-redirection ├── 4-not_found_page_404 ├── README.md └── fabfile.py ├── 0x0C-web_stack_debugging_0 ├── 0-give_me_a_page └── README.md ├── 0x0D-configuration_management ├── 0-create_a_file.pp ├── 1-install_a_package.pp ├── 2-execute_a_command.pp └── 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 └── README.md ├── 0x10-https_ssl ├── 0-https_abc ├── 1-world_wide_web ├── 100-redirect_http_to_https ├── 2-haproxy_ssl_termination └── README.md ├── 0x11-what_happens_when_your_type_holbertonschool_com_in_your_browser_and_press_enter ├── 0-blog_post ├── 1-what_happen_when_diagram └── README.md ├── 0x12-web_stack_debugging_2 ├── 0-iamsomeonelese ├── 1-run_nginx_as_nginx ├── 100-fix_in_7_lines_or_less └── README.md ├── 0x13-firewall ├── 0-firewall_ABC ├── 1-block_all_incoming_traffic_but ├── 100-port_forwarding └── README.md ├── 0x14-mysql ├── 4-mysql_configuration_primary ├── 4-mysql_configuration_replica ├── 5-mysql_backup └── README.md ├── 0x15-api ├── 0-gather_data_from_an_API.py ├── 1-export_to_CSV.py ├── 2-export_to_JSON.py ├── 3-dictionary_of_list_of_dictionaries.py └── README.md ├── 0x16-api_advanced ├── 0-subs.py ├── 1-top_ten.py ├── 100-count.py ├── 2-recurse.py ├── README.md └── tests │ ├── 0-main.py │ ├── 1-main.py │ ├── 100-main.py │ └── 2-main.py ├── 0x17-web_stack_debugging_3 ├── 0-strace_is_your_friend.pp └── README.md ├── 0x18-webstack_monitoring ├── 0-monitor_your_nginx_traffic └── README.md ├── 0x19-postmortem └── README.md ├── 0x1A-application_server ├── 2-app_server-nginx_config ├── 3-app_server-nginx_config ├── 4-app_server-nginx_config ├── 4-reload_gunicorn_no_downtime ├── 5-app_server-nginx_config ├── README.md └── gunicorn.conf ├── 0x1B-web_stack_debugging_4 ├── 0-the_sky_is_the_limit_not.pp ├── 1-user_limit.pp └── README.md ├── README.md └── command_line_for_the_win ├── 0-first_9_tasks.png ├── 1-next-9-tasks.png ├── 2-last-9-tasks.png └── README.md /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/11-lists: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ls -la . .. /boot 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/12-file_type: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | file /tmp/iamafile 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/13-symbolic_link: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ln -s /bin/ls __ls__ 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/14-copy_html: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cp -u *.html .. 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/15-lets_move: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | mv [[:upper:]]* /tmp/u 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/16-clean_emacs: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | rm *~ 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/17-tree: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | mkdir -p welcome/to/holberton 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/18-commas: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ls -mpa 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/2-bring_me_home: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/3-listfiles: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ls -l 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/4-listmorefiles: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ls -la 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/5-listfilesdigitonly: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ls -an 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/6-firstdirectory: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | mkdir /tmp/holberton 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/7-movethatfile: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | mv /tmp/betty /tmp/holberton 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/8-firstdelete: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | rm /tmp/holberton/betty 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/9-firstdirdeletion: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | rmdir /tmp/holberton 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/README.md: -------------------------------------------------------------------------------- 1 | # Shell, basics 2 | 3 | In this project, I underwent an introductory crash course in the Shell. I 4 | learned how to navigate directories using `cd`, `pwd`, `ls`, how to look 5 | around using `ls`, `less`, and `file`, and how to manipulate files with `cp`, 6 | `mv`, `rm`, and `mkdir`. Further, I practiced working with the `type`, `which`, 7 | `help`, and `man` commands, implementing wildcards, reading man pages, 8 | creating links, and using keyboard shortcuts in Bash. 9 | 10 | ## Tasks :page_with_curl: 11 | 12 | * **0. Where am I?** 13 | * [0-current_working_directory](./0-current_working_directory): Bash script that 14 | prints the absolute pathname of the current working directory. 15 | 16 | * **1. What’s in there?** 17 | * [1-listit](./1-listit): Bash script that displays the contents list of current directory. 18 | 19 | * **2. There is no place like home** 20 | * [2-bring_me_home](./2-bring_me_home): Bash script that changes the working directory to the 21 | user's home directory. 22 | 23 | * **3. The long format** 24 | * [3-listfiles](./3-listfiles): Bash script that displays current directory contents in 25 | long format. 26 | 27 | * **4. Hidden files** 28 | * [4-listmorefiles](./4-listmorefiles): Bash script that displays current directory contents, 29 | including hidden files, using long format. 30 | 31 | * **5. I love numbers** 32 | * [5-listfilesdigitonly](./5-listfilesdigitonly): Bash script that displays current directory 33 | contents, including hidden files, as follows: 34 | * Long format. 35 | * User and group ID's displayed numerically. 36 | 37 | * **6. Welcome holberton** 38 | * [6-firstdirectory](./6-firstdirectory): Bash script that creates a directory named `holberton` 39 | in the `/tmp/` directory. 40 | 41 | * **7. Betty in Holberton** 42 | * [7-movethatfile](./7-movethatfile): Bash script that moves the file `betty` from `/tmp/` to 43 | `/tmp/holberton`. 44 | 45 | * **8. Bye bye Betty** 46 | * [8-firstdelete](./8-firstdelete): Bash script that deletes the file `betty` in `/tmp/holberton`. 47 | 48 | * **9. Bye bye Holberton** 49 | * [9-firstdirdeletion](./9-firstdirdeletion): Bash script that deletes the directory `holberton` 50 | in the `/tmp` directory. 51 | 52 | * **10. Back to the future** 53 | * [10-back](./10-back): Bash script that changes the working directory to the previous one. 54 | 55 | * **11. Lists** 56 | * [11-lists](./11-lists): Bash script that lists all files, including hidden files, in the 57 | current directory, parent of the working directory, and `/boot` directory, using long format. 58 | 59 | * **12. File type** 60 | * [12-file_type](./12-file_type): Bash script that prints the type of the file named 61 | `iamafile` located in the `/tmp` directory. 62 | 63 | * **13. We are symbols, and inhabit symbols** 64 | * [13-symbolic_link](./13-symbolic_link): Bash script that creates a symbolic link to `/bin/ls`, 65 | named `__ls__`. 66 | 67 | * **14. Copy HTML files** 68 | * [14-copy_html](./14-copy_html): Bash script that copies all HTML files from the current 69 | working directory to the parent of the working directory, but only those that 70 | did not exist in the parent directory or were newer than the versions in the parent working directory. 71 | 72 | * **15. Let’s move** 73 | * [15-lets_move](./15-lets_move): Bash script that moves all files beginning with an uppercase 74 | letter to the directory `/tmp/u`. 75 | 76 | * **16. Clean Emacs** 77 | * [16-clean_emacs](./16-clean_emacs): Bash script that deletes all files in the current working 78 | directory that end with the character `~`. 79 | 80 | * **17. Tree** 81 | * [17-tree](./17-tree): Bash script that creates the directories `welcome/`, 82 | `welcome/to/` and `welcome/to/holberton` in the current directory. 83 | 84 | * **18. Life is a series of commas, not periods** 85 | * [18-commas](./18-commas): Bash script that lists all files and directories of the current 86 | directory, including hidden ones, as follows: 87 | * Separated by commas (`,`). 88 | * Directory names end with a slash (`/`). 89 | * Alpha-ordered, except for the directories `.` and `..` which are listed at the beginning. 90 | * Only digits and letters are used to sort - digits come first. 91 | 92 | * **19. File type: Holberton** 93 | * [holberton.mgc](./holberton.mgc): A magic file that can be used with the command `file` to 94 | detect `Holberton` data files. 95 | -------------------------------------------------------------------------------- /0x00-shell_basics/holberton.mgc: -------------------------------------------------------------------------------- 1 | 0 string HOLBERTON Holberton data 2 | !:mime Holberton 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 | whoami 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/10-mirror_permissions: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chmod --reference=olleh hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/100-Star_Wars: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | telnet towel.blinkenlights.nl 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/101-man_holberton: -------------------------------------------------------------------------------- 1 | .TH man 2 "04 May 2015" "0.32" "holberton man page" 2 | .SH NAME 3 | .B holberton 4 | - become a full-stack software engineer. 5 | .SH SYNOPSIS 6 | holberton [STUDENTNAME] 7 | .SH DESCRIPTION 8 | Holberton School is a project-based alternative to college for the next generation of software engineers. 9 | .SH OPTIONS 10 | .B holberton 11 | does not take any options. However, you can supply studentname. 12 | .SH SEE ALSO 13 | .I peerlearning(2), projectbased(2), fullstack(2), Betty(1) 14 | .SH BUGS 15 | No known bugs. 16 | .SH AUTHOR 17 | Julien Barbier, Sylvain Kalache, Sophie Barbier, Guillaume Salva, Kris Bredemeier, Julien Cyr, Alex Gautier and all the Holberton mentors -------------------------------------------------------------------------------- /0x01-shell_permissions/11-directories_permissions: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chmod -R a+X . 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/12-directory_permissions: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | mkdir -m 751 dir_holberton 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/13-change_group: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chgrp holberton hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/14-change_owner_and_group: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chown -R betty:holberton . 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/15-symbolic_link_permissions: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chown -h betty:holberton _hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/16-if_only: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chown --from=guillaume betty 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 u+x,g+x,o+r hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/7-everybody: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chmod a+x hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/8-James_Bond: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chmod 007 hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/9-John_Doe: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chmod 753 hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/README.md: -------------------------------------------------------------------------------- 1 | # Shell, permissions 2 | 3 | In this project, I learned about using the `chmod`, `sudo`, `su`, `chown`, and 4 | `chgrp` commands to represent and change Linux file permissions and change users 5 | in the Shell. 6 | 7 | ## Tasks :page_with_curl: 8 | 9 | * **0. My name is Betty** 10 | * [0-iam_betty](./0-iam_betty): Bash script that changes the user ID to `betty`. 11 | 12 | * **1. Who am I** 13 | * [1-who_am_i](./1-who_am_i): Bash script that prints the effective userid of the 14 | current user. 15 | 16 | * **2. Groups** 17 | * [2-groups](./2-groups): Bash script that prints all the groups the 18 | current user is a part of. 19 | 20 | * **3. New owner** 21 | * [3-new_owner](./3-new_owner): Bash script that changes the owner of the 22 | file `hello` to the user `betty`. 23 | 24 | * **4. Empty!** 25 | * [4-empty](./4-empty): Bash script that creates an empty file called `hello`. 26 | 27 | * **5. Execute** 28 | * [5-execute](./5-execute): Bash script that adds execute permissions to the owner 29 | of the file `hello`. 30 | 31 | * **6. Multiple permissions** 32 | * [6-multiple_permissions](./6-multiple_permissions): Bash script that adds 33 | execute permission to the owner and the group owner, and read permission to 34 | other users, for the file `hello`. 35 | 36 | * **7. Everybody!** 37 | * [7-everybody](./7-everybody): Bash script that adds execution permission to the owner, 38 | the group owner and the other users, for the file `hello`. 39 | 40 | * **8. James Bond** 41 | * [8-James_Bond](./8-James_Bond): Bash script that sets the permission for the file 42 | `hello` as follows: 43 | * Owner - no permission at all 44 | * Group - no permission at all 45 | * Other users - all permissoins 46 | 47 | * **9. John Doe** 48 | * [9-John_Doe](./9-John_Doe): Bash script that sets the mode of the file 49 | `hello` to -rwxr-x-wx. 50 | 51 | * **10. Look in the mirror** 52 | * [10-mirror_permissions](./10-mirror_permissions): Bash script that sets the mode 53 | of the file `hello` the same as the file `olleh`. 54 | 55 | * **11. Directories** 56 | * [11-directories_permissions](./11-directories_permissions): Bash script that adds execute 57 | permission to all subdirectories of the current directory for the owner, the group owner 58 | and all other users. Regular files are not changed. 59 | 60 | * **12. More directories** 61 | * [12-directory_permissions](./12-directory_permissions): Bash script that creates a 62 | directory `dir_holberton` with permissions 751 in the working directory. 63 | 64 | * **13. Change group** 65 | * [13-change_group](./13-change_group): Bash script that changes the group owner to 66 | `holberton` for the file `hello`. 67 | 68 | * **14. Owner and group** 69 | * [14-change_owner_and_group](./14-change_owner_and_group): Bash script that changes the 70 | owner to `betty` and the group owner to `holberton` for all the files and directories 71 | in the working directory. 72 | 73 | * **15. Symbolic links** 74 | * [15-symbolic_link_permissions](./15-symbolic_link_permissions): Bash script that changes 75 | the owner and the group owner of the file `hello` to `betty` and `holberton`, respectively. 76 | 77 | * **16. If only** 78 | * [16-if_only](./16-if_only): Bash script that changes the owner of the file `hello` 79 | to `betty` only if it is owned by the user `guillaume`. 80 | 81 | * **17. Star Wars** 82 | * [100-Star_Wars](./100-Star_Wars): Bash script that plays Star Wars Episode IV 83 | in the terminal. 84 | 85 | * **18. RTFM** 86 | * [101-man_holberton](./101-man_holberton): A man page. 87 | -------------------------------------------------------------------------------- /0x02-shell_redirections/0-hello_world: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "Hello, World" 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/1-confused_smiley: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo '"(Ôo)'\' 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/10-no_more_js: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | find . -name "*.js" -type f -delete 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/100-empty_casks: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | find . -empty -printf %f'\n' 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/101-gifs: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | find . -type f -name \*.gif -printf "%f\n" | LC_ALL=C sort -f | rev | cut -b 5- | rev 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/102-acrostic: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo $(cut -b 1 | tr -d '\n') 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/103-the_biggest_fan: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | tail -n+2 | cut -f1 | sort | uniq -c | sort -rn | cut -c 9- | head -11 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/11-directories: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | find . -mindepth 1 -type d | wc -l 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/12-newest_files: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ls -1t | head 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/13-unique: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | sort | uniq -u 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/14-findthatword: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | grep root /etc/passwd 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/15-countthatword: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | grep bin /etc/passwd | wc -l 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/16-whatsnext: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | grep -A 3 root /etc/passwd 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/17-hidethisword: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | grep -v bin /etc/passwd 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/18-letteronly: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | grep ^[[:alpha:]] /etc/ssh/sshd_config 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/19-AZ: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | tr A Z | tr c e 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/2-hellofile: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cat /etc/passwd 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/20-hiago: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | tr -d c | tr -d C 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/21-reverse: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | rev 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/22-users_and_homes: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | sort /etc/passwd | cut -d : -f1,6 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/3-twofiles: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cat /etc/passwd /etc/hosts 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/4-lastlines: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | tail /etc/passwd 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/5-firstlines: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | head /etc/passwd 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/6-third_line: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | head -3 iacta | tail -1 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/7-file: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "Holberton School" > '\*\\'\''"Holberton School"\'\''\\*$\?\*\*\*\*\*:)' 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/8-cwd_state: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ls -la > ls_cwd_content 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/9-duplicate_last_line: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | tail -1 iacta >> iacta 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/README.md: -------------------------------------------------------------------------------- 1 | # Shell, I/O Redirections and filters 2 | 3 | In this project, I learned about using the `head`, `tail`, `find`, `wc`, `sort`, 4 | `uniq`, `grep`, and `tr` commands to redirect standard input and output and 5 | combine commands in the Shell. Further, I learned about how special characters 6 | work and how to filter text from files. 7 | 8 | ## Tasks :page_with_curl: 9 | 10 | * **0. Hello World** 11 | * [0-hello_world](./0-hello_world): Bash script that prints "Hello, World" 12 | followed by a new line to the standard output. 13 | 14 | * **1. Confused smiley** 15 | * [1-confused_smiley](./1-confused_smiley): Bash script that displays a confused smiley 16 | `"(Ôo)'`. 17 | 18 | * **2. Let's display a file** 19 | * [2-hellofile](./2-hellofile): Bash script that displays the content of the 20 | `/etc/passwd` file. 21 | 22 | * **3. What about 2?** 23 | * [3-twofiles](./3-twofiles): Bash script that displays the content of 24 | `etc/passwd` and `/etc/hosts`. 25 | 26 | * **4. Last lines of a file** 27 | * [4-lastlines](./4-lastlines): Bash script that displays the last 10 lines of `/etc/passwd`. 28 | 29 | * **5. I'd prefer the first ones actually** 30 | * [5-firstlines](./5-firstlines): Bash script that displays the first 10 lines 31 | of `/etc/passwd`. 32 | 33 | * **6. Line #2** 34 | * [6-third_line](./6-third_line): Bash script that displays the third line 35 | of the file `iacta`. 36 | 37 | * **7. It is a good file that cuts iron without making a noise** 38 | * [7-file](./7-file): Bash script that creates a file named exactly 39 | `\*\\'"Holberton School"\'\\*$\?\*\*\*\*\*:)` containing the text 40 | `Holberton School` ending by a new line. 41 | 42 | * **8. Save current state of directory** 43 | * [8-cwd_state](./8-cwd_state): Bash script that writes into the file `ls_cwd_content` the 44 | result of the command `ls -la`. 45 | 46 | * **9. Duplicate last line** 47 | * [9-duplicate_last_line](./9-duplicate_last_line): Bash script that duplicates the last 48 | line of the file `iacta`. 49 | 50 | * **10. No more javascript** 51 | * [10-no_more_js](./10-no_more_js): Bash script that deletes all the regular files (not 52 | directories) with a `.js` extension that are present in the current directory 53 | and all its subfolders. 54 | 55 | * **11. Don't just count your directories, make your directories count** 56 | * [11-directories](./11-directories): Bash script that counts the number of directories and 57 | sub-directories in the current directory, not including the current and parent 58 | directories but counting hidden ones. 59 | 60 | * **12. What’s new** 61 | * [12-newest_file](./12-newest_files): Bash script that displays the 10 newest files in the 62 | current directory, one file per line, sorted from newest to oldest. 63 | 64 | * **13. Being unique is better than being perfect** 65 | * [13-unique](./13-unique): Bash script that takes a list of words as input and only 66 | prints words that appear exactly once, one word per line, sorted. 67 | 68 | * **14. It must be in that file** 69 | * [14-findthatword](./14-findthatword): Bash script that displays lines containing 70 | the pattern "root" from the file `/etc/passwd`. 71 | 72 | * **15. Count that word** 73 | * [15-countthatword](./15-countthatword): Bash script that displays the number of lines 74 | containing the pattern "bin" in the file `/etc/passwd`. 75 | 76 | * **16. What's next?** 77 | * [16-whatsnext](./16-whatsnext): Bash script that displays lines containing the pattern 78 | "root" and 3 lines after them in the file `/etc/passwd`. 79 | 80 | * **17. I hate bins** 81 | * [17-hidethisword](./17-hidethisword): Bash script that displays all lines in the file 82 | `/etc/passwd` that do not contain the pattern "bin". 83 | 84 | * **18. Letters only please** 85 | * [18-letteronly](./18-letteronly): Bash script that displays all lines of the file 86 | `/etc/ssh/sshd_config` starting with a letter, including capital letters. 87 | 88 | * **19. A to Z** 89 | * [19-AZ](./19-AZ): Bash script that replaces all characters `A` and `c` from input 90 | to `Z` and `e` respectively. 91 | 92 | * **20. Without C, you would live in hiago** 93 | * [20-hiago](./20-hiago): Bash script that removes all letters `c` and `C` from input. 94 | 95 | * **21. esreveR** 96 | * [21-reverse](./21-reverse): Bash script that reverses its input. 97 | 98 | * **22. DJ Cut Killer** 99 | * [22-users_and_homes](./22-users_and_homes): Bash script that displays all users and 100 | their home directories, sorted by users, based on the `/etc/passwd` file. 101 | 102 | * **23. Empty casks make the most noise** 103 | * [100-empty_casks](./100-empty_casks): Bash script that finds all empty files 104 | and directories in the current directory and all sub-directories as follows: 105 | * Only the names of the files and directories are displayed. 106 | * Hidden files included. 107 | * One file name per line. 108 | 109 | * **24. A gif is worth ten thousand words** 110 | * [101-gifs](./101-gifs): Bash script that lists all the files with a `.gif` extension 111 | in the current directory and all its sub-directories as follows: 112 | * Hidden files included. 113 | * Only regular files (not directories) listed. 114 | * File names displayed without extensions. 115 | * Files sorted by byte values, but case insensitive. 116 | * One file name per line. 117 | 118 | * **25. Acrostic** 119 | * [102-acrostic](./102-acrostic): Bash script that decodes acrostics that use the first 120 | letter of each line. 121 | 122 | * **26. The biggest fan** 123 | * [103-the_biggest_fan](./103-the_biggest_fan): Bash script that parses web 124 | server logs in TSV format as input and displays the 11 hosts or IP addresses 125 | which did the most requests. 126 | * Ordered by number of requests, with most active hosts or IP's at the top. 127 | -------------------------------------------------------------------------------- /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-rot13: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | tr '[A-Za-z]' '[N-ZA-Mn-za-m]' 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/101-odd: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cat -n | cut -b 6- | grep ^[13579] | cut -f2 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/102-water_and_stir: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | printf "%o\n" $(( (5#$(echo $WATER | tr '[water]' '[01234]')) + (5#$(echo $STIR | tr '[stir.]' '[01234]')) )) | tr '[01234567]' '[behlnort]' 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 | printf %s'\n' {a..z}{a..z} | 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/14-decimal_to_hexadecimal: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | printf %x'\n' $DECIMAL 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 -s ':' '\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 | BETTY="Holberton" 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/7-create_global_variable: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | export HOLBERTON="Betty" 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/8-true_knowledge: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo $((TRUEKNOWLEDGE+128)) 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/9-divide_and_rule: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo $((POWER/DIVIDE)) 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/README.md: -------------------------------------------------------------------------------- 1 | # Shell, init files, variables and expansions 2 | 3 | In this project, I learned about initialization files, local, global, and 4 | reserved variables, and special parameters in the Shell. Further, I practiced 5 | using expansions, performing arithmetic operations, and utilizing aliases. 6 | 7 | ## Tasks :page_with_curl: 8 | 9 | * **0. ** 10 | * [0-alias](./0-alias): Bash script that creates an alias named `ls` with value `rm *`. 11 | 12 | * **1. Hello you** 13 | * [1-hello_you](./1-hello_you): Bash script that prints `hello user`, where user is the 14 | current Linux user. 15 | 16 | * **2. The path to success is to take massive, determined action** 17 | * [2-path](./2-path): Bash script that adds `/action` to the `PATH`. 18 | 19 | * **3. If the path be beautiful, let us not ask where it leads** 20 | * [3-paths](./3-paths): Bash script that counts the number of directories in the `PATH`. 21 | 22 | * **4. Global variables** 23 | * [4-global_variables](./4-global_variables): Bash script that lists environment variables. 24 | 25 | * **5. Local variable** 26 | * [5-local_variables](./5-local_variables): Bash script that lists all local variables, 27 | environment variables and functions. 28 | 29 | * **6. Local variable** 30 | * [6-create_local_variable](./6-create_local_variable): Bash script that creates 31 | a new local variable named `BETTY` with value `Holberton`. 32 | 33 | * **7. Global variable** 34 | * [7-create_global_variable](./7-create_global_variable): Bash script that 35 | creates a new global variable named `HOLBERTON` with value `Betty`. 36 | 37 | * **8. Every addition to true knowledge is an addition to human power** 38 | * [8-true_knowledge](./8-true_knowledge): Bash script that prints the result of the 39 | addition of 128 with the value stored in the environment variable 40 | `TRUEKNOWLEDGE`, followed by a new line. 41 | 42 | * **9. Divide and rule** 43 | * [9-divide_and_rule](./9-divide_and_rule): Bash script that prints the result 44 | of `POWER` divided by `DIVIDE`. `POWER` and `DIVIDE` are environment variables. 45 | 46 | * **10. Love is anterior to life, posterior to death, initial of creation, and the exponent of breath** 47 | * [10-love_exponent_breath](./10-love_exponent_breath): Bash script that displays the 48 | result of `BREATH` to the power of `LOVE`. `BREATH` and `LOVE` are environment variables. 49 | 50 | * **11. There are 10 types of people in the world -- Those who understand binary, and those who don't** 51 | * [11-binary_to_decimal](./11-binary_to_decimal): Bash script that converts a number 52 | in base 2 stored in the environment variable `BINARY` to base 10. 53 | 54 | * **12. Combination** 55 | * [12-combinations](./12-combinations): Bash script that prints all possible combinations 56 | of two letters, except `oo`, as follows: 57 | * Letters are lower cases, from `a` to `z`. 58 | * One combination per line. 59 | * Alpha-ordered. 60 | 61 | * **13. Floats** 62 | * [13-print_float](./13-print_float): Bash script that prints a number stored in the 63 | environment variable `NUM` with two decimal places. 64 | 65 | * **14. Decimal to Hexadecimal** 66 | * [14-decimal_to_hexadecimal](./14-decimal_to_hexadecimal): Bash script 67 | that converts a number in base 10 stored in the environment variable `DECIMAL` to base 16. 68 | 69 | * **15. Everyone is a proponent of strong encryption** 70 | * [100-rot13](./100-rot13): Bash script that encodes and decodes text using the rot13 71 | encryption. 72 | 73 | * **16. The eggs of the brood need to be an odd number** 74 | * [101-odd](./101-odd): Bash script that prints every other line from the input, 75 | starting with the first line. 76 | 77 | * **17. I'm an instant star. Just add water and stir.** 78 | * [102-water_and_stir](./102-water_and_stir): Bash script that adds the two numbers 79 | stored in the environment variables `WATER` and `STIR` and prints the result. 80 | * `WATER` is in base `water`, `STIR` is in base `stir`, and the result is 81 | in base `behlnort`. 82 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/0-RSA_public_key.pub: -------------------------------------------------------------------------------- 1 | ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDKzXgnyw3xN5/25TWaoI+omBTcklzlkJFC3NaZQW3zYSquuB+yyN7GrmXygsP6Uzbm/hJIe+qUmQg0eBf8wQNITbmklWGWARE9bhtiTjiwHo3izwyeBC6ql5PBMBatSVWY0ZqHuqY4hZcZAIfjAEm0ul8cFw44VAEdQYLU2CVSggUjnILDv4aGVsNY1Y/HY9RgvcMCamz0uvuFjY0ODJe3Yg/ENNe2s4y3E1YrxzwhfmSk1aBll8Ac1eE6JUPZikB3NZZpE3vTZiluM3v1agifpeD2NICvnEOoJFUAAsx2kcosX+Z5Z3JNn775QIftOYL2mlkDcN2D90CykqmX+L2N vagrant@vagrant-ubuntu-trusty-64 2 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/1-for_holberton_school: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays "Holberton School" 10 times using a for loop. 3 | 4 | for (( i=0; i<10; i++ )) 5 | do 6 | echo "Holberton 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 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 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_holberton_school: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays "Holberton School" 10 times using a while loop. 3 | 4 | count=0 5 | 6 | while [ $count -lt 10 ] 7 | do 8 | echo "Holberton School" 9 | (( count++ )) 10 | done 11 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/3-until_holberton_school: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays "Holberton School" 10 times using an until loop. 3 | 4 | count=0 5 | 6 | until [ $count -eq 10 ] 7 | do 8 | echo "Holberton School" 9 | (( count++ )) 10 | done 11 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/4-if_9_say_hi: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays "Holberton School" 10 times using a while loop. 3 | # On the 9th iteration, displays "Hi" before "Holberton 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 "Holberton 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 | # "Holberton 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 "Holberton School" 19 | fi 20 | (( count++ )) 21 | done 22 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/6-superstitious_numbers: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays numbers from 1 to 20 in addition to: 3 | # "bad luck from China" for the 4th iteration 4 | # "bad luck from Japan" for the 9th iteration 5 | # "bad luck from Italy" for the 17th loop iteration 6 | 7 | count=1 8 | 9 | while [ $count -le 20 ] 10 | do 11 | echo "$count" 12 | case $count in 13 | "4") echo "bad luck from China";; 14 | "9") echo "bad luck from Japan";; 15 | "17") echo "bad luck from Italy";; 16 | esac 17 | (( count++ )) 18 | done 19 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/7-clock: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays the time for 12 horus and 59 minutes. 3 | # Displays hours from 0 to 12 4 | # Displays minutes from 1 to 59 5 | 6 | hour=0 7 | 8 | while [ $hour -le 12 ] 9 | do 10 | echo "Hour: $hour" 11 | minute=1 12 | while [ $minute -le 59 ] 13 | do 14 | echo "$minute" 15 | (( minute++ )) 16 | done 17 | (( hour++ )) 18 | done 19 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/8-for_ls: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays the contents of the current directory in list format. 3 | # Only displays the part of the name after the first dash. 4 | 5 | list=$(ls) 6 | for i in $list; do 7 | echo "$i" | cut -d '-' -f2 8 | done 9 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/9-to_file_or_not_to_file: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays information about the file `holbertonschool`. 3 | 4 | if [ -e "holbertonschool" ] 5 | then 6 | echo "holbertonschool file exists" 7 | if [ -s "holbertonschool" ] 8 | then 9 | echo "holbertonschool file is not empty" 10 | else 11 | echo "holbertonschool file is empty" 12 | fi 13 | 14 | if [ -f "holbertonschool" ] 15 | then 16 | echo "holbertonschool is a regular file" 17 | fi 18 | else 19 | echo "holbertonschool file does not exist" 20 | fi 21 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/README.md: -------------------------------------------------------------------------------- 1 | # Loops, conditions and parsing 2 | 3 | In this project, I began working loops and conditionals statemetns in Bash. 4 | 5 | ## Helper File :raised_hands: 6 | 7 | * [apache-access.log](./apache-access.log): An Apache access log file parsed in 8 | tasks `102` and `103`. 9 | 10 | ## Tasks :page_with_curl: 11 | 12 | * **0. Create a SSH RSA key pair** 13 | * [0-RSA_public_key.pub](./0-RSA_public_key.pub): A public SSH key uploaded for the 14 | purposes of Holberton School. 15 | 16 | * **1. For Holberton School loop** 17 | * [1-for_holberton_school](./1-for_holberton_school): Bash script that displays 18 | `Holberton School` 10 times using a `for` loop. 19 | 20 | * **2. While Holberton School loop** 21 | * [2-while_holberton_school](./2-while_holberton_school): Bash script that 22 | displays `Holberton School` 10 times using a `while` loop. 23 | 24 | * **3. Until Holberton School loop** 25 | * [3-until_holberton_school](./3-until_holberton_school): Bash script that displays 26 | `Holberton School` 10 times using an `until` loop. 27 | 28 | * **4. If 9, say Hi!** 29 | * [4-if_9_say_hi](./4-if_9_say_hi): Bash script that displays `Holberton School` 30 | 10 times using a `while` loop. 31 | * For the 9th iteration, displays `Holberton School` and then `Hi` on a 32 | new line. 33 | * Uses an `if` statement. 34 | 35 | * **5. 4 bad luck, 8 is your chance** 36 | * [5-4_bad_luck_8_is_your_chance](./5-4_bad_luck_8_is_your_chance): Bash script that loops 37 | from 1 to 10 using a `while` loop and: 38 | * Displays `bad luck` on the 4th iteration. 39 | * Displays `good luck` on the 8th iteration. 40 | * Displays `Holberton School` for all other iterations. 41 | * Uses the `if`, `elif`, and `else` statements. 42 | 43 | * **6. Superstitious numbers** 44 | * [6-superstitious_numbers](./6-superstitious_numbers): Bash script that displays 45 | numbers from `1` to `20` using a `while` loop and: 46 | * Displays `4` and then `bad luck from China` for the 4th iteration. 47 | * Displays `9` and then `bad luck from Japan` for the 9th iteration. 48 | * Displays `17` and then `bad luck from Italy` for the 17th iteration. 49 | * Uses a `case` statement. 50 | 51 | * **7. Clock** 52 | * [7-clock](./7-clock): Bash script that displays the time for 12 hours and 59 minutes. 53 | * Displays hours from `0` to `12`. 54 | * Displays minutes from `0` to `59`. 55 | 56 | * **8. For ls** 57 | * [8-for_ls](./8-for_ls): Bash script that displays the contents of the current directory 58 | in list format. 59 | * Only the part of the name after the first dash is displayed. 60 | 61 | * **9. To file, or not to file** 62 | * [9-to_file_or_not_to_file](./9-to_file_or_not_to_file): Bash script that gives information 63 | about the `holbertonschool` file. 64 | * If the file exists, displays: `holbertonschool file exists`. 65 | * If the file does not exist, displays: `holbertonschool file does not exist`. 66 | * If the file exists and is empty, displays: `holbertonschool file is empty`. 67 | * If the file exists and is not empty, displays: `holbertonschoolfile is not 68 | empty`. 69 | * If the file exists and is a regular file, displays: `holbertonschool file 70 | is a regular file`. 71 | * Otherwise, displays nothing. 72 | 73 | * **10. FizzBuzz** 74 | * [10-fizzbuzz](./10-fizzbuzz): Bash script that displays numbers from 75 | `1` to `100` in list format. 76 | * Displays `FizzBuzz` when the number is a multiple of 3 and 5. 77 | * Displays `Fizz` when the number is a multiple of 3. 78 | * Displays `Buzz` when the number is a multiple of 5. 79 | * Otherwise, displays the number. 80 | 81 | * **11. Read and cut** 82 | * [100-read_and_cut](./100-read_and_cut): Bash script that displays the contents of the 83 | `/etc/passwd` file. 84 | * Displays only the username, user id, and user home directory path for each line. 85 | 86 | * **12. Tell the story of passwd** 87 | * [101-tell_the_story_of_passwd](./101-tell_the_story_of_passwd): Bash script that 88 | tells stories based on the contents of the `/etc/passwd` file. 89 | * Displays content from the file in the format: `The user USERNAME is part of 90 | the GROUP_ID gang, lives in HOME_DIRECTORY and rides COMMAND/SHELL. USER ID's 91 | place is protected by the passcode PASSWORD, more info about the user here: USER ID INFO`. 92 | 93 | * **13. Let's parse Apache logs** 94 | * [102-lets_parse_apache_logs](./102-lets_parse_apache_logs): Bash script that displays 95 | the visitor IP along with the HTTP status code for logs read from an Apache log access file. 96 | * Displays content in the format `IP HTTP_CODE`. 97 | * Uses `awk`. 98 | 99 | * **14. Dig the data** 100 | * [103-dig_the-data](./103-dig_the-data): Bash script that reads content from an 101 | Apace log access file and groups visitors by IP and HTTP status code. 102 | * Displays the grouped number of visitors to an IP address in the format 103 | `OCCURRENCE_NUMBER IP HTTP_CODE`. 104 | * Logs are grouped in order of greatest to lowest number of visitors. 105 | * Uses `awk`. 106 | -------------------------------------------------------------------------------- /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/holbertonscript.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/holbertonscript.pid and terminates upon 8 | #+ receiving a SIGQUIT or SIGTERM. 9 | 10 | terminator() { 11 | rm /var/run/holbertonscript.pid 12 | exit 13 | } 14 | 15 | echo "$$" > /var/run/holbertonscript.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 | echo $$ > /var/run/my_process.pid 24 | echo "manage_my_process started" 25 | 26 | elif [ "$1" == "stop" ] 27 | then 28 | kill "$(pgrep -f /manage_my_process)" 29 | rm /var/run/my_process.pid 30 | echo "manage_my_process stopped" 31 | 32 | elif [ "$1" == "restart" ] 33 | then 34 | kill "$(pgrep -f /manage_my_process)" 35 | rm /var/run/my_process.pid 36 | ./manage_my_process & 37 | echo $$ > /var/run/my_process.pid 38 | echo "manage_my_process restarted" 39 | 40 | else 41 | echo "Usage: manage_my_process {start|stop|restart}" 42 | fi 43 | -------------------------------------------------------------------------------- /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-kill_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-kill_me_now_made_easy: -------------------------------------------------------------------------------- 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/7-highlander: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays "To infinity and beyond" indefinitely with 3 | #+ a sleep 2 in between each iteration. 4 | # Displays "I am invincible!!!" in between each iteration. 5 | 6 | while true 7 | do 8 | echo "To infinity and beyond" 9 | sleep 2 10 | trap 'echo "I am invincible"' SIGTERM 11 | done 12 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/8-beheaded_process: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Kills the process 7-highlander. 3 | 4 | pkill -f -SIGKILL 7-highlander 5 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/README.md: -------------------------------------------------------------------------------- 1 | # Processes and signals 2 | 3 | In this project, I learned about handling process ID's and signals in Bash 4 | with `ps`, `pgrep`, `pkill`, `pkill`, `exit`, and `trap`. 5 | 6 | ## Tasks :page_with_curl: 7 | 8 | * **0. What is my PID** 9 | * [0-what-is-my-pid](./0-what-is-my-pid): Bash script that displays its own PID. 10 | 11 | * **1. List your processes** 12 | * [1-list_your_processes](./1-list_your_processes): Bash script that displays a 13 | list of currently running processes. 14 | * Shows all processes for all users, including those not featuring a TTY. 15 | * Processes are displayed in a user-oriented hierarchy. 16 | 17 | * **2. Show your Bash PID** 18 | * [2-show_your_bash_pid](./2-show_your_bash_pid): Bash script that displays lines 19 | containing the `bash` keyword based on the script defined in `1-list_your_processes`. 20 | 21 | * **3. Show your Bash PID made easy** 22 | * [3-show_your_bash_pid_made_easy](./3-show_your_bash_pid_made_easy): Bash script 23 | that displays the PID along with the process name of processes who name contains the 24 | word `bash`. 25 | 26 | * **4. To infinity and beyond** 27 | * [4-to_infinity_and_beyond](./4-to_infinity_and_beyond): Bash script that displays 28 | `To infinity and beyond` indefinitely with a `sleep 2` in between each iteration. 29 | 30 | * **5. Kill me now** 31 | * [5-kill_me_now](./5-kill_me_now): Bash script that kills the 32 | [4-to_infinity_and_beyond](./4-to_infinity_and_beyond) process using `kill`. 33 | 34 | * **6. Kill me now made easy** 35 | * [6-kill_me_now_made_easy](./6-kill_me_now_made_easy): Bash script that kills the 36 | [4-to_infinity_and_beyond](./4-to_infinity_and_beyond) process using `pkill`. 37 | 38 | * **7. Highlander** 39 | * [7-highlander](./7-highlander): Bash script that displays `To infinity and beyond` 40 | indefinitely with a `sleep 2` in between each iteration. 41 | * Displays `I am invincible!!!` upon receiving a `SIGTERM` signal. 42 | 43 | * **8. Beheaded process** 44 | * [8-beheaded_process](./8-beheaded_process): Bash script that kills the process 45 | [7-highlander](./7-highlander). 46 | 47 | * **9. Process and PID file** 48 | * [100-process_and_pid_file](./100-process_and_pid_file): Bash script that creates the file 49 | `/var/run/holbertonscript.pid` containing its PID and displays `To infinity and 50 | beyond` indefinitely. 51 | * Displays `I hate the kill command` upon receiving a `SIGTERM` signal. 52 | * Displays `Y U no love me?!` upon receiving a `SIGINT` signal. 53 | * Deletes the file `/var/run/holbertonscript.pid` and terminates itself 54 | upon receiving the `SIGQUIT` or `SIGTERM` signal. 55 | 56 | * **10. Manage my process** 57 | * [manage_my_process](./manage_my_process): Bash script that writes `I am alive!` to the file 58 | `/tmp/my_process` indefinitely. 59 | * Sleeps two seconds in between each write. 60 | * [101-manage_my_process](./101-manage_my_process): Bash script that manages the 61 | [manage_my_process](./manage_my_process) script. 62 | * When passed the argument `start`: 63 | * Starts [manage_my_process](./manage_my_process). 64 | * Creates a file containing its PID in `/var/run/my_process.pid`. 65 | * Displays `manage_my_process started`. 66 | * When passed the argument `stop`: 67 | * Stops [manage_my_process](./manage_my_process). 68 | * Deletes the file `/var/run/my_process.pid`. 69 | * Displays `manage_my_process stopped`. 70 | * When passed the argument `restart`: 71 | * Stops [manage_my_process](./manage_my_process). 72 | * Deletes the file `/var/run/my_process.pid`. 73 | * Starts `manage_my_process`. 74 | * Creates a file containing its PID in `/var/run/my_process.pid`. 75 | * Displays `manage_my_process started`. 76 | * Otherwise, displays `Usage: manage_my_process {start|stop|restart}`. 77 | 78 | * **11. Zombie** 79 | * [102-zombie.c](./102-zombie.c): C program that creates five zombie processes. 80 | * For every zombie created, displays `Zombie process created, PID: 81 | `. 82 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/manage_my_process: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Indefinitely writes "I am alive" to the file /tmp/my_process. 3 | # Pauses two seconds in between each message. 4 | 5 | while true 6 | do 7 | echo "I am alive!" >> /tmp/my_process 8 | sleep 2 9 | done 10 | -------------------------------------------------------------------------------- /0x06-regular_expressions/0-simply_match_holberton.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | puts ARGV[0].scan(/Holberton/).join 3 | -------------------------------------------------------------------------------- /0x06-regular_expressions/1-repetition_token_0.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | puts ARGV[0].scan(/hbt{2,5}n/).join 3 | -------------------------------------------------------------------------------- /0x06-regular_expressions/100-textme.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | puts ARGV[0].scan(/\[from:(.*?)\] \[to:(.*?)\] \[flags:(.*?)\]/).join(",") 3 | -------------------------------------------------------------------------------- /0x06-regular_expressions/101-passed_linkedin_regex_challenge.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdbaraban/holberton-system_engineering-devops/b91f70f6d78ce366709e0ebe9928663c6d0e2d5b/0x06-regular_expressions/101-passed_linkedin_regex_challenge.jpg -------------------------------------------------------------------------------- /0x06-regular_expressions/2-repetition_token_1.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | puts ARGV[0].scan(/hb?t?n/).join 3 | -------------------------------------------------------------------------------- /0x06-regular_expressions/3-repetition_token_2.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | puts ARGV[0].scan(/hbt+n/).join 3 | -------------------------------------------------------------------------------- /0x06-regular_expressions/4-repetition_token_3.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | puts ARGV[0].scan(/hbt*n/).join 3 | -------------------------------------------------------------------------------- /0x06-regular_expressions/5-beginning_and_end.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | puts ARGV[0].scan(/^h.n$/).join 3 | -------------------------------------------------------------------------------- /0x06-regular_expressions/6-phone_number.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | puts ARGV[0].scan(/^\d{10,10}$/).join 3 | -------------------------------------------------------------------------------- /0x06-regular_expressions/7-OMG_WHY_ARE_YOU_SHOUTING.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | puts ARGV[0].scan(/[A-Z]*/).join 3 | -------------------------------------------------------------------------------- /0x06-regular_expressions/README.md: -------------------------------------------------------------------------------- 1 | # Regular expression 2 | 3 | In this project, I learned how to use regular expressions. I practiced building 4 | them using Ruby's Oniguruma library. 5 | 6 | ## Tasks :page_with_curl: 7 | 8 | _Note: Each Ruby script in the project matches regular expressions based on an 9 | argument passed to it via the command line._ 10 | 11 | * **0. Simply matching Holberton** 12 | * [0-simply_match_holberton.rb](./0-simply_match_holberton.rb): Ruby script that 13 | matches the regular expression `Holberton`. 14 | 15 | * **1. Repetition Token #0** 16 | * [1-repetition_token_0.rb](./1-repetition_token_0.rb): Ruby script that matches 17 | the regular expression `hbn` with between 2-5 `t`'s in between `hb` and `n`. 18 | 19 | * **2. Repetition Token #1** 20 | * [2-repetition_token_1.rb](./2-repetition_token_1.rb): Ruby script that matches 21 | the regular expression `hn` with 0 or 1 occurrences of `b` and 0 or 1 22 | occurrences of `t` in between `h` and `n`. 23 | 24 | * **3. Repetition Token #2** 25 | * [3-repetition_token_2.rb](./3-repetition_token_2.rb): Ruby script that matches 26 | the regular expression `hbn` with 1 or more `t`'s in between `hb` and `n`. 27 | 28 | * **4. Repetition Token #3** 29 | * [4-repetition_token_3.rb](./4-repetition_token_3.rb): Ruby script that matches the 30 | regular expression `hbn` with 0 or more `t`'s in between `hb` and `n`. 31 | 32 | * **5. Not quite HBTN yet** 33 | * [5-beginning_and_end.rb](./5-beginning_and_end.rb): Ruby script that matches a 34 | regular expression starting with `h` and ending with `n` with any single character in between. 35 | 36 | * **6. Call me maybe** 37 | * [6-phone_number.rb](./6-phone_number.rb): Ruby script that matches a regular expression 38 | representing a 10-digit phone number. 39 | 40 | * **7. OMG WHY ARE YOU SHOUTING?** 41 | * [7-OMG_WHY_ARE_YOU_SHOUTING.rb](./7-OMG_WHY_ARE_YOU_SHOUTING.rb): Ruby script that 42 | matches regular expressions of uppercase letters. 43 | 44 | * **8. Textme** 45 | * [100-textme.rb](./100-textme.rb): Ruby script that runs statistics on TextMe app text 46 | message transcations. 47 | * Output: `[SENDER],[RECEIVER],[FLAGS]` where 48 | * `[SENDER]` is the sender phone number or name (including country code 49 | if present). 50 | * `[RECEIVER]` is the receiver phone number or name (including country code 51 | if present). 52 | * `[FLAGS]` is the flags that were used. 53 | 54 | * **9. Pass LinkedIn technical interview level0** 55 | * [101-passed_linkedin_regex_challenge.jpg](./101-passed_linkedin_regex_challenge.jpg): 56 | Screenshot signifying completion of the 57 | [LinkedIn Engineering Regex Puzzle](https://engineering.linkedin.com/puzzle). 58 | -------------------------------------------------------------------------------- /0x07-networking_basics/0-OSI_model: -------------------------------------------------------------------------------- 1 | 2 2 | 2 3 | -------------------------------------------------------------------------------- /0x07-networking_basics/1-types_of_network: -------------------------------------------------------------------------------- 1 | 3 2 | 2 3 | 1 4 | -------------------------------------------------------------------------------- /0x07-networking_basics/2-MAC_and_IP_address: -------------------------------------------------------------------------------- 1 | 2 2 | 1 3 | -------------------------------------------------------------------------------- /0x07-networking_basics/3-UDP_and_TCP: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 1 4 | -------------------------------------------------------------------------------- /0x07-networking_basics/4-TCP_and_UDP_ports: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays listening ports. Includes listening sockets as well 3 | # + as the PID and name of the program to which each socket belongs. 4 | 5 | netstat -l --program 6 | -------------------------------------------------------------------------------- /0x07-networking_basics/5-is_the_host_on_the_network: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Pings an IP address received as an argument 5 times. 3 | 4 | if [ $# -eq 0 ] 5 | then 6 | echo "Usage: 5-is_the_host_on_the_network {IP_ADDRESS}" 7 | else 8 | ping -c 5 "$1" 9 | fi 10 | -------------------------------------------------------------------------------- /0x07-networking_basics/README.md: -------------------------------------------------------------------------------- 1 | # Networking basics #0 2 | 3 | This project was the first of two introducing networking concepts. In this 4 | project, I answered a few quiz-like questions and wrote a couple bash scripts 5 | while learning about the OSI model, LAN and WAN networks, and TCP/UDP data 6 | transfer protocols. 7 | 8 | ## Tasks :page_with_curl: 9 | 10 | * **0. OSI model** 11 | * [0-OSI_model](./0-OSI_model): Text file answering the following questions: 12 | * What is the OSI model? 13 | 1. Set of specifications that network hardware manufacturers must respect 14 | 2. The OSI model is a conceptual model that characterizes the communication 15 | functions of a telecommunication system without regard to their underlying 16 | internal structure and technology. 17 | 3. The OSI model is a model that characterizes the communication functions 18 | of a telecommunication system with a strong regard for their underlying 19 | internal structure and technology. 20 | * How is the OSI model organized? 21 | 1. Alphabetically 22 | 2. From the lowest to the highest level 23 | 3. Randomly 24 | 25 | * **1. Types of network** 26 | * [1-types_of_network](./1-types_of_network): Text file answering the following questions: 27 | * What type of network are Holberton iMacs connected to? 28 | 1. Internet 29 | 2. WAN 30 | 3. LAN 31 | * What type of network could connect an office in one building to another 32 | office in a building a few streets away? 33 | 1. Internet 34 | 2. WAN 35 | 3. LAN 36 | * What network do you use when you browse www.holbertonschool.com from your 37 | smartphone (not connected to the Wifi)? 38 | 1. Internet 39 | 2. WAN 40 | 3. LAN 41 | 42 | * **2. MAC and IP address** 43 | * [2-MAC_and_IP_address](./2-MAC_and_IP_address): Text file answering the following questions: 44 | * What is a MAC address? 45 | 1. The name of a network interface 46 | 2. The unique identifier of a network interface 47 | 3. A network interface 48 | * What is an IP address? 49 | 1. Is to devices connected to a network what postal address is to houses 50 | 2. The unique identifier of a network interface 51 | 3. Is a number that network devices use to connect to networks 52 | 53 | * **3. UDP and TCP** 54 | * [3-UDP_and_TCP](./3-UDP_and_TCP): Text file answering the following questions 55 | (boxes refer to an image provided by Holberton School): 56 | * Which statement is correct for the TCP box: 57 | 1. It is a protocol that is transferring data in a slow way but surely 58 | 2. It is a protocol that is transferring data in a fast way and might loss 59 | data along in the process 60 | * Which statement is correct for the UDP box: 61 | 1. It is a protocol that is transferring data in a slow way but surely 62 | 2. It is a protocol that is transferring data in a fast way and might loss 63 | data along in the process 64 | * Which statement is correct for the TCP worker: 65 | 1. Have you received boxes x, y, z? 66 | 2. May I increase the rate at which I am sending you boxes? 67 | 68 | * **4. TCP and UDP ports** 69 | * [4-TCP_and_UDP_ports](./4-TCP_and_UDP_ports): Bash script that displays listening ports. 70 | * Only shows listening sockets. 71 | * Displays the PID and name of the program to which each socket belongs. 72 | 73 | * **5. Is the host on the network** 74 | * [5-is_the_host_on_the_network](./5-is_the_host_on_the_network): Bash script that 75 | pings an IP address received as an argument 5 times. 76 | * Usage: `5-is_the_host_on_the_network {IP_ADDRESS}`. 77 | -------------------------------------------------------------------------------- /0x08-networking_basics_2/0-localhost: -------------------------------------------------------------------------------- 1 | 2 2 | -------------------------------------------------------------------------------- /0x08-networking_basics_2/1-wildcard: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /0x08-networking_basics_2/2-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/3-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/4-port_listening_on_localhost: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Listens on port 98 on localhost. 3 | 4 | nc -l localhost 98 5 | -------------------------------------------------------------------------------- /0x08-networking_basics_2/README.md: -------------------------------------------------------------------------------- 1 | # Networking basics #1 2 | 3 | This project was the second of two introducing networking. I continued to learn 4 | about IP addresses while practicing manipulating them with Bash scripts. 5 | 6 | ## Tasks :page_with_curl: 7 | 8 | * **Localhost** 9 | * [0-localhost](./0-localhost): Text file that answers the following question: 10 | * What is `localhost`? 11 | 1. A hostname that means this IP 12 | 2. A hostname that means this computer 13 | 3. An IP attached to a computer 14 | 15 | * **1. All IPs** 16 | * [1-wildcard](./1-wildcard): Text file that answers the following question: 17 | * What is `0.0.0.0`? 18 | 1. All IPv4 addresses on the local machine 19 | 2. All the IPs 20 | 3. It means null in networking 21 | 22 | * **2. Change your home IP** 23 | * [2-change_your_home_IP](./2-change_your_home_IP): Bash script that configures 24 | an Ubuntu server as follows: 25 | * `localhost` resolves to `127.0.0.2` 26 | * `facebook.com` resolves to `8.8.8.8` 27 | 28 | * **3. Show attached IPs** 29 | * [3-show_attached_IPs](./3-show_attached_IPs): Bash script that displays all active IPv4 30 | IP's on the machine. 31 | 32 | * **4. Port listening on localhost** 33 | * [4-port_listening_on_localhost](./4-port_listening_on_localhost): Bash script that 34 | listens on port `98` on `localhost`. 35 | -------------------------------------------------------------------------------- /0x09-web_infrastructure_design/0-simple_web_stack: -------------------------------------------------------------------------------- 1 | https://imgur.com/rf2Vinm 2 | -------------------------------------------------------------------------------- /0x09-web_infrastructure_design/1-distributed_web_infrastructure: -------------------------------------------------------------------------------- 1 | https://imgur.com/scS4tTj 2 | -------------------------------------------------------------------------------- /0x09-web_infrastructure_design/2-secured_and_monitored_web_infrastructure: -------------------------------------------------------------------------------- 1 | https://imgur.com/F53GXdo 2 | -------------------------------------------------------------------------------- /0x09-web_infrastructure_design/3-scale_up: -------------------------------------------------------------------------------- 1 | https://imgur.com/RUIDBKj 2 | -------------------------------------------------------------------------------- /0x09-web_infrastructure_design/README.md: -------------------------------------------------------------------------------- 1 | # Web infrastructure design 2 | 3 | This was a week-long project in which I began to research web infrastructure 4 | design. As I conducted research on different design principles, I 5 | whiteboarded diagrams of a developing web infrastructure. I started with a 6 | simple LAMP model and ended with a fully distributed, monitored, and secured 7 | system. 8 | 9 | Files in this project contain links to each respective whiteboard diagram. 10 | -------------------------------------------------------------------------------- /0x0A-ssh/0-use_a_private_key: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Connects to my Holberton server. 3 | ssh -i ~/.ssh/holberton ubuntu@104.196.168.90 4 | -------------------------------------------------------------------------------- /0x0A-ssh/1-create_ssh_key_pair: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Creates a new 4096-byte RSA key pair named holberton. 3 | ssh-keygen -b 4096 -N betty -f holberton 4 | -------------------------------------------------------------------------------- /0x0A-ssh/2-ssh_config: -------------------------------------------------------------------------------- 1 | 2 | # This is the ssh client system-wide configuration file. See 3 | # ssh_config(5) for more information. This file provides defaults for 4 | # users, and the values can be changed in per-user configuration files 5 | # or on the command line. 6 | 7 | # Configuration data is parsed as follows: 8 | # 1. command line options 9 | # 2. user-specific file 10 | # 3. system-wide file 11 | # Any configuration value is only changed the first time it is set. 12 | # Thus, host-specific definitions should be at the beginning of the 13 | # configuration file, and defaults at the end. 14 | 15 | # Site-wide defaults for some commonly used options. For a comprehensive 16 | # list of available options, their meanings and defaults, please see the 17 | # ssh_config(5) man page. 18 | 19 | Host * 20 | # ForwardAgent no 21 | # ForwardX11 no 22 | # ForwardX11Trusted yes 23 | # RhostsRSAAuthentication no 24 | # RSAAuthentication yes 25 | PasswordAuthentication no 26 | # HostbasedAuthentication no 27 | # GSSAPIAuthentication no 28 | # GSSAPIDelegateCredentials no 29 | # GSSAPIKeyExchange no 30 | # GSSAPITrustDNS no 31 | # BatchMode no 32 | # CheckHostIP yes 33 | # AddressFamily any 34 | # ConnectTimeout 0 35 | # StrictHostKeyChecking ask 36 | # IdentityFile ~/.ssh/identity 37 | # IdentityFile ~/.ssh/id_rsa 38 | # IdentityFile ~/.ssh/id_dsa 39 | IdentityFile ~/.ssh/holberton 40 | # Port 22 41 | # Protocol 2,1 42 | # Cipher 3des 43 | # Ciphers aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc 44 | # MACs hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160 45 | # EscapeChar ~ 46 | # Tunnel no 47 | # TunnelDevice any:any 48 | # PermitLocalCommand no 49 | # VisualHostKey no 50 | # ProxyCommand ssh -q -W %h:%p gateway.example.com 51 | # RekeyLimit 1G 1h 52 | SendEnv LANG LC_* 53 | HashKnownHosts yes 54 | GSSAPIAuthentication yes 55 | GSSAPIDelegateCredentials no 56 | -------------------------------------------------------------------------------- /0x0A-ssh/README.md: -------------------------------------------------------------------------------- 1 | # SSH 2 | 3 | In this project, I became familiar connecting to and working 4 | with servers using the SSH protocol. I worked on a server 5 | provided by Holberton School. 6 | 7 | ## Tasks :page_with_curl: 8 | 9 | * **0. Use a private key** 10 | * [0-use_a_private_key](./0-use_a_private_key): Bash script that uses `ssh` to connect to my 11 | Holberton-provided server. 12 | 13 | * **1. Create an SSH key pair** 14 | * [1-create_ssh_key_pair](./1-create_ssh_key_pair): Bash script that creates an RSA key pair. 15 | 16 | * **2. Client configuration file** 17 | * [2-ssh_config](./2-ssh_config): SSH configuration file configured to use the private key 18 | `~/.ssh/holberton` and to refuse authentication using a password. 19 | -------------------------------------------------------------------------------- /0x0B-web_server/0-transfer_file: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Transfers a file from Holberton's client to another. 3 | # Accepts four arguments: 4 | #+ The path to the file to be transferred. 5 | #+ The IP of the server to transfer the file to. 6 | #+ The username that scp connects with. 7 | #+ The path to the SSH private key that scp uses. 8 | 9 | if [ $# -lt 4 ] 10 | then 11 | echo "Usage: 0-transfer_file PATH_TO_FILE IP USERNAME PATH_TO_SSH_KEY" 12 | else 13 | scp -o StrictHostKeyChecking=no -i "$4" "$1" "$3@$2":~ 14 | fi 15 | -------------------------------------------------------------------------------- /0x0B-web_server/1-install_nginx_web_server: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Installs Nginx with the following configurations: 3 | #+ Listens on port 80. 4 | #+ Returns a page containing "Holberton School" when queried 5 | #++ at the root with a curl GET request. 6 | 7 | apt-get update 8 | apt-get install -y nginx 9 | 10 | mkdir /etc/nginx/html 11 | touch /etc/nginx/html/index.html 12 | echo "Holberton School" > /etc/nginx/html/index.html 13 | printf %s "server { 14 | listen 80 default_server; 15 | listen [::]:80 default_server; 16 | root /etc/nginx/html; 17 | index index.html index.htm; 18 | } 19 | " > /etc/nginx/sites-available/default 20 | 21 | service nginx restart 22 | -------------------------------------------------------------------------------- /0x0B-web_server/2-setup_a_domain_name: -------------------------------------------------------------------------------- 1 | bdbnb.site 2 | -------------------------------------------------------------------------------- /0x0B-web_server/3-redirection: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Configures an Nginx server so that /redirect_me redirects to another page. 3 | # The redirection is configured as a "301 Moved Permanently" 4 | 5 | apt-get update 6 | apt-get install -y nginx 7 | 8 | mkdir /etc/nginx/html 9 | touch /etc/nginx/html/index.html 10 | echo "Holberton School" > /etc/nginx/html/index.html 11 | printf %s "server { 12 | listen 80; 13 | listen [::]:80 default_server; 14 | root /etc/nginx/html; 15 | index index.html index.htm; 16 | 17 | location /redirect_me { 18 | return 301 http://cuberule.com/; 19 | } 20 | }" > /etc/nginx/sites-available/default 21 | 22 | service nginx restart 23 | -------------------------------------------------------------------------------- /0x0B-web_server/4-not_found_page_404: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Installs Nginx with the following configurations: 3 | #+ Listens on port 80. 4 | #+ Returns a page containing "Holberton School" when queried 5 | #+ at the root with a curl GET request. 6 | # Configures /redirect_me as a "301 Moved Permanently". 7 | # Includes a custom 404 page containing "Ceci n'est pas une page". 8 | 9 | apt-get update 10 | apt-get install -y nginx 11 | 12 | mkdir /etc/nginx/html 13 | touch /etc/nginx/html/index.html 14 | echo "Holberton School" > /etc/nginx/html/index.html 15 | touch /etc/nginx/html/404.html 16 | echo "Ceci n'est pas une page" > /etc/nginx/html/404.html 17 | 18 | printf %s "server { 19 | listen 80; 20 | listen [::]:80 default_server; 21 | root /etc/nginx/html; 22 | index index.html index.htm; 23 | 24 | location /redirect_me { 25 | return 301 http://cuberule.com/; 26 | } 27 | 28 | error_page 404 /404.html; 29 | location /404 { 30 | root /etc/nginx/html; 31 | internal; 32 | } 33 | }" > /etc/nginx/sites-available/default 34 | 35 | service nginx restart 36 | -------------------------------------------------------------------------------- /0x0B-web_server/README.md: -------------------------------------------------------------------------------- 1 | # Web server 2 | 3 | In this project, I learned how web servers work and began using one. I was 4 | provided a personal server by Holberton School. I learned how to use `scp` 5 | and Fabric to transfer files to my server. Additionally, I completed a basic 6 | configuration of the server using Nginx. 7 | 8 | The server is accessible at [bdbnb.site](http://bdbnb.site). 9 | 10 | ## Tasks :page_with_curl: 11 | 12 | * **0. Transfer a file to your server** 13 | * [0-transfer_file](./0-transfer_file): Bash script that transfers a file 14 | from Holberton's client to a server. 15 | * Accepts four arguments: 16 | * The path of the file to be transferred. 17 | * The IP of the server to transfer the file to. 18 | * The username that `scp` connects with. 19 | * The path of the SSH privtae key that `scp` uses. 20 | * `scp` transfers the file to the user home directory `~/`. 21 | 22 | * **1. Install nginx web server** 23 | * [1-install_nginx_web_server](./1-install_nginx_web_server): Bash script 24 | that configures a new Ubuntu machine with Nginx. 25 | * Nginx listens on port 80. 26 | * When querying Nginx at its root `/` with a `curl` GET request, 27 | it returns a page containing the string `Holberton School`. 28 | 29 | * **2. Setup a domain name** 30 | * [2-setup_a_domain_name](./2-setup_a_domain_name): A text file containing 31 | the domain name set up for the server through Gandi. 32 | 33 | * **3. Redirection** 34 | * [3-redirection](./3-redirection): Bash script that configures a new Ubuntu 35 | machine with Nginx. 36 | * Setup is identical to [1-install_nginx_web_server](./1-install_nginx_web_server) 37 | plus: 38 | * The location `/redirect_me` returns a `301 Moved Permanently` redirection 39 | to another page. 40 | 41 | * **4. Not found page 404** 42 | * [4-not_found_page_404](./4-not_found_page_404): Bash script that configures 43 | a new Ubuntu machine with Nginx. 44 | * Setup is identical to [1-install_nginx_web_server](./1-install_nginx_web_server) 45 | plus: 46 | * Features a custom 404 page containing the string `Ceci n'est pas une page`. 47 | 48 | * **5. Design a beautiful 404 page** 49 | * A custom-designed 404 error page for my server, accessible at 50 | [bdbnb.site/404](http://bdbnb.site/404). 51 | 52 | * **6. Deploy fast, deploy well** 53 | * [fabfile.py](./fabfile.py): A Python Fabric configuration file defining 54 | the following functions: 55 | * `pack` 56 | * Usage: `fabric pack` 57 | * Creates a tar gzipped archive of the current directory named 58 | `holbertonwebapp.tar.gz` in the local directory. 59 | * `deploy` 60 | * Usage: `fabric -H deploy` 61 | * Uploads the archive `holbertonwebapp.tar.gz` to the `/tmp` 62 | directory of the remote server. 63 | * Creates the directory `/tmp/holbertonwebapp` in the remote server. 64 | * Untars `holbertonwebapp.tar.gz` in the `/tmp/holbertonwebapp` directory 65 | of the remote server. 66 | * `clean` 67 | * Deletes the archive `holbertonwebapp.tar.gz` in the local directory. 68 | -------------------------------------------------------------------------------- /0x0B-web_server/fabfile.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Fabfile defining functions to pack, deploy, and clean the 3 | # current directory to a remote server. 4 | from fabric import task 5 | 6 | 7 | @task 8 | def pack(c): 9 | """Create a tar gzipped archive of the current directory.""" 10 | c.run("touch holbertonwebapp.tar.gz") 11 | c.run("tar --exclude='*.tar.gz' -cvzf holbertonwebapp.tar.gz .") 12 | 13 | 14 | @task 15 | def deploy(c): 16 | """Upload the archive to the remote server in the /tmp/ directory.""" 17 | c.user = "ubuntu" 18 | c.put("holbertonwebapp.tar.gz", "/tmp") 19 | c.run("mkdir /tmp/holbertonwebapp") 20 | c.run("tar -C /tmp/holbertonwebapp -xzvf /tmp/holbertonwebapp.tar.gz") 21 | 22 | 23 | @task 24 | def clean(c): 25 | """Deletes holbertonwebapp.tar.gz on the local machine.""" 26 | c.run("rm holbertonwebapp.tar.gz") 27 | -------------------------------------------------------------------------------- /0x0C-web_stack_debugging_0/0-give_me_a_page: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Run Apache on the holbertonschool/265-0 Docker container. 3 | echo "ServerName localhost" >> /etc/apache2.conf 4 | service apache2 start 5 | -------------------------------------------------------------------------------- /0x0C-web_stack_debugging_0/README.md: -------------------------------------------------------------------------------- 1 | # Web stack debugging #0 2 | 3 | This was the first in a series of web stack debugging projects. In these 4 | projects, I was given broken/bugged webstacks in isolated containers, 5 | and tasked with fixing the web stack to a working state. For each 6 | task, I wrote a script automating the commands necessary to fix the 7 | web stack. 8 | 9 | ## Tasks :page_with_curl: 10 | 11 | * **0. Give me a page!** 12 | * [0-give_me_a_page](./0-give_me_a_page): Bash script that runs Apache on a 13 | web server and gets it to respond to queries to the root. 14 | -------------------------------------------------------------------------------- /0x0D-configuration_management/0-create_a_file.pp: -------------------------------------------------------------------------------- 1 | # Create a file in /tmp 2 | 3 | file { 'holberton': 4 | ensure => 'present', 5 | content => 'I love Puppet', 6 | group => 'www-data', 7 | mode => '0744', 8 | owner => 'www-data', 9 | path => '/tmp/holberton', 10 | } 11 | -------------------------------------------------------------------------------- /0x0D-configuration_management/1-install_a_package.pp: -------------------------------------------------------------------------------- 1 | # Installs puppet-lint 2 | 3 | package { 'puppet-lint': 4 | ensure => '2.1.1', 5 | provider => 'gem', 6 | } 7 | -------------------------------------------------------------------------------- /0x0D-configuration_management/2-execute_a_command.pp: -------------------------------------------------------------------------------- 1 | # Kills a process named killmenow 2 | 3 | exec { 'pkill -f killmenow': 4 | path => '/usr/bin/:/usr/local/bin/:/bin/' 5 | } 6 | -------------------------------------------------------------------------------- /0x0D-configuration_management/README.md: -------------------------------------------------------------------------------- 1 | # Configuration management 2 | 3 | In this project, I started working with Puppet as a configuration management 4 | tool. I practiced writing Puppet manifest files to create a file, install a 5 | package, and execute a command. 6 | 7 | ## Tasks :page_with_curl: 8 | 9 | * **0. Create a file** 10 | * [0-create_a_file.pp](./0-create_a_file.pp): Puppet manifest file that 11 | creates a file `holberton` in the `/tmp` directory. 12 | * File permissions: `0744`. 13 | * File group: `www-data`. 14 | * File owner: `www-data`. 15 | * File content: `I love Puppet`. 16 | 17 | * **1. Install a package** 18 | * [1-install_a_package.pp](./1-install_a_package.pp): Puppet manifest file 19 | that install puppet-lint version 2.1.1. 20 | 21 | * **2. Execute a command** 22 | * [2-execute_a_command.pp](./2-execute_a_command.pp): Puppet manifest file 23 | that kills the process `killmenow`. 24 | -------------------------------------------------------------------------------- /0x0E-web_stack_debugging_1/0-nginx_likes_port_80: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Configures an Nginx server to listen on port 80. 3 | 4 | rm /etc/nginx/sites-enabled/default 5 | ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default 6 | service nginx restart 7 | -------------------------------------------------------------------------------- /0x0E-web_stack_debugging_1/1-debugging_made_short: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Configures an Nginx server to listen on port 80. 3 | ln -sf /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default 4 | service nginx start 5 | kill "$(pgrep 'nginx' | head -1)" 6 | -------------------------------------------------------------------------------- /0x0E-web_stack_debugging_1/README.md: -------------------------------------------------------------------------------- 1 | # Web stack debugging #1 2 | 3 | This was the second in a series of web stack debugging projects. In these 4 | projects, I was given broken/bugged webstacks in isolated containers, 5 | and tasked with fixing the web stack to a working state. For each 6 | task, I wrote a script automating the commands necessary to fix the 7 | web stack. 8 | 9 | ## Tasks :page_with_curl: 10 | 11 | * **0. Nginx likes port 80** 12 | * [0-nginx_likes_port_80](./0-nginx_likes_port_80): Bash script that 13 | configures Nginx to run and listen to port 80 on all of a server's active IPv4's. 14 | 15 | * **1. Make it sweet and short** 16 | * [1-debugging_made_short](./1-debugging_made_short): Bash script that 17 | configures Nginx to listen to port 80 without running on all of a server's 18 | active IPv4's. 19 | -------------------------------------------------------------------------------- /0x0F-load_balancer/0-custom_http_response-header: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Installs Nginx with the following configurations: 3 | #+ Listens on port 80. 4 | #+ Returns a page containing "Holberton School" when queried 5 | #+ at the root with a curl GET request. 6 | #+ Configures /redirect_me as a "301 Moved Permanently". 7 | #+ Includes a custom 404 page containing "Ceci n'est pas une page". 8 | #+ Contains a custom HTTP header named X-Served-By. 9 | #+ The value of the HTTP header is the hostname of the running server. 10 | 11 | apt-get update 12 | apt-get install -y nginx 13 | 14 | mkdir -p /var/www/html 15 | touch /var/www/html/index.html 16 | echo "Holberton School" > /var/www/html/index.html 17 | touch /var/www/html/404.html 18 | echo "Ceci n'est pas une page" > /var/www/html/404.html 19 | 20 | printf %s "server { 21 | listen 80 default_server; 22 | listen [::]:80 default_server; 23 | add_header X-Served-By $HOSTNAME; 24 | root /var/www/html; 25 | index index.html index.htm; 26 | 27 | location /redirect_me { 28 | return 301 http://cuberule.com/; 29 | } 30 | 31 | error_page 404 /404.html; 32 | location /404 { 33 | root /var/www/html; 34 | internal; 35 | } 36 | }" > /etc/nginx/sites-available/default 37 | 38 | service nginx restart 39 | -------------------------------------------------------------------------------- /0x0F-load_balancer/1-install_load_balancer: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Installs HAProxy version 1.8 with the following configurations: 3 | #+ Enables management via the init script. 4 | #+ Distributes requests using a round-robin algorithm. 5 | 6 | apt-get install -y software-properties-common 7 | add-apt-repository -y ppa:vbernat/haproxy-1.8 8 | apt-get update 9 | apt-get install -y haproxy=1.8.\* 10 | 11 | echo "ENABLED=1" >> /etc/default/haproxy 12 | mv /etc/haproxy/haproxy.cfg{,.original} 13 | touch /etc/haproxy/haproxy.cfg 14 | 15 | printf %s "global 16 | log 127.0.0.1 local0 notice 17 | maxconn 2000 18 | user haproxy 19 | group haproxy 20 | 21 | defaults 22 | log global 23 | mode http 24 | option httplog 25 | option dontlognull 26 | retries 3 27 | option redispatch 28 | timeout connect 5000 29 | timeout client 10000 30 | timeout server 10000 31 | 32 | listen hbnb 33 | bind 0.0.0.0:80 34 | mode http 35 | stats enable 36 | stats uri /haproxy?stats 37 | balance roundrobin 38 | option httpclose 39 | option forwardfor 40 | server 375-web-01 104.196.168.90:80 check 41 | server 375-web-02 35.196.46.172:80 check 42 | " >> /etc/haproxy/haproxy.cfg 43 | 44 | service haproxy start 45 | -------------------------------------------------------------------------------- /0x0F-load_balancer/README.md: -------------------------------------------------------------------------------- 1 | # Load balancer 2 | 3 | In this project, I continued to build up the configuration of the web server 4 | issued in project 0x0B. I was issued two additional servers, one to replicate 5 | the Nginx configuration of my original server, and another to set up an HAproxy 6 | load balancer on to manage both web servers. 7 | 8 | ## Tasks :page_with_curl: 9 | 10 | * **0. Double the number of webservers** 11 | * [0-custom_http_response_header](./0-custom_http_response-header): Bash 12 | script that installs and configures Nginx on a server with a custom HTTP 13 | response header. 14 | * The name of the HTTP header is `X-Served-By`. 15 | * The value of the HTTP header is the hostname of the server. 16 | 17 | * **1. Install your load balancer** 18 | * [1-install_load_balancer](./1-install_load_balancer): Bash script that 19 | installs and configures HAproxy version 1.5 on a server. 20 | * Enables management via the init script. 21 | * Requests are distributed using a round-robin algorithm. 22 | -------------------------------------------------------------------------------- /0x10-https_ssl/0-https_abc: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | -------------------------------------------------------------------------------- /0x10-https_ssl/1-world_wide_web: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Usage: ./1-world_wide_web 3 | # Display information about subdomains. 4 | 5 | domain_information () { 6 | line=$(dig "$2"."$1" | grep -A1 'ANSWER SECTION:' | tr '\t' '\n' | tail -2 | tr '\n' ' ') 7 | echo "$2 $line" | awk '{print "The subdomain " $1 " is a " $2 " record and points to " $3}' 8 | } 9 | 10 | if [ "$#" == 1 ] 11 | then 12 | domain_information "$1" "www" 13 | domain_information "$1" "lb-01" 14 | domain_information "$1" "web-01" 15 | domain_information "$1" "web-02" 16 | elif [ "$#" == 2 ] 17 | then 18 | domain_information "$1" "$2" 19 | fi 20 | -------------------------------------------------------------------------------- /0x10-https_ssl/100-redirect_http_to_https: -------------------------------------------------------------------------------- 1 | global 2 | log /dev/log local0 3 | maxconn 2048 4 | user haproxy 5 | group haproxy 6 | tune.ssl.default-dh-param 2048 7 | 8 | defaults 9 | log global 10 | mode http 11 | option httplog 12 | option dontlognull 13 | retries 3 14 | option redispatch 15 | timeout connect 5000 16 | timeout client 10000 17 | timeout server 10000 18 | option forwardfor 19 | option http-server-close 20 | 21 | frontend www-http 22 | bind 0.0.0.0:80 23 | reqadd X-Forwarded-Proto:\ http 24 | default_backend www-backend 25 | redirect scheme https code 301 if !{ ssl_fc } 26 | 27 | frontend www-https 28 | bind 0.0.0.0:443 ssl crt /etc/haproxy/certs/www.bdbnb.site.pem 29 | reqadd X-Forwarded-Proto:\ https 30 | acl letsencrypt-acl path_beg /.well-known/acme-challenge/ 31 | use_backend letsencrypt-backend if letsencrypt-acl 32 | default_backend www-backend 33 | 34 | backend www-backend 35 | balance roundrobin 36 | redirect scheme https if !{ ssl_fc } 37 | server 375-web-01 104.196.168.90:80 check 38 | server 375-web-02 35.196.46.172:80 check 39 | 40 | backend letsencrypt-backend 41 | server letsencrypt 127.0.0.1:54321 42 | -------------------------------------------------------------------------------- /0x10-https_ssl/2-haproxy_ssl_termination: -------------------------------------------------------------------------------- 1 | global 2 | log /dev/log local0 3 | maxconn 2048 4 | user haproxy 5 | group haproxy 6 | tune.ssl.default-dh-param 2048 7 | 8 | defaults 9 | log global 10 | mode http 11 | option httplog 12 | option dontlognull 13 | retries 3 14 | option redispatch 15 | timeout connect 5000 16 | timeout client 10000 17 | timeout server 10000 18 | option forwardfor 19 | option http-server-close 20 | 21 | frontend www-http 22 | bind 0.0.0.0:80 23 | reqadd X-Forwarded-Proto:\ http 24 | default_backend www-backend 25 | 26 | frontend www-https 27 | bind 0.0.0.0:443 ssl crt /etc/haproxy/certs/www.bdbnb.site.pem 28 | reqadd X-Forwarded-Proto:\ https 29 | acl letsencrypt-acl path_beg /.well-known/acme-challenge/ 30 | use_backend letsencrypt-backend if letsencrypt-acl 31 | default_backend www-backend 32 | 33 | backend www-backend 34 | balance roundrobin 35 | redirect scheme https if !{ ssl_fc } 36 | server 375-web-01 104.196.168.90:80 check 37 | server 375-web-02 35.196.46.172:80 check 38 | 39 | backend letsencrypt-backend 40 | server letsencrypt 127.0.0.1:54321 41 | -------------------------------------------------------------------------------- /0x10-https_ssl/README.md: -------------------------------------------------------------------------------- 1 | # HTTPS SSL 2 | 3 | In this project, I learned about the importance of HTTPS and how it works. I 4 | configured my HolbertonBnB web servers with `certbot` certificate and HAproxy 5 | SSL termination. 6 | 7 | ## Tasks :page_with_curl: 8 | 9 | * **0. HTTPS ABC** 10 | * [0-https_abc](./0-https_abc): Text file containing answers to the 11 | following questions, one answer per line: 12 | * What is HTTPS? 13 | * A secure version of HTTP. 14 | * A faster version of HTTP. 15 | * A superior version of HTTP. 16 | * Why do you need HTTPS? 17 | * To encrypt credit card and social security number information going 18 | between the client and the website servers. 19 | * To encrypt all communication between the client and the website 20 | servers. 21 | * To accelerate the communication between the client and the website 22 | servers. 23 | * In a secure location where nobody can access it. 24 | * You can host it anywhere but you have to share the link to it on your 25 | website. 26 | * On your website web server(s). 27 | 28 | * **1. World wide web** 29 | * [1-world_wide_web](./1-world_wide_web): Bash script that displays 30 | information about subdomains on my configured servers. 31 | * Usage: `./1-world_wide_web ` 32 | * Output: `The subdomain [SUB_DOMAIN] is a [RECORD_TYPE] record and 33 | points to [DESTINATION]` 34 | * If no `subdomain` parameter is passed, displays information about the 35 | subdomains `www`, `lb-01`, `web-01` and `web-02`, in that order. 36 | 37 | * **2. HAproxy SSL termination** 38 | * [2-haproxy_ssl_termination](./2-haproxy_ssl_termination): HAproxy 39 | configuration file that accepts encrypted SSL traffic for the subdomain 40 | `www.` on TCP port 443. 41 | 42 | * **3. No loophole in your website traffic** 43 | * [100-redirect_http_to_https](./100-redirect_http_to_https): HAproxy 44 | configuration file that automatically redirects HTTP traffic to HTTPS. 45 | -------------------------------------------------------------------------------- /0x11-what_happens_when_your_type_holbertonschool_com_in_your_browser_and_press_enter/0-blog_post: -------------------------------------------------------------------------------- 1 | https://medium.com/@bdov_/what-happens-when-you-type-fill-in-the-blank-website-into-a-browser-and-hit-enter-739702df3999 2 | -------------------------------------------------------------------------------- /0x11-what_happens_when_your_type_holbertonschool_com_in_your_browser_and_press_enter/1-what_happen_when_diagram: -------------------------------------------------------------------------------- 1 | https://imgur.com/a/kQc2ujU 2 | -------------------------------------------------------------------------------- /0x11-what_happens_when_your_type_holbertonschool_com_in_your_browser_and_press_enter/README.md: -------------------------------------------------------------------------------- 1 | # What happens when you type holbertonschool.com in your browser and press Enter 2 | 3 | Reviewing and encapsulating networking knowledge and skills I had been learning 4 | and practicing over the last month, in this project, I wrote a blog post 5 | answering the classic interview question - what happens when you enter [generic 6 | website] into a browser and hit `Enter`? 7 | 8 | ## Tasks :page_with_curl: 9 | 10 | * **0. What happens when...** 11 | * [0-blog_post](./0-blog_post): Text file containing the link to my blog post. 12 | 13 | * **1. Everything's better with a pretty diagram** 14 | * [1-what_happen_when_diagram](./1-what_happen_when_diagram): Text file 15 | containing the link to a diagram put togeter to visualize the networking 16 | process described in my blog. 17 | -------------------------------------------------------------------------------- /0x12-web_stack_debugging_2/0-iamsomeonelese: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Runs the whoami command under the user passed as argument. 3 | sudo -u "$1" whoami 4 | -------------------------------------------------------------------------------- /0x12-web_stack_debugging_2/1-run_nginx_as_nginx: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Fixes a web server to run Nginx as the nginx user listening on port 8080. 3 | sed -i "s/#user www-data/user nginx/" /etc/nginx/nginx.conf 4 | sed -i "s/80/8080/g" /etc/nginx/sites-available/default 5 | chmod 644 /etc/nginx/nginx.conf 6 | pkill apache2 7 | sudo -u nginx service nginx start 8 | -------------------------------------------------------------------------------- /0x12-web_stack_debugging_2/100-fix_in_7_lines_or_less: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Fixes a web server to run Nginx as the nginx user listening on port 8080. 3 | sed -i "s/#user www-data/user nginx/" /etc/nginx/nginx.conf 4 | sed -i "s/80/8080/g" /etc/nginx/sites-available/default 5 | chmod 644 /etc/nginx/nginx.conf 6 | pkill apache2 7 | sudo -u nginx service nginx start 8 | -------------------------------------------------------------------------------- /0x12-web_stack_debugging_2/README.md: -------------------------------------------------------------------------------- 1 | # Web stack debugging #2 2 | 3 | This was the third in a series of web stack debugging projects. In these 4 | projects, I was given broken/bugged webstacks in isolated containers, 5 | and tasked with fixing the web stack to a working state. For each 6 | task, I wrote a script automating the commands necessary to fix the 7 | web stack. 8 | 9 | ## Tasks :page_with_curl: 10 | 11 | * **0. Run software as another user** 12 | * [0-iamsomeonelese](./0-iamsomeonelese): Bash script that runs the command 13 | `whoami` under the user passed as argument. 14 | * Usage: `./0-iamsomeonelese ` 15 | 16 | * **1. Run Nginx as Nginx** 17 | * [1-run_nginx_as_nginx](./1-run_nginx_as_nginx): Bash script that fixes a 18 | web server to run Nginx listening on port `8080` as the `nginx` user. 19 | 20 | * **2. 7 lines or less** 21 | * [100-fix_in_7_lines_or_less](./100-fix_in_7_lines_or_less): Bash script 22 | that fixes a web server to run Nginx listening on port `8080` as the `nginx` 23 | user. 24 | * 7 lines long. 25 | -------------------------------------------------------------------------------- /0x13-firewall/0-firewall_ABC: -------------------------------------------------------------------------------- 1 | 2 2 | 3 3 | 1 4 | -------------------------------------------------------------------------------- /0x13-firewall/1-block_all_incoming_traffic_but: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Configures a ufw firewall to block all incoming traffic 3 | #+ except for TCP ports 22, 443 and 80. 4 | 5 | apt-get install ufw 6 | sed -i 's/IPV6=.*/IPV6=yes/' /etc/default/ufw 7 | ufw disable 8 | ufw enable 9 | ufw default deny incoming 10 | ufw default allow outgoing 11 | ufw allow 22/tcp 12 | ufw allow 443/tcp 13 | ufw allow 80/tcp 14 | -------------------------------------------------------------------------------- /0x13-firewall/100-port_forwarding: -------------------------------------------------------------------------------- 1 | # 2 | # rules.before 3 | # 4 | # Rules that should be run before the ufw command line added rules. Custom 5 | # rules should be added to one of these chains: 6 | # ufw-before-input 7 | # ufw-before-output 8 | # ufw-before-forward 9 | # 10 | 11 | *nat 12 | :PREROUTING ACCEPT [0:0] 13 | -A PREROUTING -p tcp --dport 8080 -j REDIRECT --to-port 80 14 | 15 | # Don't delete these required lines, otherwise there will be errors 16 | *filter 17 | :ufw-before-input - [0:0] 18 | :ufw-before-output - [0:0] 19 | :ufw-before-forward - [0:0] 20 | :ufw-not-local - [0:0] 21 | # End required lines 22 | 23 | 24 | # allow all on loopback 25 | -A ufw-before-input -i lo -j ACCEPT 26 | -A ufw-before-output -o lo -j ACCEPT 27 | 28 | # quickly process packets for which we already have a connection 29 | -A ufw-before-input -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT 30 | -A ufw-before-output -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT 31 | -A ufw-before-forward -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT 32 | 33 | # drop INVALID packets (logs these in loglevel medium and higher) 34 | -A ufw-before-input -m conntrack --ctstate INVALID -j ufw-logging-deny 35 | -A ufw-before-input -m conntrack --ctstate INVALID -j DROP 36 | 37 | # ok icmp codes for INPUT 38 | -A ufw-before-input -p icmp --icmp-type destination-unreachable -j ACCEPT 39 | -A ufw-before-input -p icmp --icmp-type source-quench -j ACCEPT 40 | -A ufw-before-input -p icmp --icmp-type time-exceeded -j ACCEPT 41 | -A ufw-before-input -p icmp --icmp-type parameter-problem -j ACCEPT 42 | -A ufw-before-input -p icmp --icmp-type echo-request -j ACCEPT 43 | 44 | # ok icmp code for FORWARD 45 | -A ufw-before-forward -p icmp --icmp-type destination-unreachable -j ACCEPT 46 | -A ufw-before-forward -p icmp --icmp-type source-quench -j ACCEPT 47 | -A ufw-before-forward -p icmp --icmp-type time-exceeded -j ACCEPT 48 | -A ufw-before-forward -p icmp --icmp-type parameter-problem -j ACCEPT 49 | -A ufw-before-forward -p icmp --icmp-type echo-request -j ACCEPT 50 | 51 | # allow dhcp client to work 52 | -A ufw-before-input -p udp --sport 67 --dport 68 -j ACCEPT 53 | 54 | # 55 | # ufw-not-local 56 | # 57 | -A ufw-before-input -j ufw-not-local 58 | 59 | # if LOCAL, RETURN 60 | -A ufw-not-local -m addrtype --dst-type LOCAL -j RETURN 61 | 62 | # if MULTICAST, RETURN 63 | -A ufw-not-local -m addrtype --dst-type MULTICAST -j RETURN 64 | 65 | # if BROADCAST, RETURN 66 | -A ufw-not-local -m addrtype --dst-type BROADCAST -j RETURN 67 | 68 | # all other non-local packets are dropped 69 | -A ufw-not-local -m limit --limit 3/min --limit-burst 10 -j ufw-logging-deny 70 | -A ufw-not-local -j DROP 71 | 72 | # allow MULTICAST mDNS for service discovery (be sure the MULTICAST line above 73 | # is uncommented) 74 | -A ufw-before-input -p udp -d 224.0.0.251 --dport 5353 -j ACCEPT 75 | 76 | # allow MULTICAST UPnP for service discovery (be sure the MULTICAST line above 77 | # is uncommented) 78 | -A ufw-before-input -p udp -d 239.255.255.250 --dport 1900 -j ACCEPT 79 | 80 | # don't delete the 'COMMIT' line or these rules won't be processed 81 | COMMIT 82 | -------------------------------------------------------------------------------- /0x13-firewall/README.md: -------------------------------------------------------------------------------- 1 | # Firewall 2 | 3 | In this project, I used `ufw` to configure firewalls on my issued web servers. 4 | 5 | ## Tasks :page_with_curl: 6 | 7 | * **0. Firewall ABC** 8 | * [0-firewall_ABC](./0-firewall_ABC): Text file containing answers to the the 9 | following multiple-choice questions, one per line: 10 | * What is a firewall? 11 | * A hardware security system. 12 | * A hardware or software security system. 13 | * A software security system. 14 | * What are the 2 types of firewall? 15 | * Soft and hard firewall 16 | * Incoming and outgoing firewall. 17 | * Network and host-based firewall. 18 | * What is the main function of a firewall? 19 | * To filter incoming and outgoing network traffic. 20 | * To filter incoming and outgoing TCP traffic. 21 | * To filter outgoing traffic. 22 | 23 | * **1. Block all incoming traffic but** 24 | * [1-block_all_incoming_traffic_but](./1-block_all_incoming_traffic_but): Bash 25 | script that installs a `ufw` firewall to block all incoming traffic except for 26 | ports `22`, `443` and `80` on a web server. 27 | 28 | * **2. Port forwarding** 29 | * [100-port_forwarding](./100-port_forwarding): `ufw` configuration file that 30 | configures a firewall to redirect port `8080/TCP` to port `80/TCP`. 31 | -------------------------------------------------------------------------------- /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 | # Mysql 2 | 3 | This project involved learning how to configure database servers in a 4 | primary-replica model. I configured the two servers provided to me by 5 | Holberton School in a MySQL primary-replica setup with a dummy database, 6 | and wrote a Bash script to automate generation of database backups. 7 | 8 | ## Tasks :page_with_curl: 9 | 10 | * [4-mysql_configuration_primary](./4-mysql_configuration_primary): The MySQL 11 | `my.conf` configuration file used to set up my first server as a primary database 12 | server on the database `tyrell_corp`. 13 | 14 | * [4-mysql_configuration_replica](./4-mysql_configuration_replica): The MySQL 15 | `my.conf` configuration file used to set up my second server as the replica 16 | database server on the database `tyrell_corp`. 17 | 18 | * [5-mysql_backup](./5-mysql_backup): Bash script that generates a compressed 19 | `tar.gz` archive from a MySQL dump. 20 | * Usage: `./5-mysql_backup ` 21 | * Generates a dump containing all MySQL databases on the root server. 22 | * Names the resulting tar archive in the format `day-month-year.tar.gz`. 23 | -------------------------------------------------------------------------------- /0x15-api/0-gather_data_from_an_API.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Returns to-do list information for a given employee ID.""" 3 | import requests 4 | import sys 5 | 6 | if __name__ == "__main__": 7 | url = "https://jsonplaceholder.typicode.com/" 8 | user = requests.get(url + "users/{}".format(sys.argv[1])).json() 9 | todos = requests.get(url + "todos", params={"userId": sys.argv[1]}).json() 10 | 11 | completed = [t.get("title") for t in todos if t.get("completed") is True] 12 | print("Employee {} is done with tasks({}/{}):".format( 13 | user.get("name"), len(completed), len(todos))) 14 | [print("\t {}".format(c)) for c in completed] 15 | -------------------------------------------------------------------------------- /0x15-api/1-export_to_CSV.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Exports to-do list information for a given employee ID to CSV format.""" 3 | import csv 4 | import requests 5 | import sys 6 | 7 | if __name__ == "__main__": 8 | user_id = sys.argv[1] 9 | url = "https://jsonplaceholder.typicode.com/" 10 | user = requests.get(url + "users/{}".format(user_id)).json() 11 | username = user.get("username") 12 | todos = requests.get(url + "todos", params={"userId": user_id}).json() 13 | 14 | with open("{}.csv".format(user_id), "w", newline="") as csvfile: 15 | writer = csv.writer(csvfile, quoting=csv.QUOTE_ALL) 16 | [writer.writerow( 17 | [user_id, username, t.get("completed"), t.get("title")] 18 | ) for t in todos] 19 | -------------------------------------------------------------------------------- /0x15-api/2-export_to_JSON.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Exports to-do list information for a given employee ID to JSON format.""" 3 | import json 4 | import requests 5 | import sys 6 | 7 | if __name__ == "__main__": 8 | user_id = sys.argv[1] 9 | url = "https://jsonplaceholder.typicode.com/" 10 | user = requests.get(url + "users/{}".format(user_id)).json() 11 | username = user.get("username") 12 | todos = requests.get(url + "todos", params={"userId": user_id}).json() 13 | 14 | with open("{}.json".format(user_id), "w") as jsonfile: 15 | json.dump({user_id: [{ 16 | "task": t.get("title"), 17 | "completed": t.get("completed"), 18 | "username": username 19 | } for t in todos]}, jsonfile) 20 | -------------------------------------------------------------------------------- /0x15-api/3-dictionary_of_list_of_dictionaries.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Exports to-do list information of all employees to JSON format.""" 3 | import json 4 | import requests 5 | 6 | if __name__ == "__main__": 7 | url = "https://jsonplaceholder.typicode.com/" 8 | users = requests.get(url + "users").json() 9 | 10 | with open("todo_all_employees.json", "w") as jsonfile: 11 | json.dump({ 12 | u.get("id"): [{ 13 | "task": t.get("title"), 14 | "completed": t.get("completed"), 15 | "username": u.get("username") 16 | } for t in requests.get(url + "todos", 17 | params={"userId": u.get("id")}).json()] 18 | for u in users}, jsonfile) 19 | -------------------------------------------------------------------------------- /0x15-api/README.md: -------------------------------------------------------------------------------- 1 | # API 2 | 3 | This project was further practice in working with API's. I collected data from the 4 | [JSONPlaceholder REST API](https://jsonplaceholder.typicode.com/), and learned how 5 | to export it to either CSV or JSON format. 6 | 7 | ## Tasks :page_with_curl: 8 | 9 | * **0. Gather data from an API** 10 | * [0-gather_data_from_an_API.py](./0-gather_data_from_an_API.py): Python script 11 | that returns information on the to-do list progress of a given employee ID. 12 | * Usage: `python3 0-gather_data_from_an_API.py `. 13 | * Output: `Employee is done with tasks(<# completed tasks>/):` 14 | 15 | * **1. Export to CSV** 16 | * [1-export_to_CSV.py](./1-export_to_CSV.py): Python script exports to-do list 17 | information of a given employee ID to CSV format. 18 | * Usage: `python3 1-export_to_CSV.py ` 19 | * File name: `.csv`. 20 | * Format: `"","","",""`. 21 | 22 | * **2. Export to JSON** 23 | * [2-export_to_JSON.py](./2-export_to_JSON.py): Python script that exports 24 | to-do list information of a given employee ID to JSON format. 25 | * Usage: `python3 2-export_to_JSON.py ` 26 | * File name: `.json` 27 | * Format: `{ "": [ {"task": "", "completed": , "username": ""}}, ... ]}` 28 | 29 | * **3. Dictionary of list of dictionaries** 30 | * [3-dictionary_of_list_of_dictionaries.py](./3-dictionary_of_list_of_dictionaries.py): 31 | Python script that exports to-do list information for all employees to JSON format. 32 | * Usage: `python3 3-dictionary_of_list_of_dictionaries.py` 33 | * File name: `todo_all_employees.json` 34 | * Format: `{ "": [ {"username": "", "task": "", "completed": }, {"username": "", "task": "", "completed": }, ... ], "": [ {"username": "", "task": "", "completed": }, {"username": "", "task": "", "completed": }, ... ]}` 35 | -------------------------------------------------------------------------------- /0x16-api_advanced/0-subs.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Function to query subscribers on a given Reddit subreddit.""" 3 | import requests 4 | 5 | 6 | def number_of_subscribers(subreddit): 7 | """Return the total number of subscribers on a given subreddit.""" 8 | url = "https://www.reddit.com/r/{}/about.json".format(subreddit) 9 | headers = { 10 | "User-Agent": "linux:0x16.api.advanced:v1.0.0 (by /u/bdov_)" 11 | } 12 | response = requests.get(url, headers=headers, allow_redirects=False) 13 | if response.status_code == 404: 14 | return 0 15 | results = response.json().get("data") 16 | return results.get("subscribers") 17 | -------------------------------------------------------------------------------- /0x16-api_advanced/1-top_ten.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Function to print hot posts on a given Reddit subreddit.""" 3 | import requests 4 | 5 | 6 | def top_ten(subreddit): 7 | """Print the titles of the 10 hottest posts on a given subreddit.""" 8 | url = "https://www.reddit.com/r/{}/hot/.json".format(subreddit) 9 | headers = { 10 | "User-Agent": "linux:0x16.api.advanced:v1.0.0 (by /u/bdov_)" 11 | } 12 | params = { 13 | "limit": 10 14 | } 15 | response = requests.get(url, headers=headers, params=params, 16 | allow_redirects=False) 17 | if response.status_code == 404: 18 | print("None") 19 | return 20 | results = response.json().get("data") 21 | [print(c.get("data").get("title")) for c in results.get("children")] 22 | -------------------------------------------------------------------------------- /0x16-api_advanced/100-count.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Function to count words in all hot posts of a given Reddit subreddit.""" 3 | import requests 4 | 5 | 6 | def count_words(subreddit, word_list, instances={}, after="", count=0): 7 | """Prints counts of given words found in hot posts of a given subreddit. 8 | 9 | Args: 10 | subreddit (str): The subreddit to search. 11 | word_list (list): The list of words to search for in post titles. 12 | instances (obj): Key/value pairs of words/counts. 13 | after (str): The parameter for the next page of the API results. 14 | count (int): The parameter of results matched thus far. 15 | """ 16 | url = "https://www.reddit.com/r/{}/hot/.json".format(subreddit) 17 | headers = { 18 | "User-Agent": "linux:0x16.api.advanced:v1.0.0 (by /u/bdov_)" 19 | } 20 | params = { 21 | "after": after, 22 | "count": count, 23 | "limit": 100 24 | } 25 | response = requests.get(url, headers=headers, params=params, 26 | allow_redirects=False) 27 | try: 28 | results = response.json() 29 | if response.status_code == 404: 30 | raise Exception 31 | except Exception: 32 | print("") 33 | return 34 | 35 | results = results.get("data") 36 | after = results.get("after") 37 | count += results.get("dist") 38 | for c in results.get("children"): 39 | title = c.get("data").get("title").lower().split() 40 | for word in word_list: 41 | if word.lower() in title: 42 | times = len([t for t in title if t == word.lower()]) 43 | if instances.get(word) is None: 44 | instances[word] = times 45 | else: 46 | instances[word] += times 47 | 48 | if after is None: 49 | if len(instances) == 0: 50 | print("") 51 | return 52 | instances = sorted(instances.items(), key=lambda kv: (-kv[1], kv[0])) 53 | [print("{}: {}".format(k, v)) for k, v in instances] 54 | else: 55 | count_words(subreddit, word_list, instances, after, count) 56 | -------------------------------------------------------------------------------- /0x16-api_advanced/2-recurse.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Function to query a list of all hot posts on a given Reddit subreddit.""" 3 | import requests 4 | 5 | 6 | def recurse(subreddit, hot_list=[], after="", count=0): 7 | """Returns a list of titles of all hot posts on a given subreddit.""" 8 | url = "https://www.reddit.com/r/{}/hot/.json".format(subreddit) 9 | headers = { 10 | "User-Agent": "linux:0x16.api.advanced:v1.0.0 (by /u/bdov_)" 11 | } 12 | params = { 13 | "after": after, 14 | "count": count, 15 | "limit": 100 16 | } 17 | response = requests.get(url, headers=headers, params=params, 18 | allow_redirects=False) 19 | if response.status_code == 404: 20 | return None 21 | 22 | results = response.json().get("data") 23 | after = results.get("after") 24 | count += results.get("dist") 25 | for c in results.get("children"): 26 | hot_list.append(c.get("data").get("title")) 27 | 28 | if after is not None: 29 | return recurse(subreddit, hot_list, after, count) 30 | return hot_list 31 | -------------------------------------------------------------------------------- /0x16-api_advanced/README.md: -------------------------------------------------------------------------------- 1 | # API advanced 2 | 3 | I continued to practice querying API's in this advanced project, this time 4 | working with the Reddit API. 5 | 6 | ## Tests :heavy_check_mark: 7 | 8 | * [tests](./tests): Folder of test files for all tasks. Provided by Holberton 9 | School. 10 | 11 | ## Function Prototypes :floppy_disk: 12 | 13 | Prototypes for functions written in this project: 14 | 15 | | File | Prototype | 16 | | -------------- | --------------------------------------- | 17 | | `0-subs.py` | `def number_of_subscribers(subreddit)` | 18 | | `1-top_ten.py` | `def top_ten(subreddit)` | 19 | | `2-recurse.py` | `def recurse(subreddit, hot_list=[])` | 20 | | `100-count.py` | `def count_words(subreddit, word_list)` | 21 | 22 | ## Tasks :page_with_curl: 23 | 24 | * **0. How many subs?** 25 | * [0-subs.py](./0-subs.py): Python function that returns the total number of 26 | subscribers for a given subreddit. 27 | * Returns `0` if an invalid subreddit is given. 28 | 29 | * **1. Top Ten** 30 | * [1-top_ten.py](./1-top_ten.py): Python function that prints the top ten 31 | hottest posts for a given subreddit. 32 | * Prints `None` if an invalid subreddit is given. 33 | 34 | * **2. Recurse it!** 35 | * [2-recurse.py](./2-recurse.py): Python function that recursively returns a 36 | list of titles for all hot articles on a given subreddit. 37 | * Returns `None` if no results are found on the given subreddit. 38 | 39 | * **3. Count it!** 40 | * [100-count.py](./100-count.py): Python function that recursively prints a 41 | sorted count of given keywords parsed from titles of all hot articles on a given 42 | subreddit. 43 | * Keywords are case-insensitive and delimited by spaces. 44 | * Results are printed in descending order by count. 45 | * Words with identical counts are sorted alphabetically. 46 | * Words with no matches are skipped. 47 | * Results are based on the number of times a keyword appears - ie., 48 | `java java java` counts as three separate instances of `java`. 49 | -------------------------------------------------------------------------------- /0x16-api_advanced/tests/0-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | import sys 3 | 4 | 5 | if __name__ == '__main__': 6 | number_of_subscribers = __import__('0-subs').number_of_subscribers 7 | if len(sys.argv) < 2: 8 | print("Please pass an argument for the subreddit to search.") 9 | else: 10 | print("{:d}".format(number_of_subscribers(sys.argv[1]))) 11 | -------------------------------------------------------------------------------- /0x16-api_advanced/tests/1-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | import sys 3 | 4 | if __name__ == '__main__': 5 | top_ten = __import__('1-top_ten').top_ten 6 | if len(sys.argv) < 2: 7 | print("Please pass an argument for the subreddit to search.") 8 | else: 9 | top_ten(sys.argv[1]) 10 | -------------------------------------------------------------------------------- /0x16-api_advanced/tests/100-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | import sys 3 | 4 | if __name__ == '__main__': 5 | count_words = __import__('100-count').count_words 6 | if len(sys.argv) < 3: 7 | print("Usage: {} ".format(sys.argv[0])) 8 | print("Ex: {} programming 'python java javascript'".format(sys.argv[0])) 9 | else: 10 | result = count_words(sys.argv[1], [x for x in sys.argv[2].split()]) 11 | -------------------------------------------------------------------------------- /0x16-api_advanced/tests/2-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | import sys 3 | 4 | if __name__ == '__main__': 5 | recurse = __import__('2-recurse').recurse 6 | if len(sys.argv) < 2: 7 | print("Please pass an argument for the subreddit to search.") 8 | else: 9 | result = recurse(sys.argv[1]) 10 | if result is not None: 11 | print(len(result)) 12 | else: 13 | print("None") 14 | -------------------------------------------------------------------------------- /0x17-web_stack_debugging_3/0-strace_is_your_friend.pp: -------------------------------------------------------------------------------- 1 | # Fixes bad `phpp` extensions to `php` in the WordPress file `wp-settings.php`. 2 | 3 | exec { 'fix-wordpress': 4 | command => 'sed -i s/phpp/php/g /var/www/html/wp-settings.php', 5 | path => '/usr/local/bin/:/bin/' 6 | } 7 | -------------------------------------------------------------------------------- /0x17-web_stack_debugging_3/README.md: -------------------------------------------------------------------------------- 1 | # Web stack debugging #3 2 | 3 | This was the fourth in a series of web stack debugging projects. In these 4 | projects, I was given broken/bugged webstacks in isolated containers, 5 | and tasked with fixing the web stack to a working state. For each 6 | task, I wrote a script automating the commands necessary to fix the 7 | web stack. 8 | 9 | ## Tasks :page_with_curl: 10 | 11 | * **0. Strace is your friend** 12 | * [0-strace_is_your_friend.pp](./0-strace_is_your_friend.pp): Puppet manifest 13 | that fixes a typo error causing a WordPress application being served by an Apache 14 | web server to fail. 15 | * Usage: `puppet apply 0-strace_is_your_friend.pp` 16 | -------------------------------------------------------------------------------- /0x18-webstack_monitoring/0-monitor_your_nginx_traffic: -------------------------------------------------------------------------------- 1 | suMaSD0Wx3DPAZ 2 | 7RCGZINfJojNUWDfqFgR4LNPrWbfItz4AIWJFY4UbdyxJSqf3poffvSDItdXzHPK 3 | -------------------------------------------------------------------------------- /0x18-webstack_monitoring/README.md: -------------------------------------------------------------------------------- 1 | # Webstack monitoring 2 | 3 | This project invovled setting up Sumo Logic accounts to monitor server traffic 4 | on my three HolbertonBnB servers. 5 | 6 | ## Tasks :page_with_curl: 7 | 8 | * **0. Monitor your Nginx traffic** 9 | * [0-monitor_your_nginx_traffic](./0-monitor_your_nginx_traffic): Text file containing 10 | my Sumo Logic access key. 11 | * First line: `Access ID` 12 | * Second line: `Access Key` 13 | 14 | * **1. Monitor your server** 15 | * For this task, I configured Sumo Logic to monitor my server's memory, CPU, network 16 | and disk. 17 | -------------------------------------------------------------------------------- /0x19-postmortem/README.md: -------------------------------------------------------------------------------- 1 | # Postmortem 2 | 3 | Upon the release of Holberton School's System Engineering & DevOps project 0x19, 4 | approximately 00:07 Pacific Standard Time (PST), an outage occurred on an isolated 5 | Ubuntu 14.04 container running an Apache web server. GET requests on the server led to 6 | `500 Internal Server Error`'s, when the expected response was an HTML file defining a 7 | simple Holberton WordPress site. 8 | 9 | ## Debugging Process 10 | 11 | Bug debugger Brennan (BDB... as in my actual initials... made that up on the spot, pretty 12 | good, huh?) encountered the issue upon opening the project and being, well, instructed to 13 | address it, roughly 19:20 PST. He promptly proceeded to undergo solving the problem. 14 | 15 | 1. Checked running processes using `ps aux`. Two `apache2` processes - `root` and `www-data` - 16 | were properly running. 17 | 18 | 2. Looked in the `sites-available` folder of the `/etc/apache2/` directory. Determined that 19 | the web server was serving content located in `/var/www/html/`. 20 | 21 | 3. In one terminal, ran `strace` on the PID of the `root` Apache process. In another, curled 22 | the server. Expected great things... only to be disappointed. `strace` gave no useful 23 | information. 24 | 25 | 4. Repeated step 3, except on the PID of the `www-data` process. Kept expectations lower this 26 | time... but was rewarded! `strace` revelead an `-1 ENOENT (No such file or directory)` error 27 | occurring upon an attempt to access the file `/var/www/html/wp-includes/class-wp-locale.phpp`. 28 | 29 | 5. Looked through files in the `/var/www/html/` directory one-by-one, using Vim pattern 30 | matching to try and locate the erroneous `.phpp` file extension. Located it in the 31 | `wp-settings.php` file. (Line 137, `require_once( ABSPATH . WPINC . '/class-wp-locale.php' );`). 32 | 33 | 6. Removed the trailing `p` from the line. 34 | 35 | 7. Tested another `curl` on the server. 200 A-ok! 36 | 37 | 8. Wrote a Puppet manifest to automate fixing of the error. 38 | 39 | ## Summation 40 | 41 | In short, a typo. Gotta love'em. In full, the WordPress app was encountering a critical 42 | error in `wp-settings.php` when tyring to load the file `class-wp-locale.phpp`. The correct 43 | file name, located in the `wp-content` directory of the application folder, was 44 | `class-wp-locale.php`. 45 | 46 | Patch involved a simple fix on the typo, removing the trailing `p`. 47 | 48 | ## Prevention 49 | 50 | This outage was not a web server error, but an application error. To prevent such outages 51 | moving forward, please keep the following in mind. 52 | 53 | * Test! Test test test. Test the application before deploying. This error would have arisen 54 | and could have been addressed earlier had the app been tested. 55 | 56 | * Status monitoring. Enable some uptime-monitoring service such as 57 | [UptimeRobot](./https://uptimerobot.com/) to alert instantly upon outage of the website. 58 | 59 | Note that in response to this error, I wrote a Puppet manifest 60 | [0-strace_is_your_friend.pp](https://github.com/bdbaraban/holberton-system_engineering-devops/blob/master/0x17-web_stack_debugging_3/0-strace_is_your_friend.pp) 61 | to automate fixing of any such identitical errors should they occur in the future. The manifest 62 | replaces any `phpp` extensions in the file `/var/www/html/wp-settings.php` with `php`. 63 | 64 | But of course, it will never occur again, because we're programmers, and we never make 65 | errors! :wink: 66 | -------------------------------------------------------------------------------- /0x1A-application_server/2-app_server-nginx_config: -------------------------------------------------------------------------------- 1 | # Configures Nginx to serve the route /airbnb-onepage/ from AirBnB_clone_v2. 2 | 3 | server { 4 | # Listen on port 80 5 | listen 80 default_server; 6 | listen [::]:80 default_server ipv6only=on; 7 | 8 | # Use IP of server as domain name 9 | server_name 104.196.168.90; 10 | 11 | # Customize HTTP response header 12 | add_header X-Served-By 375-web-01; 13 | 14 | # Serve /airbnb-onepage/ route from AirBnB_clone_v2 15 | location = /airbnb-onepage/ { 16 | proxy_pass http://127.0.0.1:5000/airbnb-onepage/; 17 | } 18 | 19 | # 404 error page 20 | error_page 404 /404.html; 21 | location /404 { 22 | root /var/www/html; 23 | internal; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /0x1A-application_server/3-app_server-nginx_config: -------------------------------------------------------------------------------- 1 | # Configures Nginx to serve the /number_odd_or_even/ route on AirBnB_clone_v2. 2 | 3 | server { 4 | # Listen on port 80 5 | listen 80 default_server; 6 | listen [::]:80 default_server ipv6only=on; 7 | 8 | # Use server IP as domain name 9 | server_name 104.196.168.90; 10 | 11 | # Customize HTTP response header 12 | add_header X-Served-By 375-web-01; 13 | 14 | # Serve /airbnb-onepage/ route on AirBnB_clone_v2 15 | location = /airbnb-onepage/ { 16 | proxy_pass http://127.0.0.1:5000/airbnb-onepage/; 17 | } 18 | 19 | # Serve /number_odd_or_even/ route on AirBnB_clone_v2 20 | location ~ /airbnb-dynamic/number_odd_or_even/(\d+)$ { 21 | proxy_pass http://127.0.0.1:5001/number_odd_or_even/$1; 22 | } 23 | 24 | # 404 error page 25 | error_page 404 /404.html; 26 | location /404 { 27 | root /var/www/html; 28 | internal; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /0x1A-application_server/4-app_server-nginx_config: -------------------------------------------------------------------------------- 1 | # Configures Nginx to serve the AirBnB_clone_v3 API. 2 | 3 | server { 4 | # Listen on port 80 5 | listen 80 default_server; 6 | listen [::]:80 default_server ipv6only=on; 7 | 8 | # Use server IP as domain name 9 | server_name 104.196.168.90; 10 | 11 | # Customize HTTP response header 12 | add_header X-Served-By 375-web-01; 13 | 14 | # Serve /airbnb-onepage/ route on AirBnB_clone_v3 15 | location = /airbnb-onepage/ { 16 | proxy_pass http://127.0.0.1:5000/airbnb-onepage/; 17 | } 18 | 19 | # Serve /number_odd_or_even/ route on AirBnB_clone_v3 20 | location ~ /airbnb-dynamic/number_odd_or_even/(\d+)$ { 21 | proxy_pass http://127.0.0.1:5001/number_odd_or_even/$1; 22 | } 23 | 24 | # Serve API on AirBnB_clone_v3 25 | location /api { 26 | proxy_pass http://127.0.0.1:5002/api; 27 | } 28 | 29 | # 404 error page 30 | error_page 404 /404.html; 31 | location /404 { 32 | root /var/www/html; 33 | internal; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /0x1A-application_server/4-reload_gunicorn_no_downtime: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Gracefully reloads Gunicorn. 3 | 4 | ps aux | grep gunicorn | awk '{ print $2 }' | xargs kill -HUP 5 | -------------------------------------------------------------------------------- /0x1A-application_server/5-app_server-nginx_config: -------------------------------------------------------------------------------- 1 | # Configures Nginx to serve the complete AirBnB_clone_v4 application. 2 | 3 | server { 4 | # Listen on port 80. 5 | listen 80 default_server; 6 | listen [::]:80 default_server ipv6only=on; 7 | 8 | # Use server IP as domain name 9 | server_name 104.196.168.90; 10 | 11 | # Customize HTTP response header 12 | add_header X-Served-By 375-web-01; 13 | 14 | # Serve /airbnb-onepage/ route on AirBnB_clone_v2 15 | location = /airbnb-onepage/ { 16 | proxy_pass http://127.0.0.1:5000/airbnb-onepage/; 17 | } 18 | 19 | # Serve /number_odd_or_even/ route on AirBnB_clone_v2 20 | location ~ /airbnb-dynamic/number_odd_or_even/(\d+)$ { 21 | proxy_pass http://127.0.0.1:5001/number_odd_or_even/$1; 22 | } 23 | 24 | # Serve AirBnB_clone_v3 API 25 | location /api { 26 | proxy_pass http://127.0.0.1:5002/api; 27 | } 28 | 29 | # Configure /2-hbnb route of AirBnB_clone_v4 as root location 30 | location / { 31 | proxy_pass http://127.0.0.1:5003/2-hbnb; 32 | } 33 | 34 | # Serve static content for AirBnB_clone_v4 35 | location /static { 36 | proxy_pass http://127.0.0.1:5003; 37 | } 38 | 39 | # 404 error page 40 | error_page 404 /404.html; 41 | location /404 { 42 | root /var/www/html; 43 | internal; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /0x1A-application_server/README.md: -------------------------------------------------------------------------------- 1 | # Application server 2 | 3 | This was the application deployment project for our AirBnB clone. In this 4 | project, I configured Nginx on the web servers provided me by Holberton School 5 | to serve a WSGI Flask app running through Gunicorn. Additionally, I set up an 6 | Upstart script to keep the application running on server reboots. 7 | 8 | ## Tasks :page_with_curl: 9 | 10 | * **0. Set up development with Python** 11 | * In this task, I configured the file `web_flask/0-hello_route.py` from my 12 | [AirBnB_clone_v2](https://github.com/bdbaraban/AirBnB_clone_v2) to serve content 13 | on the route `/airbnb-onepage/`, running on port `5000`. 14 | 15 | * **1. Set up production with Gunicorn** 16 | * This task involved setting up a production environment, installing and configuring 17 | Gunicorn to serve the same file from task 0. 18 | 19 | * **2. Serve a page with Nginx** 20 | * [2-app_server-nginx_config](./2-app_server-nginx_config): Nginx configuration file 21 | proxying requests on the route `/airbnb-onepage/` to the Gunicorn app running on 22 | port `5000`. 23 | 24 | * **3. Add a route with query parameters** 25 | * [3-app_server-nginx_config](./3-app_server-nginx_config): Nginx configuration file 26 | proxying requests on the route `/airbnb-dynamic/number_odd_or_even/` to the 27 | Gunicorn app running on port `5000`. 28 | 29 | * **4. Let's do this for your API** 30 | * In this task, I configured the API from my [AirBnB_clone_v3](./https://github.com/Ostoyae/AirBnB_clone_v3) to run on Gunicorn. 31 | * [4-app_server-nginx_config](./4-app_server-nginx_config): Nginx configuration file 32 | that proxies requests on the AirBnB API to the corresponding Gunicorn app. 33 | 34 | * **5. Serve your AirBnB clone** 35 | * In this task, I configured the complete AirBnB app from [AirBnB_clone_v4](https://github.com/bdbaraban/AirBnB_clone_v4) to run on Gunicorn and be served through Nginx. 36 | * [5-app_server-nginx_config](./5-app_server-nginx_config): Nginx configuration file 37 | configured to serve the static assets from `web_dynamic/static/` on the Gunicorn AirBnB 38 | app. 39 | 40 | * **6. Deploy it** 41 | * [gunicorn.conf](./gunicorn.conf): Configuration file for an Upstart script that starts a 42 | Gunicorn process bounded to port 5003 that serves the content from task 5. 43 | * The Gunicorn process spawns three worker processes and logs errors to `/tmp/airbnb-error.log`, 44 | access to `/tmp/airbnb-access.log`. 45 | 46 | * **7. No service interruption** 47 | * [4-reload_gunicorn_no_downtime](./4-reload_gunicorn_no_downtime): Bash script that gracefully 48 | reloads Gunicorn. 49 | -------------------------------------------------------------------------------- /0x1A-application_server/gunicorn.conf: -------------------------------------------------------------------------------- 1 | description "Gunicorn application server running AirBnB_clone_v4" 2 | author "Brennan D Baraban" 3 | 4 | start on runlevel [2345] 5 | stop on runlevel [!2345] 6 | 7 | respawn 8 | setuid ubuntu 9 | setgid www-data 10 | 11 | chdir /home/ubuntu/AirBnB_clone_v4 12 | exec gunicorn --workers 3 --bind 0.0.0.0:5003 web_dynamic.2-hbnb:app >> /tmp/airbnb-access.log 2> /tmp/airbnb-error.logirbnb-access.log 13 | -------------------------------------------------------------------------------- /0x1B-web_stack_debugging_4/0-the_sky_is_the_limit_not.pp: -------------------------------------------------------------------------------- 1 | # Increases the amount of traffic an Nginx server can handle. 2 | 3 | # Increase the ULIMIT of the default file 4 | exec { 'fix--for-nginx': 5 | command => 'sed -i "s/15/4096/" /etc/default/nginx', 6 | path => '/usr/local/bin/:/bin/' 7 | } -> 8 | 9 | # Restart Nginx 10 | exec { 'nginx-restart': 11 | command => 'nginx restart', 12 | path => '/etc/init.d/' 13 | } 14 | -------------------------------------------------------------------------------- /0x1B-web_stack_debugging_4/1-user_limit.pp: -------------------------------------------------------------------------------- 1 | # Enable the user holberton to login and open files without error. 2 | 3 | # Increase hard file limit for Holberton user. 4 | exec { 'increase-hard-file-limit-for-holberton-user': 5 | command => 'sed -i "/holberton hard/s/5/50000/" /etc/security/limits.conf', 6 | path => '/usr/local/bin/:/bin/' 7 | } 8 | 9 | # Increase soft file limit for Holberton user. 10 | exec { 'increase-soft-file-limit-for-holberton-user': 11 | command => 'sed -i "/holberton soft/s/4/50000/" /etc/security/limits.conf', 12 | path => '/usr/local/bin/:/bin/' 13 | } 14 | -------------------------------------------------------------------------------- /0x1B-web_stack_debugging_4/README.md: -------------------------------------------------------------------------------- 1 | # Web stack debugging #4 2 | 3 | This was the fifth in a series of web stack debugging projects. In these 4 | projects, I was given broken/bugged webstacks in isolated containers, 5 | and tasked with fixing the web stack to a working state. For each 6 | task, I wrote a script automating the commands necessary to fix the 7 | web stack. 8 | 9 | ## Tasks :page_with_curl: 10 | 11 | * **0. Sky is the limit, let's bring that limit higher** 12 | * [0-the_sky_is_the_limit_not.pp](./0-the_sky_is_the_limit_not.pp): Puppet manifest 13 | that increases the amount of traffic an Apache web server can effectively handle. 14 | 15 | * **1. User limit** 16 | * [1-user_limit.pp](./1-user_limit.pp): Puppet manifest that changes the operating system 17 | configuration so that it is possible to login with the user `holberton` and open a file 18 | without error. 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # System Engineering and DevOps - Bash, Scripting, Web Stack/Web Stack Debugging, Networking & Security, CI/CD 2 | 3 | This repository contains programs written for the system engineering and DevOps 4 | track at Holberton School. In these projects, I worked with Bash and practiced 5 | writing Bash scripts to automate tasks. I learned about the OSI model and 6 | various Linux networking tools. Further, I configured a distributed system - 7 | two web servers and one load balancer - for deployment of my AirBnB project 8 | using Nginx, HAProxy, certbot, ufw, and MySQL. The specific list of projects 9 | contained follows: 10 | 11 | * [0x00. Shell, basics](./0x00-shell_basics) 12 | * [0x01. Shell, permissions](./0x01-shell_permissions) 13 | * [0x02. Shell, I/O Redirections and filters](./0x02-shell_redirections) 14 | * [0x03. Shell, init files, variables and expansions](./0x03-shell_variables_expansions) 15 | * [0x04. Loops, conditions and parsing](./0x04-loops_conditions_and_parsing) 16 | * [0x05. Processes and signals](./0x05-processes_and_signals) 17 | * [0x06. Regular expression](./0x06-regular_expressions) 18 | * [0x07. Networking basics #0](./0x07-networking_basics) 19 | * [0x08. Networking basics #1](./0x08-networking_basics_2) 20 | * [0x09. Web infrastructure design](./0x09-web_infrastructure_design) 21 | * [0x0A. SSH](./0x0A-ssh) 22 | * [0x0B. Web server](./0x0B-web_server) 23 | * [0x0C. Web stack debugging #0](./0x0C-web_stack_debugging_0) 24 | * [0x0D. Configuration management](./0x0D-configuration_management) 25 | * [0x0E. Web stack debugging #1](./0x0E-web_stack_debugging_1) 26 | * [0x10. HTTPS SSL](./0x10-https_ssl) 27 | * [0x11. What happens when you type holbertonschool.com in your browser and press Enter](./0x11-what_happens_when_your_type_holbertonschool_com_in_your_browser_and_press_enter) 28 | * [0x12. Web stack debugging #2](./0x12-web_stack_debugging_2) 29 | * [0x13. Firewall](./0x13-firewall) 30 | * [0x14. Mysql](./0x14-mysql) 31 | * [0x15. API](./0x15-api) 32 | * [0x16. API advanced](./0x16-api_advanced) 33 | * [0x17. Web stack debugging #3](./0x17-web_stack_debugging_3) 34 | * [0x18. Webstack monitoring](./0x18-webstack_monitoring) 35 | * [0x19. Postmortem](./0x19-postmortem) 36 | * [0x1A. Application server](./0x1A-application_server) 37 | * [0x1B. Web stack debugging #4](./0x1B-web_stack_debugging_4) 38 | * [Command Line for the Win](./command_line_for_the_win) 39 | 40 | ## Author :black_nib: 41 | 42 | * __Brennan D Baraban__ <[bdbaraban](https://github.com/bdbaraban)> 43 | 44 | ## Acknowledgements :pray: 45 | 46 | All work contained in this project was completed as part of the curriculum for 47 | Holberton School. Holberton School is a campus-based full-stack software 48 | engineering program that prepares students for careers in the tech industry 49 | using project-based peer learning. For more information, visit 50 | [this link](https://www.holbertonschool.com/). 51 | 52 |

53 | Holberton School logo 56 |

57 | -------------------------------------------------------------------------------- /command_line_for_the_win/0-first_9_tasks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdbaraban/holberton-system_engineering-devops/b91f70f6d78ce366709e0ebe9928663c6d0e2d5b/command_line_for_the_win/0-first_9_tasks.png -------------------------------------------------------------------------------- /command_line_for_the_win/1-next-9-tasks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdbaraban/holberton-system_engineering-devops/b91f70f6d78ce366709e0ebe9928663c6d0e2d5b/command_line_for_the_win/1-next-9-tasks.png -------------------------------------------------------------------------------- /command_line_for_the_win/2-last-9-tasks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdbaraban/holberton-system_engineering-devops/b91f70f6d78ce366709e0ebe9928663c6d0e2d5b/command_line_for_the_win/2-last-9-tasks.png -------------------------------------------------------------------------------- /command_line_for_the_win/README.md: -------------------------------------------------------------------------------- 1 | # Command Line for the Win 2 | 3 | For this project, I completed the [Commandline Challenge](https://cmdchallenge.com/). 4 | Each file is a PNG screenshot signifying my completion of all levels. 5 | --------------------------------------------------------------------------------