├── .gitignore ├── 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 └── iacta ├── 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-configuration_management ├── 0-create_a_file.pp ├── 1-install_a_package.pp ├── 2-execute_a_command.pp └── README.md ├── 0x0B-ssh ├── 0-use_a_private_key ├── 1-create_ssh_key_pair ├── 2-ssh_config ├── 4-puppet_ssh_config.pp └── README.md ├── 0x0C-web_server ├── 0-transfer_file ├── 1-install_nginx_web_server ├── 2-setup_a_domain_name ├── 3-redirection ├── 4-not_found_page_404 ├── 7-puppet_install_nginx_web_server.pp └── README.md ├── 0x0D-web_stack_debugging_0 ├── 0-give_me_a_page └── README.md ├── 0x0E-web_stack_debugging_1 ├── 0-nginx_likes_port_80 ├── 1-debugging_made_short └── README.md ├── 0x0F-load_balancer ├── 0-custom_http_response-header ├── 1-install_load_balancer ├── 2-puppet_custom_http_response-header.pp └── README.md ├── 0x10-https_ssl ├── 0-https_abc ├── 1-world_wide_web ├── 100-redirect_http_to_https ├── 2-haproxy_ssl_termination └── 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 ├── 0x17-web_stack_debugging_3 ├── 0-strace_is_your_friend.pp └── README.md ├── 0x18-webstack_monitoring ├── 0-setup_datadog ├── 2-setup_datadog └── README.md ├── 0x19-postmortem └── README.md ├── 0x1A-application_server ├── 2-app_server-nginx_config ├── 3-app_server-nginx_config ├── 4-app_server-nginx_config ├── 5-app_server-nginx_config └── README.md ├── 0x1B-web_stack_debugging_4 ├── 0-the_sky_is_the_limit_not.pp ├── 1-user_limit.pp └── README.md └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | #Emacs buffer 2 | *# 3 | *~ -------------------------------------------------------------------------------- /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 . .. /boot -la \ 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 -n *.html ..\ 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/15-lets_move: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | mv -t /tmp/u [[:upper:]]* \ 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 -am --file-type 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 -lan\ 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 | rm -rf /tmp/holberton\ 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/README.md: -------------------------------------------------------------------------------- 1 | # Shell, Basics 2 | 3 | Project done during **Full Stack Software Engineering studies** at **Holberton School**. It aims to learn about basics commands, navigation, files and directories in **Shell**. 4 | 5 | ## Technologies 6 | * Scripts written in Bash 4.3.11(1) 7 | * Tested on Ubuntu 14.04 LTS 8 | 9 | ## Files 10 | All of the following files are scripts, except `holberton.mgc`: 11 | 12 | | Filename | Description | 13 | | -------- | ----------- | 14 | | `0-current_working_directory` | Prints the absolute path name of the current working directory | 15 | | `1-listit` | Displays the content list of the current directory | 16 | | `2-bring_me_home` | Changes the working directory to the user's home directory | 17 | | `3-list_files` | Displays current directory contents in a long format | 18 | | `4-listmorefiles` | Displays, in the long format, current directory contents, including hidden files | 19 | | `5-listfilesdigitonly` | Displays current directory contents with user and group IDs | 20 | | `6-firstdirectory` | Creates a directory named `holberton` in the `/tmp/` directory | 21 | | `7-movethatfile` | Moves the file `betty` from `/tmp/` to `/tmp/holberton` | 22 | | `8-firstdelete` | Deletes the file `betty` | 23 | | `9-firstdirdeletion` | Deletes the directory `holberton` that is in the `/tmp` directory | 24 | | `10-back` | Changes the working directory to the previous one | 25 | | `11-lists` | Lists all files in the current directory and its parent directory and the `/boot` directory | 26 | | `12-file_type` | Prints the type of the file named `iamafile` that is in the `/tmp` directory | 27 | | `13-symbolic_link` | Creates a symbolic link to `/bin/ls`, named `__ls__` | 28 | | `14-copy_html` | Copies all the HTML files from the current working directory to the parent directory, but only copies files that did not exist in the parent directory | 29 | | `15-lets_move` | Moves all files beginning with an uppercase letter to the directory `/tmp/u` | 30 | | `16-clean_emacs` | Deletes all files in the current working directory that end with the character `~` | 31 | | `17-tree` | Creates the directories `welcome/`, `welcome/to/` and `welcome/to/holberton` in the current directory | 32 | | `18-commas` | Lists all the files and directories of the current directory, separated by commas (`,`) | 33 | | `holberton.mgc` | Magic file that can be used with the command `file` to detect `Holberton` data files. `Holberton` data files always contain the string `HOLBERTON` at offset 0 | 34 | -------------------------------------------------------------------------------- /0x00-shell_basics/holberton.mgc: -------------------------------------------------------------------------------- 1 | 0 string HOLBERTON Holberton data 2 | !:mime Holberton -------------------------------------------------------------------------------- /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 | find . -type d -exec chmod 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 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 -R --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 ugo+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 | Project done during **Full Stack Software Engineering studies** at **Holberton School**. It aims to learn about man pages, permissions (owner, group and other) of files and directories in **Shell**. 4 | 5 | ## Technologies 6 | * Scripts written in Bash 4.3.11(1) 7 | * Tested on Ubuntu 14.04 LTS 8 | 9 | ## Files 10 | All of the following files are scripts: 11 | 12 | | Filename | Description | 13 | | -------- | ----------- | 14 | | `0-iam_betty` | Changes your user ID to `betty` | 15 | | `1-who_am_i` | Prints the effective userid of the current user | 16 | | `2-groups` | Prints all the groups the current user is part of | 17 | | `3-new_owner` | Changes the owner of the file `hello` to the user `betty` | 18 | | `4-empty` | Creates an empty file called `hello` | 19 | | `5-execute` | Adds execute permission to the owner of the file `hello` | 20 | | `6-multiple_permissions` | Adds execute permission to the owner and the group owner, and reads permission to other users, to the file `hello` | 21 | | `7-everybody` | Adds execution permission to the owner, the group owner and the other users, to the file `hello` | 22 | | `8-James_Bond` | Write a script that sets the permission to the file `hello` to other users | 23 | | `9-John_Doe` | Sets the `-rwxr-x-wx` permissions to the file `hello` | 24 | | `10-mirror_permissions` | Sets the mode of the file `hello` the same as `olleh`'s mode | 25 | | `11-directories_permissions` | Adds execute permission to all subdirectories of the current directory for the owner, the group of the owner and all the other users | 26 | | `12-directory_permissions` | Creates a directory called `dir_holberton` with permissions 751 in the working directory | 27 | | `13-change_group` | Changes the group owner to `holberton` for the file `hello` | 28 | | `14-change_owner_and_group` | Changes the owner to `betty` and the group owner to `holberton` for all the files and directories in the working directory | 29 | | `15-symbolic_link_permissions` | Changes the owner and the group owner of the file `_hello` to `betty` and `holberton` respectively | 30 | | `16-if_only` | Changes the owner of the file `hello` to `betty` only if it is owned by the user `guillaume` | 31 | | `100-Star_Wars` | Plays the Star Wars IV episode in the terminal | 32 | | `101-man_holberton` | Man page | 33 | -------------------------------------------------------------------------------- /0x02-shell_redirections/0-hello_world: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "Hello, World" 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/1-confused_smiley: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "\"(Ôo)'" 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/10-no_more_js: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | find . -type f -name "*.js" -delete 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/100-empty_casks: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | find . -empty | rev | cut -d '/' -f 1 | rev 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/101-gifs: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | find -type f -name "*.gif" | rev | cut -d "/" -f 1 | cut -d '.' -f 2- | rev | LC_ALL=C sort -f 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/102-acrostic: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cut -c 1 | paste -s -d '' 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/103-the_biggest_fan: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | tail -n +2 | cut -f -1 | sort -k 1 | uniq -c | sort -rnk 1 | head -n 11 | rev | cut -d ' ' -f -1 | rev 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/11-directories: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | find . -type d -not -name '.' | wc -l 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/12-newest_files: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ls -t1 | head -n 10 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/13-unique: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | sort | uniq -u 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/14-findthatword: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | grep -i "root" /etc/passwd 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/15-countthatword: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | grep -c -i "bin" /etc/passwd 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/16-whatsnext: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | grep -i "root" -A 3 /etc/passwd 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/17-hidethisword: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | grep -i -v "bin" /etc/passwd 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/18-letteronly: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | grep -i "^[a-z]" /etc/ssh/sshd_config 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/19-AZ: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | tr "A" "Z" | tr "c" "e" 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/2-hellofile: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cat /etc/passwd 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/20-hiago: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | tr -d "cC" 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/21-reverse: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | rev 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/22-users_and_homes: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cut -d ':' -f 1,6 /etc/passwd | sort 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/3-twofiles: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cat /etc/passwd /etc/hosts 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/4-lastlines: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | tail -n 10 /etc/passwd 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/5-firstlines: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | head -n 10 /etc/passwd 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/6-third_line: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | head -n 3 iacta | tail -n 1 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/7-file: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "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 -n 1 iacta >> iacta 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/README.md: -------------------------------------------------------------------------------- 1 | # Shell, I/O Redirections and filters 2 | 3 | Project done during **Full Stack Software Engineering studies** at **Holberton School**. It aims to learn about how to handle standard input and output and how to combine commands and filters with redirections in **Shell**. 4 | 5 | ## Technologies 6 | * Scripts written in Bash 4.3.11(1) 7 | * Tested on Ubuntu 14.04 LTS 8 | 9 | ## Files 10 | All of the following files are scripts: 11 | 12 | | Filename | Description | 13 | | -------- | ----------- | 14 | | `0-hello_world` | Prints "Hello, World", followed by a new line to the standard output | 15 | | `1-confused_smiley` | Displays a confused smiley `"(Ôo)'` | 16 | | `2-hellofile` | Displays the content of the `/etc/passwd`file | 17 | | `3-twofiles` | Displays the content of `/etc/passwd` and `/etc/hosts` | 18 | | `4-lastlines` | Displays the last 10 lines of `/etc/passwd` | 19 | | `5-firstlines` | Displays the first 10 lines of `/etc/passwd` | 20 | | `6-third_line` | Displays the third line of the file `iacta` | 21 | | `7-file` | Creates a file named exactly `\*\\'"Holberton School"\'\\*$\?\*\*\*\*\*:)` containing the test `Holberton School` ending by a new line | 22 | | `8-cwd_state` | Writes into the file `ls_cwd_content` the result of the command `ls -la`. | 23 | | `9-duplicate_last_line` | Duplicates the last line of the file `iacta` | 24 | | `10-no_more_js` | Deletes all the regular files with a `.js` extension that are present in the current directory and all its subfolders | 25 | | `11-directories` | Counts the number of directories and sub-directories in the current directory | 26 | | `12-newest_files` | Displays the 10 newest files in the current directory | 27 | | `13-unique` | Takes a list of words as input and prints only words that appear exactly once | 28 | | `14-findthatword` | Displayes lines containing the pattern "root" from the file `/etc/passwd` | 29 | | `15-countthatword` | Displays the number of lines that contain the pattern "bin" in the file `/etc/passwd` | 30 | | `16-whatsnext` | Displays lines containing the patter "root" and 3 lines after them in the file `/etc/passwd` | 31 | | `17-hidethisword` | Displays all the lines in the file `/etc/passwd` that do not contain the pattern "bin" | 32 | | `18-letteronly` | Displays all lines of the file `/etc/ssh/sshd_config` starting with a letter | 33 | | `19-AZ` | Replaces all characters `A` and `c` from input to `Z` and `e` respectively | 34 | | `20-hiago` | Removes all letters `c` and `C` from input | 35 | | `21-reverse` | Reverses its input | 36 | | `22-users_and_homes` | Displays all users and their home directories, sorted by users | 37 | | `100-empty_casks` | Finds all empty files and directories in the current directory and all sub-directories | 38 | | `101-gifs` | Lists all the files with a `.gif` extension in the current directory and all its sub-directories | 39 | | `102-acrostic` | Decodes acrostics that use the first letter of each line | 40 | | `103-the_biggest_fan` | Parses web servers in TSV format as input and displays the 11 hosts or IP addresses which did the most requests | 41 | -------------------------------------------------------------------------------- /0x02-shell_redirections/iacta: -------------------------------------------------------------------------------- 1 | Alea iacta est 2 | 3 | Alea iacta est ("The die is cast") is a Latin phrase attributed by Suetonius 4 | (as iacta alea est) to Julius Caesar on January 10, 49 BC 5 | as he led his army across the Rubicon river in Northern Italy. With this step, 6 | he entered Italy at the head of his army in defiance of the Senate and began 7 | his long civil war against Pompey and the Optimates. The phrase has been 8 | adopted in Italian (Il dado è tratto), Romanian (Zarurile au fost aruncate), 9 | Spanish (La suerte está echada), French (Les dés sont jetés), Portuguese (A 10 | sorte está lançada), Dutch (De teerling is geworpen), 11 | German (Der Würfel ist gefallen), Hungarian (A kocka el van vetve) and many other languages to 12 | indicate that events have passed a point of no return. 13 | 14 | Read more: https://en.wikipedia.org/wiki/Alea_iacta_est -------------------------------------------------------------------------------- /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 `echo {a..z} | tr -d ' '` `echo {n..z} $(echo {a..m}) | tr -d ' '` | tr `echo {A..Z} | tr -d ' '` `echo {N..Z} $(echo {A..M}) | tr -d ' '` 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/101-odd: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | perl -lne 'print if $. % 2 == 1' 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/102-water_and_stir: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo $(printf %o $(($((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 | echo {a..z}{a..z} | tr " " "\n" | grep -v "oo" 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/13-print_float: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | printf "%.2f" $NUM | sort 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 | export PATH=$PATH:/action 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/3-paths: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo $((`echo $PATH | grep -o ":/" | wc -l`+ 1)) 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 | Project done during **Full Stack Software Engineering studies** at **Holberton School**. It aims to learn about alias builtin, help builtin, local, global and reserved variables (PATH, HOME and PS1), special parameters `$?` and single an double quotes in **Shell**. 4 | 5 | ## Technologies 6 | * Scripts written in Bash 4.3.11(1) 7 | * Tested on Ubuntu 14.04 LTS 8 | 9 | ## Files 10 | All of the following files are scripts: 11 | 12 | | Filename | Description | 13 | | -------- | ----------- | 14 | | `0-alias` | Creates an alias | 15 | | `1-hello_you` | Prints `hello user`, where user is the current Linux user | 16 | | `2-path` | Add `/action` to the `PATH`. `/action` should be the last directory the shell looks into when looking for a program | 17 | | `3-paths` | Counts the number of the directories in the `PATH` | 18 | | `4-global_variables` | Lists environment variables | 19 | | `5-local_variables` | Lists all local variables and environment variables, and functions | 20 | | `6-create_local_variable` | Creates a new local variable named `BETTY` | 21 | | `7-create_global_variable` | Creates a new global variable named `HOLBERTON` | 22 | | `8-true_knowledge` | Prints the result of the addition of 128 with the value stored in the environment variable `TRUEKNOWLEDGE`, followed by a new line | 23 | | `9-divide_and_rule` | Prints the result of `POWER` divided by `DIVIDE`, followed by a new line | 24 | | `10-love_exponent_breath` | Displays the result of `BREATH` to the power `LOVE` | 25 | | `11-binary_to_decimal` | Converts a number from base 2 to base 10 | 26 | | `12-combinations` | Prints all possible combinations of two letters, except `oo` | 27 | | `13-print_float` | Prints a number with two decimal places. The number is stored in the environment variable `NUM` | 28 | | `14-decimal_to_hexadecimal` | Converts a number from base 10 to base 16 | 29 | | `100-rot13` | Encodes and decodes text using the rot13 encryption | 30 | | `101-odd` | Prints every other line from the input, starting with the first line | 31 | | `102-water_and_str` | Adds the two numbers stored in the environment variables `WATER` and `STIR` and prints the result | 32 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/0-RSA_public_key.pub: -------------------------------------------------------------------------------- 1 | ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDBV9J4Zd4qw20TY7Id7xq9SCnpQwcR9ThavuW7Ox/Bu/FZjHFQkIBL9bBRmjb/dxK6RBYAgZI8vRrxaZfpz0DzIcGgV+eJXm1BXDFo4ixRGE+TTJARuZeuyxj5M7TzNmbiCVfBXmiWdwsK8ROjxP+WJlOaYydDHYRIG5CTB1SHYN0rLw/m6lIjONc0/eApSt0k1OJezG0kbufAFLUZr0S4AnTYVnGKfzWIZ+bDh2N1renKSwzn3Jd4A0NiQK8YdG/8Y+4Oxa0Ur+gP4p9+1dxt5e3Qph6N1jSgfJIyiurfwB5h5nzW9zQBIP9BMSuEuxY4YSn8LZGbYnt/MLKYCy0j vagrant@vagrant-ubuntu-trusty-64 2 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/1-for_holberton_school: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #Creating a script that uses a for loop 3 | for _ in {1..10} 4 | do 5 | echo "Holberton School" 6 | done 7 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/10-fizzbuzz: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #Program that prints FizzBuzz sequence 3 | for i in {1..100} 4 | do 5 | if [ $((i % 5)) -eq 0 -a $((i % 3)) -eq 0 ] 6 | then 7 | echo "FizzBuzz" 8 | elif [ $((i % 5)) -eq 0 ] 9 | then 10 | echo "Buzz" 11 | elif [ $((i % 3)) -eq 0 ] 12 | then 13 | echo "Fizz" 14 | else 15 | echo "$i" 16 | fi 17 | done 18 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/100-read_and_cut: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #Script that displays the content of the file /etc/passwd 3 | while IFS= read -r line 4 | do 5 | echo "$line" | cut -f 1,3,6 -d ':' 6 | done < "/etc/passwd" 7 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/101-tell_the_story_of_passwd: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #Script that displays the content of the file /etc/passwd 3 | while IFS= read -r line 4 | do 5 | username=$(echo "$line" | cut -f 1 -d ':') 6 | password=$(echo "$line" | cut -f 2 -d ':') 7 | userID=$(echo "$line" | cut -f 3 -d ':') 8 | groupID=$(echo "$line" | cut -f 4 -d ':') 9 | userINFO=$(echo "$line" | cut -f 5 -d ':') 10 | home=$(echo "$line" | cut -f 6 -d ':') 11 | command=$(echo "$line" | cut -f 7 -d ':') 12 | 13 | 14 | echo -n "The user $username is part of the $groupID gang, " 15 | echo -n "lives in $home and rides $command." 16 | echo -n " $userID's place is protected by the passcode $password, " 17 | echo "more info about the user here: $userINFO" 18 | done < "/etc/passwd" 19 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/102-lets_parse_apache_logs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #Script that parses Apache logs 3 | awk -F' ' '{ print $1 " " $9 }' apache-access.log 4 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/103-dig_the-data: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #Script that parses Apache logs 3 | awk -F' ' '{ print $1 " " $9 }' apache-access.log | sort | uniq -c | sort -nr 4 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/2-while_holberton_school: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #Creating a script that uses a while loop 3 | x=1 4 | while [ $x -le 10 ] 5 | do 6 | echo "Holberton School" 7 | x=$(( x + 1 )) 8 | done 9 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/3-until_holberton_school: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #Creating a script that uses an until loop 3 | x=0 4 | until [ $x -gt 9 ] 5 | do 6 | echo "Holberton School" 7 | ((x++)) 8 | done 9 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/4-if_9_say_hi: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #Creating a script that uses an if statement 3 | x=1 4 | while [ $x -le 10 ] 5 | do 6 | echo "Holberton School" 7 | if [ $x -eq 9 ] 8 | then 9 | echo "Hi" 10 | fi 11 | ((x++)) 12 | done 13 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/5-4_bad_luck_8_is_your_chance: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #Creating a script that uses if, else if and else statements 3 | x=1 4 | while [ $x -le 10 ] 5 | do 6 | if [ $x -eq 4 ] 7 | then 8 | echo "bad luck" 9 | elif [ $x -eq 8 ] 10 | then 11 | echo "good luck" 12 | else 13 | echo "Holberton School" 14 | fi 15 | ((x++)) 16 | done 17 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/6-superstitious_numbers: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #Creating a script that uses case statements 3 | x=1 4 | while [ $x -le 20 ] 5 | do 6 | echo "$x" 7 | case $x in 8 | 4) 9 | echo "bad luck from China" 10 | ;; 11 | 9) 12 | echo "bad luck from Japan" 13 | ;; 14 | 17) 15 | echo "bad luck from Italy" 16 | ;; 17 | esac 18 | ((x++)) 19 | done 20 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/7-clock: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #Creating a script that uses a nested loop 3 | hour=0 4 | while [ $hour -le 12 ] 5 | do 6 | echo "Hour: $hour" 7 | minutes=1 8 | while [ $minutes -lt 60 ] 9 | do 10 | echo "$minutes" 11 | ((minutes++)) 12 | done 13 | ((hour++)) 14 | done 15 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/8-for_ls: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #Creating a script that lists files 3 | for i in * 4 | do 5 | echo "$i" | cut -f 2- -d '-' 6 | done 7 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/9-to_file_or_not_to_file: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #Creating a script that uses nested if statements 3 | file="holbertonschool" 4 | if [ -e $file ] 5 | then 6 | echo "$file file exists" 7 | 8 | if [ -s $file ] 9 | then 10 | echo "$file file is not empty" 11 | else 12 | echo "$file file is empty" 13 | fi 14 | 15 | if [ -f $file ] 16 | then 17 | echo "$file is a regular file" 18 | fi 19 | else 20 | echo "$file file does not exist" 21 | fi 22 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/README.md: -------------------------------------------------------------------------------- 1 | # Loops, conditions and parsing 2 | 3 | Project done during **Full Stack Software Engineering studies** at **Holberton School**. It aims to learn about loops (`while`, `until` and `for`), condition statements (`if`, `else`, `elif` and `case`), shebangs and how to create SSH keys with **Bash**. 4 | 5 | ## Technologies 6 | * Scripts written in Bash 4.3.11(1) 7 | * Tested on Ubuntu 14.04 LTS 8 | 9 | ## Files 10 | 11 | | Filename | Description | 12 | | -------- | ----------- | 13 | | `0-RSA_public_key.pub` | File that stores a RSA public key to access servers via SSH | 14 | | `1-for_holberton_school` | Displays `Holberton School` 10 times with a `for` loop | 15 | | `2-while_holberton_school` | Displays `Holberton School` 10 times with a `while` loop | 16 | | `3-until_holberton_school` | Displays `Holberton School` 10 times with an `until` loop | 17 | | `4-if_9_say_hi` | Displays `Holberton School` 10 times and displays `Hi` for the 9th iteration | 18 | | `5-4_bad_luck_8_is_your_chance` | Loops from 1 to 10 and displays `Holberton School`, except for 4th and 8th iteration which displays `bad luck` and `good luck`, respectively | 19 | | `6-superstitious_numbers` | Displays numbers from 1 to 20 and displays `bad luck from China`, `bad luck from Japan` and `bad luck from Italy` for the 4th, 9th and 17th iteration, respectively | 20 | | `7-clock` | Displays the time for 12 hours and 59 minutes | 21 | | `8-for_ls` | Displays the content of the current directory in a list format | 22 | | `9-to_file_or_not_to_file` | Gives information about the `holbertonschool` file | 23 | | `10-fizzbuzz` | Displays the `fizzbuzz` sequence | 24 | | `100-read_and_cut` | Displays the content of the file `/etc/passwd` | 25 | | `101-tell_the_story_of_passwd` | Displays the content of the file `/etc/passwd` with an specific message | 26 | | `102-lets_parse_apache_logs` | Displays the visitor IP along with the HTTP status code from an Apache log file | 27 | | `103-dig_the-data` | Groups visitors by IP and HTTP status code and displays the occurrences, from the greatest to the lowest number | 28 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/0-what-is-my-pid: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #Bash script that prints the PID 3 | echo $$ -------------------------------------------------------------------------------- /0x05-processes_and_signals/1-list_your_processes: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #Bash script that displays a list of current processes 3 | ps -aux --forest 4 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/100-process_and_pid_file: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #Bash script that displays messages when read some signals 3 | echo $$ > /var/run/holbertonscript.pid 4 | trap 'echo "I hate the kill command"; rm -rf /var/run/holbertonscript.pid; exit' SIGTERM 5 | trap 'echo "Y U no love me?!"' SIGINT 6 | trap 'rm -rf /var/run/holbertonscript.pid; exit' SIGQUIT 7 | while : 8 | do 9 | echo "To infinity and beyond" 10 | sleep 2 11 | done 12 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/101-manage_my_process: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #Bash script that creates a subprocess 3 | . /lib/lsb/init-functions 4 | 5 | PIDFILE=/var/run/my_process.pid 6 | 7 | start() { 8 | ./manage_my_process & 9 | echo "$!" > "$PIDFILE" 10 | } 11 | 12 | stop() { 13 | sudo kill -15 "$(cat "$PIDFILE")" && rm -f "$PIDFILE" 14 | } 15 | 16 | case "$1" in 17 | start) 18 | start 19 | echo "manage_my_process started" 20 | ;; 21 | stop) 22 | stop 23 | echo "manage_my_process stopped" 24 | ;; 25 | restart) 26 | stop 27 | start 28 | echo "manage_my_process restarted" 29 | ;; 30 | *) 31 | echo "Usage: manage_my_process {start|stop|restart}" 32 | esac 33 | 34 | exit 0 35 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/102-zombie.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | /** 7 | * infinite_while - function that containts an infinite loop 8 | * 9 | * Return: 0 10 | */ 11 | int infinite_while(void) 12 | { 13 | while (1) 14 | { 15 | sleep(1); 16 | } 17 | return (0); 18 | } 19 | 20 | /** 21 | * main - Entry point 22 | * 23 | * Return: Always 0 24 | */ 25 | int main(void) 26 | { 27 | int i; 28 | 29 | for (i = 0; i < 5; i++) 30 | { 31 | if (fork() == 0) 32 | { 33 | dprintf(1, "Zombie process created, PID: %d\n", getpid()); 34 | return (0); 35 | } 36 | } 37 | infinite_while(); 38 | return (0); 39 | } 40 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/2-show_your_bash_pid: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #Bash script that displays a list of current processes 3 | # shellcheck disable=SC2009 4 | ps aux --forest | grep bash 5 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/3-show_your_bash_pid_made_easy: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #Bash script that displays the PID of processes whose name contain the word bash 3 | pgrep -l bash 4 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/4-to_infinity_and_beyond: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #Bash script that displays To infinity and beyond indefinitely 3 | while : 4 | do 5 | echo "To infinity and beyond" 6 | sleep 2 7 | done 8 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/5-kill_me_now: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #Bash script that kills a process 3 | pgrep -f 4-to_infinity_and_beyond | xargs kill -15 4 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/6-kill_me_now_made_easy: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #Bash script that kills a process 3 | pkill -f 4-to_infinity_and_beyond 4 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/7-highlander: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #Bash script that displays a message when it is terminated 3 | trap 'echo "I am invincible!!!"' SIGTERM 4 | while : 5 | do 6 | echo "To infinity and beyond" 7 | sleep 2 8 | done 9 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/8-beheaded_process: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #Bash script that kills a process 3 | pgrep -f 7-highlander | xargs kill -9 4 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/README.md: -------------------------------------------------------------------------------- 1 | # Processes and signals 2 | 3 | Project done during **Full Stack Software Engineering studies** at **Holberton School**. It aims to learn about PID, processes and commands that handles them (`ps`, `pgrep`, `pkill`, `kill`, etc) in **Bash**. 4 | 5 | ## Technologies 6 | * Scripts written in Bash 4.3.11(1) 7 | * Tested on Ubuntu 14.04 LTS 8 | 9 | ## Files 10 | 11 | | Filename | Description | 12 | | -------- | ----------- | 13 | | `0-what-is-my-pid` | Displays its own PID | 14 | | `1-list_your_processes` | Displays a list of currently running processes | 15 | | `2-show_your_bash_pid` | Displays lines contaning the `bash` word in a list of currently running processes | 16 | | `3-show_your_bash_pid_made_easy` | Displays the PID, along with the process name, of processes whose name contain the word `Bash` | 17 | | `4-to_infinity_and_beyond` | Displays `To infinity and beyond` indefinitely | 18 | | `5-kill_me_now` | Kills `4-to_infinity_and_beyond` process | 19 | | `6-kill_me_now_made_easy` | Kills `4-to_infinity_and_beyond` process | 20 | | `7-highlander` | Displays `To infinity and beyond` indefinitely and displays `I am invincible!!!` when receiving a `SIGTERM` signal | 21 | | `8-beheaded_process` | Kills the process `7-highlander` | 22 | | `100-process_and_pid_file` | Prints some messages according to sended signals | 23 | | `101-manage_my_process` | Init script that manages `manage_my_process` with `start`, `stop` and `restart` instructions | 24 | | `102-zombie.c` | C program that creates 5 zombie processes | 25 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/manage_my_process: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #Writes a message to a file 3 | while : 4 | do 5 | echo "I am alive!" >> /tmp/my_process 6 | sleep 2 7 | done 8 | -------------------------------------------------------------------------------- /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/luischaparroc/holberton-system_engineering-devops/a943b965346caaa9db19e33905efd223dfb12618/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?tn/).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}$/).join 3 | -------------------------------------------------------------------------------- /0x06-regular_expressions/7-OMG_WHY_ARE_YOU_SHOUTING.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | puts ARGV[0].scan(/[[:upper:]]/).join 3 | -------------------------------------------------------------------------------- /0x06-regular_expressions/README.md: -------------------------------------------------------------------------------- 1 | # Regular expression 2 | Project done during **Full Stack Software Engineering studies** at **Holberton School**. It aims to learn about how to build a regular expression. 3 | 4 | ## Technologies 5 | * Scripts written in Bash 4.3.11(1) 6 | * Tested on Ubuntu 14.04 LTS 7 | 8 | ## Files 9 | 10 | | Filename | Description | 11 | | -------- | ----------- | 12 | | `0-simply_match_holberton.rb` | A regular expression that matches `Holberton` | 13 | | `1-repetition_token_0.rb` | A regular expression that matches `hbttn` | 14 | | `2-repetition_token_1.rb` | A regular expression that matches `htn` and `hbtn` | 15 | | `3-repetition_token_2.rb` | A regular expression that matches `hbtn`, where the letter `t` can be replied | 16 | | `4-repetition_token_3.rb` | A regular expression that matches `hbtn` with or without `t` | 17 | | `5-beginning_and_end.rb` | A regular expression that matches with a word that starts with `h` and ends with `n` | 18 | | `6-phone_number.rb` | A regular expression that match with 10 digit phone number| 19 | | `7-OMG_WHY_ARE_YOU_SHOUTING.rb` | A regular expression that only matches capital letters | 20 | | `100-textme.rb` | Filters information of a log file | 21 | | `101-passed_linkedin_regex_challenge.jpg` | Result of Linkedin Regex Puzzle | 22 | -------------------------------------------------------------------------------- /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 | # Script that displays listening ports 3 | netstat -lp 4 | -------------------------------------------------------------------------------- /0x07-networking_basics/5-is_the_host_on_the_network: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Script 3 | if [ "$#" -lt "1" ] 4 | then 5 | echo "Usage: 5-is_the_host_on_the_network {IP_ADDRESS}" 6 | else 7 | ping "$1" -c 5 8 | fi 9 | -------------------------------------------------------------------------------- /0x07-networking_basics/README.md: -------------------------------------------------------------------------------- 1 | # Networking basics 2 | Project done during **Full Stack Software Engineering studies** at **Holberton School**. It aims to learn about what is an OSI model, LAN, WAN, IP address, localhost, subnet and TCP/UDP. 3 | 4 | ## Technologies 5 | * Scripts written in Bash 4.3.11(1) 6 | * Tested on Ubuntu 14.04 LTS 7 | 8 | ## Files 9 | 10 | | Filename | Description | 11 | | -------- | ----------- | 12 | | `0-OSI_model` | Answers of two questions related with OSI model | 13 | | `1-types_of_network` | Answers of three questions related with WAN and LAN | 14 | | `2-MAC_and_IP_address` | Answers of two questions related with MAC and IP address | 15 | | `3-UDP_and_TCP` | Answers of three questions related with TCP and UDP | 16 | | `4-TCP_and_UDP_ports` | Bash script that displays listening ports that only shows listening sockets | 17 | | `5-is_the_host_on_the_network` | Bash script that pings an IP address passed as an argument | 18 | -------------------------------------------------------------------------------- /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 | # Adds IP address to /etc/hosts 3 | cp /etc/hosts ~/hosts.new 4 | sed -i 's/127.0.0.1/127.0.0.2/' ~/hosts.new 5 | sed -i '2i8.8.8.8 facebook.com' ~/hosts.new 6 | cp -f ~/hosts.new /etc/hosts 7 | -------------------------------------------------------------------------------- /0x08-networking_basics_2/3-show_attached_IPs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Script that displays all active IPv4 IPs on the machine 3 | ifconfig | grep "inet addr:" | cut -d ':' -f 2- | cut -d ' ' -f 1 4 | -------------------------------------------------------------------------------- /0x08-networking_basics_2/4-port_listening_on_localhost: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Script that listens on port 98 on localhost 3 | nc -l 98 4 | -------------------------------------------------------------------------------- /0x08-networking_basics_2/README.md: -------------------------------------------------------------------------------- 1 | # Networking basics 1 2 | Project done during **Full Stack Software Engineering studies** at **Holberton School**. It aims to learn about what is localhost/127.0.0.1, what is 0.0.0.0, what is `/etc/hosts` and how to display the machine's active network interfaces. 3 | 4 | ## Technologies 5 | * Scripts written in Bash 4.3.11(1) 6 | * Tested on Ubuntu 14.04 LTS 7 | 8 | ## Files 9 | 10 | | Filename | Description | 11 | | -------- | ----------- | 12 | | `0-localhost` | Answer of a question related with `localhost` | 13 | | `1-wildcard` | Answer of a question related with `0.0.0.0` | 14 | | `2-change_your_home_IP` | Bash script that configures an Ubuntu server | 15 | | `3-show_attached_IPs` | Bash script that displays all active IPv4 IPs on the machine | 16 | | `4-port_listening_on_localhost` | Bash script that listens on port `98` on `localhost` | 17 | -------------------------------------------------------------------------------- /0x09-web_infrastructure_design/0-simple_web_stack: -------------------------------------------------------------------------------- 1 | https://imgur.com/a/JnoU2Pa -------------------------------------------------------------------------------- /0x09-web_infrastructure_design/1-distributed_web_infrastructure: -------------------------------------------------------------------------------- 1 | https://imgur.com/a/weoVU8j -------------------------------------------------------------------------------- /0x09-web_infrastructure_design/2-secured_and_monitored_web_infrastructure: -------------------------------------------------------------------------------- 1 | https://imgur.com/a/iYaSz5J -------------------------------------------------------------------------------- /0x09-web_infrastructure_design/3-scale_up: -------------------------------------------------------------------------------- 1 | https://imgur.com/a/Jk4lHdn -------------------------------------------------------------------------------- /0x09-web_infrastructure_design/README.md: -------------------------------------------------------------------------------- 1 | # Web infrastructure design 2 | 3 | Project done during **Full Stack Software Engineering studies** at **Holberton School**. It aims to learn about how to design a Web Infrastructure. 4 | 5 | ## Key concepts 6 | * Network basics 7 | * Server 8 | * Web server 9 | * Application server 10 | * DNS & DNS record types 11 | * Load Balancer 12 | * Monitoring 13 | * Database 14 | * Single point of failure 15 | * HTTP & HTTPS 16 | * Firewall 17 | 18 | ## Files 19 | 20 | | Filename | Description | 21 | | -------- | ----------- | 22 | | `0-simple_web_stack` | Web Infrastructure Design with a LAMP stack. This contains: 1 server, 1 web server, 1 application server, 1 database and 1 domain name | 23 | | `1-distributed_web_infrastructure` | Web Infrastructure Design, based on `0-simple_web_stack` that contains some additional components: 1 server, 1 web server, 1 application server, 1 load-balancer, 1 set of application files, 1 database | 24 | | `2-secured_and_monitored_web_infrastructure` | Web Infrastructure Design, based on `1-distributed_web_infrastructure` that contains some additional components: 3 firewalls, 1 SSL certificate, 3 monitoring clients | 25 | | `3-scale_up` | Web Infrastructure Design, based on `2-secured_and_monitored_web_infrastructure` that contains some additional components: 1 server, 1 load-balancer | 26 | -------------------------------------------------------------------------------- /0x0A-configuration_management/0-create_a_file.pp: -------------------------------------------------------------------------------- 1 | # Creates a file in /tmp 2 | 3 | file { '/tmp/holberton': 4 | ensure => file, 5 | path => '/tmp/holberton', 6 | mode => '0744', 7 | owner => 'www-data', 8 | group => 'www-data', 9 | content => 'I love Puppet' 10 | } -------------------------------------------------------------------------------- /0x0A-configuration_management/1-install_a_package.pp: -------------------------------------------------------------------------------- 1 | # Installs puppet-lint, version 2.1.1 2 | 3 | package { 'puppet-lint': 4 | ensure => '2.1.1', 5 | provider => 'gem', 6 | } 7 | -------------------------------------------------------------------------------- /0x0A-configuration_management/2-execute_a_command.pp: -------------------------------------------------------------------------------- 1 | # Kills a process name killmenow 2 | 3 | exec { 'pkill killmenow': 4 | path => '/usr/bin', 5 | command => 'pkill killmenow', 6 | provider => shell, 7 | returns => [0, 1] 8 | } -------------------------------------------------------------------------------- /0x0A-configuration_management/README.md: -------------------------------------------------------------------------------- 1 | # Configuration management 2 | Project done during **Full Stack Software Engineering studies** at **Holberton School**. It aims to learn about server configuration management using **Puppet**. 3 | 4 | ## Technologies 5 | * Scripts written in Bash 4.3.11(1) 6 | * Tested on Ubuntu 14.04 LTS 7 | * Puppet 3.8 8 | 9 | ## Files 10 | 11 | | Filename | Description | 12 | | -------- | ----------- | 13 | | `0-create_a_file.pp` | Create a file in `/tmp` | 14 | | `1-install_a_package.pp` | Install `puppet-lint` | 15 | | `2-execute_a_command.pp` | Create a manifest that kills a process named `killmenow` | 16 | -------------------------------------------------------------------------------- /0x0B-ssh/0-use_a_private_key: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Connecting to a server through a private key 3 | ssh -i ~/.ssh/holberton ubuntu@35.231.33.237 4 | -------------------------------------------------------------------------------- /0x0B-ssh/1-create_ssh_key_pair: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Creates an RSA key pair 3 | ssh-keygen -t rsa -f holberton -b 4096 -N betty 4 | -------------------------------------------------------------------------------- /0x0B-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 yes 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 | # Port 22 40 | # Protocol 2,1 41 | # Cipher 3des 42 | # Ciphers aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc 43 | # MACs hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160 44 | # EscapeChar ~ 45 | # Tunnel no 46 | # TunnelDevice any:any 47 | # PermitLocalCommand no 48 | # VisualHostKey no 49 | # ProxyCommand ssh -q -W %h:%p gateway.example.com 50 | # RekeyLimit 1G 1h 51 | SendEnv LANG LC_* 52 | HashKnownHosts yes 53 | GSSAPIAuthentication yes 54 | GSSAPIDelegateCredentials no 55 | IdentityFile ~/.ssh/holberton 56 | PasswordAuthentication no 57 | -------------------------------------------------------------------------------- /0x0B-ssh/4-puppet_ssh_config.pp: -------------------------------------------------------------------------------- 1 | # Changes SSH config file 2 | exec { 'echo': 3 | path => 'usr/bin:/bin', 4 | command => 'echo " IdentityFile ~/.ssh/holberton\n PasswordAuthentication no" >> /etc/ssh/ssh_config', 5 | returns => [0,1], 6 | } -------------------------------------------------------------------------------- /0x0B-ssh/README.md: -------------------------------------------------------------------------------- 1 | # SSH 2 | Project done during **Full Stack Software Engineering studies** at **Holberton School**. It aims to learn about what is a SSH, how to create an SSH RSA key pair and how to connect to a remote host using SSH. 3 | 4 | ## Technologies 5 | * Scripts written in Bash 4.3.11(1) 6 | * Tested on Ubuntu 14.04 LTS 7 | * Puppet 3.8 8 | 9 | ## Files 10 | 11 | | Filename | Description | 12 | | -------- | ----------- | 13 | | `0-use_a_private_key` | Uses `ssh` to connect to a server using a private key previously generated | 14 | | `1-create_ssh_key_pair` | Creates an RSA key pair | 15 | | `2-ssh_config` | SSH client configuration using a private key and refusing to authenticate using a password | 16 | | `4-puppet_ssh_config.pp` | Sets up the client SSH configuration file to connect to a server without typing a password | 17 | -------------------------------------------------------------------------------- /0x0C-web_server/0-transfer_file: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Transfers a file from a client to a server 3 | if [ "$#" -lt 3 ] 4 | then 5 | echo "Usage: 0-transfer_file PATH_TO_FILE IP USERNAME PATH_TO_SSH_KEY" 6 | elif [ "$#" -eq 3 ] 7 | then 8 | scp -o StrictHostKeyChecking=no "$1" "$3@$2:~/" 9 | else 10 | scp -o StrictHostKeyChecking=no -i "$4" "$1" "$3@$2:~/" 11 | fi 12 | -------------------------------------------------------------------------------- /0x0C-web_server/1-install_nginx_web_server: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Script that installs Nginx server 3 | apt-get -y update 4 | apt-get -y install nginx 5 | echo "Holberton School" > /var/www/html/index.nginx-debian.html 6 | service nginx start 7 | -------------------------------------------------------------------------------- /0x0C-web_server/2-setup_a_domain_name: -------------------------------------------------------------------------------- 1 | luisch.tech 2 | -------------------------------------------------------------------------------- /0x0C-web_server/3-redirection: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Script that installs Nginx server and redirects /redirect_me 3 | apt-get -y update 4 | apt-get -y install nginx 5 | echo "Holberton School" > /var/www/html/index.nginx-debian.html 6 | sed -i "s/server_name _;/server_name _;\n\trewrite ^\/redirect_me https:\/\/github.com\/luischaparroc permanent;/" /etc/nginx/sites-available/default 7 | service nginx start 8 | -------------------------------------------------------------------------------- /0x0C-web_server/4-not_found_page_404: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Script that installs Nginx server, redirects /redirect_me and customizes 404 not found 3 | apt-get -y update 4 | apt-get -y install nginx 5 | echo "Holberton School" > /var/www/html/index.nginx-debian.html 6 | echo "Ceci n'est pas une page" > /usr/share/nginx/html/custom_404.html 7 | sed -i "s/server_name _;/server_name _;\n\trewrite ^\/redirect_me https:\/\/github.com\/luischaparroc permanent;\n\n\terror_page 404 \/custom_404.html;\n\tlocation = \/custom_404.html {\n\t\troot \/usr\/share\/nginx\/html;\n\t\tinternal;\n\t}/" /etc/nginx/sites-available/default 8 | service nginx start 9 | -------------------------------------------------------------------------------- /0x0C-web_server/7-puppet_install_nginx_web_server.pp: -------------------------------------------------------------------------------- 1 | # Installs a Nginx server 2 | 3 | exec {'install': 4 | provider => shell, 5 | command => 'sudo apt-get -y update ; sudo apt-get -y install nginx ; echo "Holberton School" | sudo tee /var/www/html/index.nginx-debian.html ; sudo sed -i "s/server_name _;/server_name _;\n\trewrite ^\/redirect_me https:\/\/github.com\/luischaparroc permanent;/" /etc/nginx/sites-available/default ; sudo service nginx start', 6 | } 7 | -------------------------------------------------------------------------------- /0x0C-web_server/README.md: -------------------------------------------------------------------------------- 1 | # Web server 2 | Project done during **Full Stack Software Engineering studies** at **Holberton School**. It aims to learn about the roles of web servers and their processes (parent and child), and DNS roles. 3 | 4 | ## Technologies 5 | * Scripts written in Bash 4.3.11(1) 6 | * Tested on Ubuntu 14.04 LTS 7 | 8 | ## Files 9 | 10 | | Filename | Description | 11 | | -------- | ----------- | 12 | | `0-transfer_file` | Transfers a file from our client to a server | 13 | | `1-install_nginx_web_server` | Configures an Ubuntu machine to install NGINX web server | 14 | | `2-setup_a_domain_name` | Contains the domain name server of a created web site | 15 | | `3-redirection` | Configures an Ubuntu machine to make a redirection | 16 | | `4-not_found_page_404` | Configures a Ubuntu machine to have a custom 404 page | 17 | | `7-puppet_install_nginx_web_server.pp` | Configures a Ubuntu machine to make a redirection and a custom 404 page | 18 | -------------------------------------------------------------------------------- /0x0D-web_stack_debugging_0/0-give_me_a_page: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Script that turns on an Apache Server 3 | service apache2 start 4 | -------------------------------------------------------------------------------- /0x0D-web_stack_debugging_0/README.md: -------------------------------------------------------------------------------- 1 | # Web stack debugging 2 | Project done during **Full Stack Software Engineering studies** at **Holberton School**. It aims to learn about how to debug a webstack. 3 | 4 | ## Technologies 5 | * Scripts written in Bash 4.3.11(1) 6 | * Tested on Ubuntu 14.04 LTS 7 | 8 | ## Files 9 | 10 | | Filename | Description | 11 | | -------- | ----------- | 12 | | `0-give_me_a_page` | Turns on the Apache server | 13 | -------------------------------------------------------------------------------- /0x0E-web_stack_debugging_1/0-nginx_likes_port_80: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Script that sets the port 80 3 | sed -i "s/listen 8080 default_server;/listen 80 default_server;/" /etc/nginx/sites-enabled/default 4 | sed -i "s/listen \[::\]:8080 default_server ipv6only=on;/listen \[::\]:80 default_server;/" /etc/nginx/sites-enabled/default 5 | sed -i "s/ ipv6only=on//" /etc/nginx/sites-available/default 6 | service nginx restart 7 | -------------------------------------------------------------------------------- /0x0E-web_stack_debugging_1/1-debugging_made_short: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Script that sets the port 80 3 | sed -i "s/8080/80/g" /etc/nginx/sites-enabled/default 4 | service nginx restart 5 | kill -9 "$(cat /run/nginx.pid)" 6 | -------------------------------------------------------------------------------- /0x0E-web_stack_debugging_1/README.md: -------------------------------------------------------------------------------- 1 | # Web stack debugging 1 -------------------------------------------------------------------------------- /0x0F-load_balancer/0-custom_http_response-header: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Script that configures Nginx server with a custom header 3 | apt-get -y update 4 | apt-get -y install nginx 5 | echo "Holberton School" > /var/www/html/index.nginx-debian.html 6 | echo "Ceci n'est pas une page" > /usr/share/nginx/html/custom_404.html 7 | sed -i "s/server_name _;/server_name _;\n\trewrite ^\/redirect_me https:\/\/github.com\/luischaparroc permanent;\n\n\terror_page 404 \/custom_404.html;\n\tlocation = \/custom_404.html {\n\t\troot \/usr\/share\/nginx\/html;\n\t\tinternal;\n\t}/" /etc/nginx/sites-available/default 8 | sed -i "s/include \/etc\/nginx\/sites-enabled\/\*;/include \/etc\/nginx\/sites-enabled\/\*;\n\tadd_header X-Served-By \"$HOSTNAME\";/" /etc/nginx/nginx.conf 9 | service nginx start 10 | -------------------------------------------------------------------------------- /0x0F-load_balancer/1-install_load_balancer: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Script that configures HAproxy in a load balancer 3 | apt-get -y install software-properties-common 4 | add-apt-repository -y ppa:vbernat/haproxy-2.0 5 | apt-get -y update 6 | apt-get -y install haproxy=2.0.\* 7 | echo -e "\nfrontend http\n\tbind *:80\n\tmode http\n\tdefault_backend web-backend\n\nbackend web-backend\n\tbalance roundrobin\n\tserver 938-web-01 35.231.33.237:80 check\n\tserver 938-web-02 34.74.155.163:80 check" >> /etc/haproxy/haproxy.cfg 8 | service haproxy restart 9 | -------------------------------------------------------------------------------- /0x0F-load_balancer/2-puppet_custom_http_response-header.pp: -------------------------------------------------------------------------------- 1 | # Installs a Nginx server with custome HTTP header 2 | 3 | exec {'update': 4 | provider => shell, 5 | command => 'sudo apt-get -y update', 6 | before => Exec['install Nginx'], 7 | } 8 | 9 | exec {'install Nginx': 10 | provider => shell, 11 | command => 'sudo apt-get -y install nginx', 12 | before => Exec['add_header'], 13 | } 14 | 15 | exec { 'add_header': 16 | provider => shell, 17 | environment => ["HOST=${hostname}"], 18 | command => 'sudo sed -i "s/include \/etc\/nginx\/sites-enabled\/\*;/include \/etc\/nginx\/sites-enabled\/\*;\n\tadd_header X-Served-By \"$HOST\";/" /etc/nginx/nginx.conf', 19 | before => Exec['restart Nginx'], 20 | } 21 | 22 | exec { 'restart Nginx': 23 | provider => shell, 24 | command => 'sudo service nginx restart', 25 | } -------------------------------------------------------------------------------- /0x0F-load_balancer/README.md: -------------------------------------------------------------------------------- 1 | # Load Balancer -------------------------------------------------------------------------------- /0x10-https_ssl/0-https_abc: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 -------------------------------------------------------------------------------- /0x10-https_ssl/1-world_wide_web: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Script that displays information about subdomains. 3 | 4 | func () { 5 | if [ -n "$2" ] 6 | then 7 | dig "$2.$1" | grep -A1 'ANSWER SECTION:' | paste - - | awk -v sd="$2" '{print "The subdomain " sd " is a " $7 " record and points to " $8}' 8 | else 9 | dig "www.$1" | grep -A1 'ANSWER SECTION:' | paste - - | awk '{print "The subdomain www is a " $7 " record and points to " $8}' 10 | dig "lb-01.$1" | grep -A1 'ANSWER SECTION:' | paste - - | awk '{print "The subdomain lb-01 is a " $7 " record and points to " $8}' 11 | dig "web-01.$1" | grep -A1 'ANSWER SECTION:' | paste - - | awk '{print "The subdomain web-01 is a " $7 " record and points to " $8}' 12 | dig "web-02.$1" | grep -A1 'ANSWER SECTION:' | paste - - | awk '{print "The subdomain web-02 is a " $7 " record and points to " $8}' 13 | fi 14 | } 15 | 16 | func "$1" "$2" 17 | -------------------------------------------------------------------------------- /0x10-https_ssl/100-redirect_http_to_https: -------------------------------------------------------------------------------- 1 | global 2 | log /dev/log local0 3 | log /dev/log local1 notice 4 | chroot /var/lib/haproxy 5 | stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners 6 | stats timeout 30s 7 | user haproxy 8 | group haproxy 9 | daemon 10 | 11 | # Default SSL material locations 12 | ca-base /etc/ssl/certs 13 | crt-base /etc/ssl/private 14 | 15 | # Default ciphers to use on SSL-enabled listening sockets. 16 | # For more information, see ciphers(1SSL). This list is from: 17 | # https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/ 18 | # An alternative list with additional directives can be obtained from 19 | # https://mozilla.github.io/server-side-tls/ssl-config-generator/?server=haproxy 20 | ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:RSA+AESGCM:RSA+AES:!aNULL:!MD5:!DSS 21 | ssl-default-bind-options no-sslv3 22 | 23 | defaults 24 | log global 25 | mode http 26 | option httplog 27 | option dontlognull 28 | option forwardfor 29 | timeout connect 5000 30 | timeout client 50000 31 | timeout server 50000 32 | errorfile 400 /etc/haproxy/errors/400.http 33 | errorfile 403 /etc/haproxy/errors/403.http 34 | errorfile 408 /etc/haproxy/errors/408.http 35 | errorfile 500 /etc/haproxy/errors/500.http 36 | errorfile 502 /etc/haproxy/errors/502.http 37 | errorfile 503 /etc/haproxy/errors/503.http 38 | errorfile 504 /etc/haproxy/errors/504.http 39 | 40 | frontend http 41 | bind *:80 42 | http-request set-header X-Forwarded-Proto http 43 | default_backend web-backend 44 | 45 | frontend www-https 46 | bind *:443 ssl crt /etc/haproxy/ssl/www.luisch.tech.pem 47 | http-request set-header X-Forwarded-Proto https 48 | default_backend web-backend 49 | 50 | backend web-backend 51 | balance roundrobin 52 | redirect scheme https code 301 if !{ ssl_fc } 53 | server 938-web-01 35.231.33.237:80 check 54 | server 938-web-02 34.74.155.163:80 check 55 | -------------------------------------------------------------------------------- /0x10-https_ssl/2-haproxy_ssl_termination: -------------------------------------------------------------------------------- 1 | global 2 | log /dev/log local0 3 | log /dev/log local1 notice 4 | chroot /var/lib/haproxy 5 | stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners 6 | stats timeout 30s 7 | user haproxy 8 | group haproxy 9 | daemon 10 | 11 | # Default SSL material locations 12 | ca-base /etc/ssl/certs 13 | crt-base /etc/ssl/private 14 | 15 | # Default ciphers to use on SSL-enabled listening sockets. 16 | # For more information, see ciphers(1SSL). This list is from: 17 | # https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/ 18 | # An alternative list with additional directives can be obtained from 19 | # https://mozilla.github.io/server-side-tls/ssl-config-generator/?server=haproxy 20 | ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:RSA+AESGCM:RSA+AES:!aNULL:!MD5:!DSS 21 | ssl-default-bind-options no-sslv3 22 | 23 | defaults 24 | log global 25 | mode http 26 | option httplog 27 | option dontlognull 28 | option forwardfor 29 | timeout connect 5000 30 | timeout client 50000 31 | timeout server 50000 32 | errorfile 400 /etc/haproxy/errors/400.http 33 | errorfile 403 /etc/haproxy/errors/403.http 34 | errorfile 408 /etc/haproxy/errors/408.http 35 | errorfile 500 /etc/haproxy/errors/500.http 36 | errorfile 502 /etc/haproxy/errors/502.http 37 | errorfile 503 /etc/haproxy/errors/503.http 38 | errorfile 504 /etc/haproxy/errors/504.http 39 | 40 | frontend http 41 | bind *:80 42 | http-request set-header X-Forwarded-Proto http 43 | default_backend web-backend 44 | 45 | frontend www-https 46 | bind *:443 ssl crt /etc/haproxy/ssl/www.luisch.tech.pem 47 | http-request set-header X-Forwarded-Proto https 48 | default_backend web-backend 49 | 50 | backend web-backend 51 | balance roundrobin 52 | redirect scheme https if !{ ssl_fc } 53 | server 938-web-01 35.231.33.237:80 check 54 | server 938-web-02 34.74.155.163:80 check 55 | -------------------------------------------------------------------------------- /0x10-https_ssl/README.md: -------------------------------------------------------------------------------- 1 | # HTTPS SSL -------------------------------------------------------------------------------- /0x12-web_stack_debugging_2/0-iamsomeonelese: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Script that runs whoami command under an used passed 3 | sudo -u "$1" 'whoami' 4 | -------------------------------------------------------------------------------- /0x12-web_stack_debugging_2/1-run_nginx_as_nginx: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Script that starts nginx as nginx user 3 | chmod 777 /etc/nginx/nginx.conf 4 | sed -i "s/80/8080/g" /etc/nginx/sites-available/default 5 | sed -i "s/#user www-data/user nginx/" /etc/nginx/nginx.conf 6 | pkill -9 apache 7 | su nginx -c "service nginx restart" 8 | -------------------------------------------------------------------------------- /0x12-web_stack_debugging_2/100-fix_in_7_lines_or_less: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Script that starts nginx as nginx user 3 | chmod 777 /etc/nginx/nginx.conf 4 | chown nginx:nginx /etc/nginx/nginx.conf 5 | sed -i "s/80/8080/g" /etc/nginx/sites-available/default 6 | pkill -9 apache 7 | su nginx -c "service nginx restart" 8 | -------------------------------------------------------------------------------- /0x12-web_stack_debugging_2/README.md: -------------------------------------------------------------------------------- 1 | # Web stack debugging 2 -------------------------------------------------------------------------------- /0x13-firewall/0-firewall_ABC: -------------------------------------------------------------------------------- 1 | 2 2 | 3 3 | 1 4 | -------------------------------------------------------------------------------- /0x13-firewall/1-block_all_incoming_traffic_but: -------------------------------------------------------------------------------- 1 | sudo ufw enable 2 | sudo ufw allow 22/tcp 3 | sudo ufw allow 443/tcp 4 | sudo ufw allow 80/tcp 5 | -------------------------------------------------------------------------------- /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 | COMMIT 15 | 16 | # Don't delete these required lines, otherwise there will be errors 17 | *filter 18 | :ufw-before-input - [0:0] 19 | :ufw-before-output - [0:0] 20 | :ufw-before-forward - [0:0] 21 | :ufw-not-local - [0:0] 22 | # End required lines 23 | 24 | 25 | # allow all on loopback 26 | -A ufw-before-input -i lo -j ACCEPT 27 | -A ufw-before-output -o lo -j ACCEPT 28 | 29 | # quickly process packets for which we already have a connection 30 | -A ufw-before-input -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT 31 | -A ufw-before-output -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT 32 | -A ufw-before-forward -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT 33 | 34 | # drop INVALID packets (logs these in loglevel medium and higher) 35 | -A ufw-before-input -m conntrack --ctstate INVALID -j ufw-logging-deny 36 | -A ufw-before-input -m conntrack --ctstate INVALID -j DROP 37 | 38 | # ok icmp codes for INPUT 39 | -A ufw-before-input -p icmp --icmp-type destination-unreachable -j ACCEPT 40 | -A ufw-before-input -p icmp --icmp-type source-quench -j ACCEPT 41 | -A ufw-before-input -p icmp --icmp-type time-exceeded -j ACCEPT 42 | -A ufw-before-input -p icmp --icmp-type parameter-problem -j ACCEPT 43 | -A ufw-before-input -p icmp --icmp-type echo-request -j ACCEPT 44 | 45 | # ok icmp code for FORWARD 46 | -A ufw-before-forward -p icmp --icmp-type destination-unreachable -j ACCEPT 47 | -A ufw-before-forward -p icmp --icmp-type source-quench -j ACCEPT 48 | -A ufw-before-forward -p icmp --icmp-type time-exceeded -j ACCEPT 49 | -A ufw-before-forward -p icmp --icmp-type parameter-problem -j ACCEPT 50 | -A ufw-before-forward -p icmp --icmp-type echo-request -j ACCEPT 51 | 52 | # allow dhcp client to work 53 | -A ufw-before-input -p udp --sport 67 --dport 68 -j ACCEPT 54 | 55 | # 56 | # ufw-not-local 57 | # 58 | -A ufw-before-input -j ufw-not-local 59 | 60 | # if LOCAL, RETURN 61 | -A ufw-not-local -m addrtype --dst-type LOCAL -j RETURN 62 | 63 | # if MULTICAST, RETURN 64 | -A ufw-not-local -m addrtype --dst-type MULTICAST -j RETURN 65 | 66 | # if BROADCAST, RETURN 67 | -A ufw-not-local -m addrtype --dst-type BROADCAST -j RETURN 68 | 69 | # all other non-local packets are dropped 70 | -A ufw-not-local -m limit --limit 3/min --limit-burst 10 -j ufw-logging-deny 71 | -A ufw-not-local -j DROP 72 | 73 | # allow MULTICAST mDNS for service discovery (be sure the MULTICAST line above 74 | # is uncommented) 75 | -A ufw-before-input -p udp -d 224.0.0.251 --dport 5353 -j ACCEPT 76 | 77 | # allow MULTICAST UPnP for service discovery (be sure the MULTICAST line above 78 | # is uncommented) 79 | -A ufw-before-input -p udp -d 239.255.255.250 --dport 1900 -j ACCEPT 80 | 81 | # don't delete the 'COMMIT' line or these rules won't be processed 82 | COMMIT 83 | -------------------------------------------------------------------------------- /0x13-firewall/README.md: -------------------------------------------------------------------------------- 1 | # Firewall -------------------------------------------------------------------------------- /0x14-mysql/4-mysql_configuration_primary: -------------------------------------------------------------------------------- 1 | # 2 | # The MySQL database server configuration file. 3 | # 4 | # You can copy this to one of: 5 | # - "/etc/mysql/my.cnf" to set global options, 6 | # - "~/.my.cnf" to set user-specific options. 7 | # 8 | # One can use all long options that the program supports. 9 | # Run program with --help to get a list of available options and with 10 | # --print-defaults to see which it would actually understand and use. 11 | # 12 | # For explanations see 13 | # http://dev.mysql.com/doc/mysql/en/server-system-variables.html 14 | 15 | # 16 | # * IMPORTANT: Additional settings that can override those from this file! 17 | # The files must end with '.cnf', otherwise they'll be ignored. 18 | # 19 | 20 | !includedir /etc/mysql/conf.d/ 21 | !includedir /etc/mysql/mysql.conf.d/ 22 | 23 | [mysqld] 24 | 25 | server-id = 1 26 | log_bin = /var/log/mysql/mysql-bin.log 27 | binlog_do_db = tyrell_corp 28 | -------------------------------------------------------------------------------- /0x14-mysql/4-mysql_configuration_replica: -------------------------------------------------------------------------------- 1 | # 2 | # The MySQL database server configuration file. 3 | # 4 | # You can copy this to one of: 5 | # - "/etc/mysql/my.cnf" to set global options, 6 | # - "~/.my.cnf" to set user-specific options. 7 | # 8 | # One can use all long options that the program supports. 9 | # Run program with --help to get a list of available options and with 10 | # --print-defaults to see which it would actually understand and use. 11 | # 12 | # For explanations see 13 | # http://dev.mysql.com/doc/mysql/en/server-system-variables.html 14 | 15 | # 16 | # * IMPORTANT: Additional settings that can override those from this file! 17 | # The files must end with '.cnf', otherwise they'll be ignored. 18 | # 19 | 20 | !includedir /etc/mysql/conf.d/ 21 | !includedir /etc/mysql/mysql.conf.d/ 22 | 23 | [mysqld] 24 | server-id = 2 25 | relay-log = /var/log/mysql/mysql-relay-bin.log 26 | log_bin = /var/log/mysql/mysql-bin.log 27 | binlog_do_db = tyrell_corp 28 | -------------------------------------------------------------------------------- /0x14-mysql/5-mysql_backup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Script that compress a SQL dump 3 | mysqldump --all-databases -u root -p"$1" > backup.sql 4 | tar -czvf "$(date '+%d-%m-%Y').tar.gz" backup.sql 5 | -------------------------------------------------------------------------------- /0x14-mysql/README.md: -------------------------------------------------------------------------------- 1 | # MySQL -------------------------------------------------------------------------------- /0x15-api/0-gather_data_from_an_API.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ Script that uses JSONPlaceholder API to get information about employee """ 3 | import requests 4 | import sys 5 | 6 | 7 | if __name__ == "__main__": 8 | url = 'https://jsonplaceholder.typicode.com/' 9 | 10 | user = '{}users/{}'.format(url, sys.argv[1]) 11 | res = requests.get(user) 12 | json_o = res.json() 13 | print("Employee {} is done with tasks".format(json_o.get('name')), end="") 14 | 15 | todos = '{}todos?userId={}'.format(url, sys.argv[1]) 16 | res = requests.get(todos) 17 | tasks = res.json() 18 | l_task = [] 19 | for task in tasks: 20 | if task.get('completed') is True: 21 | l_task.append(task) 22 | 23 | print("({}/{}):".format(len(l_task), len(tasks))) 24 | for task in l_task: 25 | print("\t {}".format(task.get("title"))) 26 | -------------------------------------------------------------------------------- /0x15-api/1-export_to_CSV.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ Script that uses JSONPlaceholder API to get information about employee """ 3 | import csv 4 | import requests 5 | import sys 6 | 7 | 8 | if __name__ == "__main__": 9 | url = 'https://jsonplaceholder.typicode.com/' 10 | 11 | userid = sys.argv[1] 12 | user = '{}users/{}'.format(url, userid) 13 | res = requests.get(user) 14 | json_o = res.json() 15 | name = json_o.get('username') 16 | 17 | todos = '{}todos?userId={}'.format(url, userid) 18 | res = requests.get(todos) 19 | tasks = res.json() 20 | l_task = [] 21 | for task in tasks: 22 | l_task.append([userid, 23 | name, 24 | task.get('completed'), 25 | task.get('title')]) 26 | 27 | filename = '{}.csv'.format(userid) 28 | with open(filename, mode='w') as employee_file: 29 | employee_writer = csv.writer(employee_file, 30 | delimiter=',', 31 | quotechar='"', 32 | quoting=csv.QUOTE_ALL) 33 | for task in l_task: 34 | employee_writer.writerow(task) 35 | -------------------------------------------------------------------------------- /0x15-api/2-export_to_JSON.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ Script that uses JSONPlaceholder API to get information about employee """ 3 | import json 4 | import requests 5 | import sys 6 | 7 | 8 | if __name__ == "__main__": 9 | url = 'https://jsonplaceholder.typicode.com/' 10 | 11 | userid = sys.argv[1] 12 | user = '{}users/{}'.format(url, userid) 13 | res = requests.get(user) 14 | json_o = res.json() 15 | name = json_o.get('username') 16 | 17 | todos = '{}todos?userId={}'.format(url, userid) 18 | res = requests.get(todos) 19 | tasks = res.json() 20 | l_task = [] 21 | for task in tasks: 22 | dict_task = {"task": task.get('title'), 23 | "completed": task.get('completed'), 24 | "username": name} 25 | l_task.append(dict_task) 26 | 27 | d_task = {str(userid): l_task} 28 | filename = '{}.json'.format(userid) 29 | with open(filename, mode='w') as f: 30 | json.dump(d_task, f) 31 | -------------------------------------------------------------------------------- /0x15-api/3-dictionary_of_list_of_dictionaries.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ Script that uses JSONPlaceholder API to get information about employee """ 3 | import json 4 | import requests 5 | import sys 6 | 7 | 8 | if __name__ == "__main__": 9 | url = 'https://jsonplaceholder.typicode.com/' 10 | user = '{}users'.format(url) 11 | res = requests.get(user) 12 | json_o = res.json() 13 | d_task = {} 14 | for user in json_o: 15 | name = user.get('username') 16 | userid = user.get('id') 17 | todos = '{}todos?userId={}'.format(url, userid) 18 | res = requests.get(todos) 19 | tasks = res.json() 20 | l_task = [] 21 | for task in tasks: 22 | dict_task = {"username": name, 23 | "task": task.get('title'), 24 | "completed": task.get('completed')} 25 | l_task.append(dict_task) 26 | 27 | d_task[str(userid)] = l_task 28 | filename = 'todo_all_employees.json' 29 | with open(filename, mode='w') as f: 30 | json.dump(d_task, f) 31 | -------------------------------------------------------------------------------- /0x15-api/README.md: -------------------------------------------------------------------------------- 1 | # API -------------------------------------------------------------------------------- /0x16-api_advanced/0-subs.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 3 | Function that queries the Reddit API and returns 4 | the number of subscribers for a given subreddit. 5 | """ 6 | import requests 7 | import sys 8 | 9 | 10 | def number_of_subscribers(subreddit): 11 | """ Queries to Reddit API """ 12 | u_agent = 'Mozilla/5.0' 13 | 14 | headers = { 15 | 'User-Agent': u_agent 16 | } 17 | 18 | url = "https://www.reddit.com/r/{}/about.json".format(subreddit) 19 | res = requests.get(url, headers=headers, allow_redirects=False) 20 | if res.status_code != 200: 21 | return 0 22 | dic = res.json() 23 | if 'data' not in dic: 24 | return 0 25 | if 'subscribers' not in dic.get('data'): 26 | return 0 27 | return res.json()['data']['subscribers'] 28 | -------------------------------------------------------------------------------- /0x16-api_advanced/1-top_ten.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 3 | Function that queries the Reddit API and prints 4 | the top ten hot posts of a subreddit 5 | """ 6 | import requests 7 | import sys 8 | 9 | 10 | def top_ten(subreddit): 11 | """ Queries to Reddit API """ 12 | u_agent = 'Mozilla/5.0' 13 | 14 | headers = { 15 | 'User-Agent': u_agent 16 | } 17 | 18 | params = { 19 | 'limit': 10 20 | } 21 | 22 | url = "https://www.reddit.com/r/{}/hot.json".format(subreddit) 23 | res = requests.get(url, 24 | headers=headers, 25 | params=params, 26 | allow_redirects=False) 27 | if res.status_code != 200: 28 | print(None) 29 | return 30 | dic = res.json() 31 | hot_posts = dic['data']['children'] 32 | if len(hot_posts) is 0: 33 | print(None) 34 | else: 35 | for post in hot_posts: 36 | print(post['data']['title']) 37 | -------------------------------------------------------------------------------- /0x16-api_advanced/100-count.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 3 | Function that queries the Reddit API and prints 4 | the top ten hot posts of a subreddit 5 | """ 6 | import re 7 | import requests 8 | import sys 9 | 10 | 11 | def add_title(dictionary, hot_posts): 12 | """ Adds item into a list """ 13 | if len(hot_posts) == 0: 14 | return 15 | 16 | title = hot_posts[0]['data']['title'].split() 17 | for word in title: 18 | for key in dictionary.keys(): 19 | c = re.compile("^{}$".format(key), re.I) 20 | if c.findall(word): 21 | dictionary[key] += 1 22 | hot_posts.pop(0) 23 | add_title(dictionary, hot_posts) 24 | 25 | 26 | def recurse(subreddit, dictionary, after=None): 27 | """ Queries to Reddit API """ 28 | u_agent = 'Mozilla/5.0' 29 | headers = { 30 | 'User-Agent': u_agent 31 | } 32 | 33 | params = { 34 | 'after': after 35 | } 36 | 37 | url = "https://www.reddit.com/r/{}/hot.json".format(subreddit) 38 | res = requests.get(url, 39 | headers=headers, 40 | params=params, 41 | allow_redirects=False) 42 | 43 | if res.status_code != 200: 44 | return None 45 | 46 | dic = res.json() 47 | hot_posts = dic['data']['children'] 48 | add_title(dictionary, hot_posts) 49 | after = dic['data']['after'] 50 | if not after: 51 | return 52 | recurse(subreddit, dictionary, after=after) 53 | 54 | 55 | def count_words(subreddit, word_list): 56 | """ Init function """ 57 | dictionary = {} 58 | 59 | for word in word_list: 60 | dictionary[word] = 0 61 | 62 | recurse(subreddit, dictionary) 63 | 64 | l = sorted(dictionary.items(), key=lambda kv: kv[1]) 65 | l.reverse() 66 | 67 | if len(l) != 0: 68 | for item in l: 69 | if item[1] is not 0: 70 | print("{}: {}".format(item[0], item[1])) 71 | else: 72 | print("") 73 | -------------------------------------------------------------------------------- /0x16-api_advanced/2-recurse.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 3 | Function that queries the Reddit API and prints 4 | the top ten hot posts of a subreddit 5 | """ 6 | import requests 7 | import sys 8 | 9 | 10 | def add_title(hot_list, hot_posts): 11 | """ Adds item into a list """ 12 | if len(hot_posts) == 0: 13 | return 14 | hot_list.append(hot_posts[0]['data']['title']) 15 | hot_posts.pop(0) 16 | add_title(hot_list, hot_posts) 17 | 18 | 19 | def recurse(subreddit, hot_list=[], after=None): 20 | """ Queries to Reddit API """ 21 | u_agent = 'Mozilla/5.0' 22 | headers = { 23 | 'User-Agent': u_agent 24 | } 25 | 26 | params = { 27 | 'after': after 28 | } 29 | 30 | url = "https://www.reddit.com/r/{}/hot.json".format(subreddit) 31 | res = requests.get(url, 32 | headers=headers, 33 | params=params, 34 | allow_redirects=False) 35 | 36 | if res.status_code != 200: 37 | return None 38 | 39 | dic = res.json() 40 | hot_posts = dic['data']['children'] 41 | add_title(hot_list, hot_posts) 42 | after = dic['data']['after'] 43 | if not after: 44 | return hot_list 45 | return recurse(subreddit, hot_list=hot_list, after=after) 46 | -------------------------------------------------------------------------------- /0x16-api_advanced/README.md: -------------------------------------------------------------------------------- 1 | # API advanced -------------------------------------------------------------------------------- /0x17-web_stack_debugging_3/0-strace_is_your_friend.pp: -------------------------------------------------------------------------------- 1 | # Fix 500 error when a GET HTTP method is requested to Apache web server 2 | 3 | exec {'replace': 4 | provider => shell, 5 | command => 'sed -i "s/phpp/php/g" /var/www/html/wp-settings.php' 6 | } -------------------------------------------------------------------------------- /0x17-web_stack_debugging_3/README.md: -------------------------------------------------------------------------------- 1 | # Web stack debugging #3 -------------------------------------------------------------------------------- /0x18-webstack_monitoring/0-setup_datadog: -------------------------------------------------------------------------------- 1 | 6c1392aa3f8609a7062e14f94d2fae2c 2 | d0b38147de661f7575781a0460874c94b156a954 -------------------------------------------------------------------------------- /0x18-webstack_monitoring/2-setup_datadog: -------------------------------------------------------------------------------- 1 | srv-5ud-a2h -------------------------------------------------------------------------------- /0x18-webstack_monitoring/README.md: -------------------------------------------------------------------------------- 1 | # Webstack monitoring -------------------------------------------------------------------------------- /0x19-postmortem/README.md: -------------------------------------------------------------------------------- 1 | # Postmortem -------------------------------------------------------------------------------- /0x1A-application_server/2-app_server-nginx_config: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80 default_server; 3 | listen [::]:80 ipv6only=on default_server; 4 | server_name localhost; 5 | 6 | root /var/www/html; 7 | 8 | location /hbnb_static/ { 9 | alias /data/web_static/current/; 10 | autoindex off; 11 | } 12 | 13 | index index.html index.htm index.nginx-debian.html; 14 | rewrite ^/redirect_me https://github.com/luischaparroc permanent; 15 | 16 | error_page 404 /custom_404.html; 17 | 18 | location = /custom_404.html { 19 | root /usr/share/nginx/html; 20 | internal; 21 | } 22 | 23 | location /airbnb-onepage/ { 24 | include proxy_params; 25 | proxy_pass http://0.0.0.0:5000/airbnb-onepage/; 26 | } 27 | 28 | location / { 29 | try_files $uri $uri/ =404; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /0x1A-application_server/3-app_server-nginx_config: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80 default_server; 3 | listen [::]:80 ipv6only=on default_server; 4 | server_name localhost; 5 | 6 | root /var/www/html; 7 | 8 | location /hbnb_static/ { 9 | alias /data/web_static/current/; 10 | autoindex off; 11 | } 12 | 13 | index index.html index.htm index.nginx-debian.html; 14 | rewrite ^/redirect_me https://github.com/luischaparroc permanent; 15 | 16 | error_page 404 /custom_404.html; 17 | 18 | location = /custom_404.html { 19 | root /usr/share/nginx/html; 20 | internal; 21 | } 22 | 23 | location /airbnb-onepage/ { 24 | include proxy_params; 25 | proxy_pass http://0.0.0.0:5000/airbnb-onepage/; 26 | } 27 | 28 | location /airbnb-dynamic/number_odd_or_even/ { 29 | include proxy_params; 30 | proxy_pass http://0.0.0.0:5001/number_odd_or_even/; 31 | } 32 | 33 | location / { 34 | try_files $uri $uri/ =404; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /0x1A-application_server/4-app_server-nginx_config: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80 default_server; 3 | listen [::]:80 ipv6only=on default_server; 4 | server_name localhost; 5 | 6 | root /var/www/html; 7 | 8 | location /hbnb_static/ { 9 | alias /data/web_static/current/; 10 | autoindex off; 11 | } 12 | 13 | index index.html index.htm index.nginx-debian.html; 14 | rewrite ^/redirect_me https://github.com/luischaparroc permanent; 15 | 16 | error_page 404 /custom_404.html; 17 | 18 | location = /custom_404.html { 19 | root /usr/share/nginx/html; 20 | internal; 21 | } 22 | 23 | location /airbnb-onepage/ { 24 | include proxy_params; 25 | proxy_pass http://0.0.0.0:5000/airbnb-onepage/; 26 | } 27 | 28 | location /airbnb-dynamic/number_odd_or_even/ { 29 | include proxy_params; 30 | proxy_pass http://0.0.0.0:5001/number_odd_or_even/; 31 | } 32 | 33 | location /api/ { 34 | include proxy_params; 35 | proxy_pass http://0.0.0.0:5002/api/; 36 | } 37 | 38 | location / { 39 | try_files $uri $uri/ =404; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /0x1A-application_server/5-app_server-nginx_config: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80 default_server; 3 | listen [::]:80 ipv6only=on default_server; 4 | server_name localhost 35.231.33.237; 5 | 6 | root /home/ubuntu/AirBnB_clone_v4/web_dynamic; 7 | 8 | location /hbnb_static/ { 9 | alias /data/web_static/current/; 10 | autoindex off; 11 | } 12 | 13 | index index.html index.htm index.nginx-debian.html; 14 | rewrite ^/redirect_me https://github.com/luischaparroc permanent; 15 | 16 | error_page 404 /custom_404.html; 17 | 18 | location = /custom_404.html { 19 | root /usr/share/nginx/html; 20 | internal; 21 | } 22 | 23 | location /airbnb-onepage/ { 24 | include proxy_params; 25 | proxy_pass http://0.0.0.0:5000/airbnb-onepage/; 26 | } 27 | 28 | location /airbnb-dynamic/number_odd_or_even/ { 29 | include proxy_params; 30 | proxy_pass http://0.0.0.0:5001/number_odd_or_even/; 31 | } 32 | 33 | location /static { 34 | } 35 | 36 | location /api/ { 37 | include proxy_params; 38 | proxy_pass http://0.0.0.0:5002/api/; 39 | } 40 | 41 | location / { 42 | include proxy_params; 43 | proxy_pass http://0.0.0.0:5003/2-hbnb/; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /0x1A-application_server/README.md: -------------------------------------------------------------------------------- 1 | # Application server -------------------------------------------------------------------------------- /0x1B-web_stack_debugging_4/0-the_sky_is_the_limit_not.pp: -------------------------------------------------------------------------------- 1 | # Fix problem of high amount of requests 2 | 3 | exec {'replace': 4 | provider => shell, 5 | command => 'sudo sed -i "s/ULIMIT=\"-n 15\"/ULIMIT=\"-n 4096\"/" /etc/default/nginx', 6 | before => Exec['restart'], 7 | } 8 | 9 | exec {'restart': 10 | provider => shell, 11 | command => 'sudo service nginx restart', 12 | } -------------------------------------------------------------------------------- /0x1B-web_stack_debugging_4/1-user_limit.pp: -------------------------------------------------------------------------------- 1 | # Fix problem of high amount files opened 2 | 3 | exec {'replace-1': 4 | provider => shell, 5 | command => 'sudo sed -i "s/nofile 5/nofile 50000/" /etc/security/limits.conf', 6 | before => Exec['replace-2'], 7 | } 8 | 9 | exec {'replace-2': 10 | provider => shell, 11 | command => 'sudo sed -i "s/nofile 4/nofile 40000/" /etc/security/limits.conf', 12 | } -------------------------------------------------------------------------------- /0x1B-web_stack_debugging_4/README.md: -------------------------------------------------------------------------------- 1 | # Web stack debugging 4 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # System engineering & Devops 2 | 3 | Module of **System engineering** and **Devops**, carried out during **Full Stack Software Engineering studies** at **[Holberton School](https://www.holbertonschool.com/)**. 4 | 5 | ## Technologies 6 | * Scripts written in Bash 4.3.11(1) 7 | * Tested on Ubuntu 14.04 LTS 8 | * Puppet 3.8 9 | 10 | ## Projects 11 | All of the following folders are projects done during the studies: 12 | 13 | | Project name | Description | 14 | | ------------ | ----------- | 15 | | [`0x00-shell_basics`](https://github.com/luischaparroc/holberton-system_engineering-devops/tree/master/0x00-shell_basics) | It aims to learn about basics commands, navigation, files and directories in **Shell** | 16 | | [`0x01-shell_permissions`](https://github.com/luischaparroc/holberton-system_engineering-devops/tree/master/0x01-shell_permissions) | It aims to learn about man pages, permissions (owner, group and other) of files and directories in **Shell** | 17 | | [`0x02-shell_redirections`](https://github.com/luischaparroc/holberton-system_engineering-devops/tree/master/0x02-shell_redirections) | It aims to learn about how to handle standard input and output and how to combine commands and filters with redirections in **Shell** | 18 | | [`0x03-shell_variable_expansions`](https://github.com/luischaparroc/holberton-system_engineering-devops/tree/master/0x03-shell_variables_expansions) | It aims to learn about alias builtin, help builtin, local, global and reserved variables (PATH, HOME and PS1), special parameters `$?` and single an double quotes in **Shell** | 19 | | [`0x04-loops_conditions_and_parsing`](https://github.com/luischaparroc/holberton-system_engineering-devops/tree/master/0x04-loops_conditions_and_parsing) | It aims to learn about loops (`while`, `until` and `for`), condition statements (`if`, `else`, `elif` and `case`), shebangs and how to create SSH keys with **Bash** | 20 | | [`0x05-processes_and_signals`](https://github.com/luischaparroc/holberton-system_engineering-devops/tree/master/0x05-processes_and_signals) | It aims to learn about PID, processes and commands that handles them (`ps`, `pgrep`, `pkill`, `kill`, etc) in **Bash** | 21 | | [`0x06-regular_expressions`](https://github.com/luischaparroc/holberton-system_engineering-devops/edit/master/0x06-regular_expressions/README.md) | It aims to learn about how to build a regular expression | 22 | | [`0x07-networking_basics`](https://github.com/luischaparroc/holberton-system_engineering-devops/edit/master/0x07-networking_basics/README.md) | It aims to learn about what is an OSI model, LAN, WAN, IP address, localhost, subnet and TCP/UDP | 23 | | [`0x08-networking_basics_2`](https://github.com/luischaparroc/holberton-system_engineering-devops/edit/master/0x08-networking_basics_2/README.md) | It aims to learn about what is localhost/127.0.0.1, what is 0.0.0.0, what is `/etc/hosts` and how to display the machine's active network interfaces | 24 | | [`0x09-web_infrastructure_design`](https://github.com/luischaparroc/holberton-system_engineering-devops/edit/master/0x09-web_infrastructure_design/README.md) | It aims to learn about how to design a Web Infrastructure | 25 | | [`0x0A-configuration_management`](https://github.com/luischaparroc/holberton-system_engineering-devops/edit/master/0x0A-configuration_management/README.md) | It aims to learn about server configuration management using **Puppet** | 26 | | [`0x0B-ssh`](https://github.com/luischaparroc/holberton-system_engineering-devops/edit/master/0x0B-ssh/README.md) | It aims to learn about what is a SSH, how to create an SSH RSA key pair and how to connect to a remote host using SSH | 27 | | [`0x0C-web_server`](https://github.com/luischaparroc/holberton-system_engineering-devops/edit/master/0x0C-web_server/README.md) | It aims to learn about the roles of web servers and their processes (parent and child), and DNS roles | 28 | | [`0x0D-web_stack_debugging_0`](https://github.com/luischaparroc/holberton-system_engineering-devops/tree/master/0x0D-web_stack_debugging_0) | It aims to learn about how to debug a webstack | 29 | --------------------------------------------------------------------------------