├── 0-simple_web_stack.png ├── 0x00-shell_basics ├── 0-current_working_directory ├── 1-listit ├── 10-back ├── 100-lets_move ├── 101-clean_emacs ├── 102-tree ├── 103-commas ├── 11-lists ├── 12-file_type ├── 13-symbolic_link ├── 14-copy_html ├── 2-bring_me_home ├── 3-listfiles ├── 4-listmorefiles ├── 5-listfilesdigitonly ├── 6-firstdirectory ├── 7-movethatfile ├── 8-firstdelete ├── 9-firstdirdeletion ├── README.md └── school.mgc ├── 0x01-shell_permissions ├── .2-groups.swp ├── .3-new_owner.swp ├── 0-iam_betty ├── 1-who_am_i ├── 10-mirror_permissions ├── 100-change_owner_and_group ├── 101-symbolic_link_permissions ├── 102-if_only ├── 11-directories_permissions ├── 12-directory_permissions ├── 13-change_group ├── 2-groups ├── 3-new_owner ├── 4-empty ├── 5-execute ├── 6-multiple_permissions ├── 7-everybody ├── 8-James_Bond ├── 9-John_Doe └── README.md ├── 0x02-shell_redirections ├── 0-hello_world ├── 1-confused_smiley ├── 10-no_more_js ├── 100-empty_casks ├── 101-gifs ├── 102-acrostic ├── 103-the_biggest_fan ├── 11-directories ├── 12-newest_files ├── 13-unique ├── 14-findthatword ├── 15-countthatword ├── 16-whatsnext ├── 17-hidethisword ├── 18-letteronly ├── 19-AZ ├── 2-hellofile ├── 20-hiago ├── 21-reverse ├── 22-users_and_homes ├── 3-twofiles ├── 4-lastlines ├── 5-firstlines ├── 6-third_line ├── 7-file ├── 8-cwd_state ├── 9-duplicate_last_line └── README.md ├── 0x03-shell_variables_expansions ├── 0-alias ├── 1-hello_you ├── 10-love_exponent_breath ├── 100-decimal_to_hexadecimal ├── 101-rot13 ├── 102-odd ├── 103-water_and_stir ├── 11-binary_to_decimal ├── 12-combinations ├── 13-print_float ├── 2-path ├── 3-paths ├── 4-global_variables ├── 5-local_variables ├── 6-create_local_variable ├── 7-create_global_variable ├── 8-true_knowledge ├── 9-divide_and_rule └── README.md ├── 0x04-loops_conditions_and_parsing ├── 0-RSA_public_key.pub ├── 1-for_best_school ├── 10-fizzbuzz ├── 2-while_best_school ├── 3-until_best_school ├── 4-if_9_say_hi ├── 5-4_bad_luck_8_is_your_chance ├── 6-superstitious_numbers ├── 7-clock ├── 8-for_ls ├── 9-to_file_or_not_to_file └── README.md ├── 0x05-processes_and_signals ├── 0-what-is-my-pid ├── 1-list_your_processes ├── 2-show_your_bash_pid ├── 3-show_your_bash_pid_made_easy ├── 4-to_infinity_and_beyond ├── 5-dont_stop_me_now ├── 6-stop_me_if_you_can ├── 7-highlander └── 8-beheaded_process ├── 0x06-regular_expressions ├── 0-simply_match_school.rb ├── 1-repetition_token_0.rb ├── 100-textme.rb ├── 2-repetition_token_1.rb ├── 3-repetition_token_2.rb ├── 4-repetition_token_3.rb ├── 5-beginning_and_end.rb ├── 6-phone_number.rb ├── 7-OMG_WHY_ARE_YOU_SHOUTING.rb └── README.md ├── 0x07-networking_basics ├── 0-OSI_model ├── 1-types_of_network ├── 2-MAC_and_IP_address ├── 3-UDP_and_TCP ├── 4-TCP_and_UDP_ports ├── 5-is_the_host_on_the_network └── README.md ├── 0x08-networking_basics_2 ├── 0-change_your_home_IP ├── 1-show_attached_IPs ├── 100-port_listening_on_localhost └── README.md ├── 0x09-web_infrastructure_design ├── 0-simple_web_stack.pdf ├── 0-simple_web_stack.png ├── 1-distributed_web_infrastructure ├── 1-distributed_web_infrastructure.pdf ├── 1-distributed_web_infrastructure.png └── 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 ├── 100-puppet_ssh_config.pp ├── 2-ssh_config ├── PasswordAuthentication no, ├── README.md ├── school └── school.pub ├── 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 └── some_page.html ├── 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 ├── 0-tranfer_file ├── 1-install_load_balancer ├── 2-puppet_custom_http_response_header.pp ├── README.md └── index.html ├── 0x10-https_ssl ├── 0-world_wide_web ├── 1-haproxy_ssl_termination ├── 100-redirect_http_to_https └── README.md ├── 0x11-what_happens_when_your_type_google_com_in_your_browser_and_press_enter ├── 0-blog_post ├── 1-what_happen_when_diagram ├── 2-contribution-to_what-happens-when_github_answer └── README.md ├── 0x12-web_stack_debugging_2 ├── 0-iamsomeoneelse ├── 1-run_nginx_as_nginx └── README.md ├── 0x13-firewall ├── 0-block_all_incoming_traffic_but └── 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-main.py ├── 0-subs.py ├── 1-main.py ├── 1-top_ten.py ├── 100-count.py ├── 2-main.py ├── 2-recurse.py └── README.md ├── 0x17-web_stack_debugging_3 ├── 0-strace_is_your_friend.pp └── README.md ├── 0x18-webstack_monitoring ├── README.md └── ddagent-install.log ├── 0x1A-application_server ├── 2-app_server-nginx_config ├── 3-app_server-nginx_config ├── 4-app_server-nginx_config ├── 4-reload_gunicorn_no_downtime ├── 5-app_server-nginx_config ├── README.md └── gunicorn.service ├── 0x1B-web_stack_debugging_4 ├── 0-the_sky_is_the_limit_not.pp ├── 1-user_limit.pp └── README.md └── command_line_for_the_win ├── 0-first_9_tasks.png ├── 1-next_9_tasks.png ├── 2-next_9_tasks.png └── README.md /0-simple_web_stack.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nathanage3/alx-system_engineering-devops/7bc2a3060d7ed3740d86193f14573adbefbfad2e/0-simple_web_stack.png -------------------------------------------------------------------------------- /0x00-shell_basics/0-current_working_directory: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | pwd 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/1-listit: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ls 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/10-back: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd .. 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/100-lets_move: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | mv [[:upper:]]* /tmp/u 2>dev/null 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/101-clean_emacs: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | rm -f *~ 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/102-tree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nathanage3/alx-system_engineering-devops/7bc2a3060d7ed3740d86193f14573adbefbfad2e/0x00-shell_basics/102-tree -------------------------------------------------------------------------------- /0x00-shell_basics/103-commas: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | mkdir -p welcome/to/school 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/11-lists: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ls -la /boot 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/12-file_type: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | file /tmp/iamafile 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/13-symbolic_link: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ln -s /bin/ls __ls__ 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/14-copy_html: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | rsync -auv --exclude='*/' --include='*.html' ./ ../ 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/2-bring_me_home: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/3-listfiles: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ls -l 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/4-listmorefiles: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ls -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/my_first_directory 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/7-movethatfile: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | mv /tmp/betty /tmp/my_first_directory/ 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/8-firstdelete: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | rm /tmp/my_first_directory/betty 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/9-firstdirdeletion: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | rm -r /tmp/my_first_directory 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/README.md: -------------------------------------------------------------------------------- 1 | shell basics for beginners 2 | -------------------------------------------------------------------------------- /0x00-shell_basics/school.mgc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nathanage3/alx-system_engineering-devops/7bc2a3060d7ed3740d86193f14573adbefbfad2e/0x00-shell_basics/school.mgc -------------------------------------------------------------------------------- /0x01-shell_permissions/.2-groups.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nathanage3/alx-system_engineering-devops/7bc2a3060d7ed3740d86193f14573adbefbfad2e/0x01-shell_permissions/.2-groups.swp -------------------------------------------------------------------------------- /0x01-shell_permissions/.3-new_owner.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nathanage3/alx-system_engineering-devops/7bc2a3060d7ed3740d86193f14573adbefbfad2e/0x01-shell_permissions/.3-new_owner.swp -------------------------------------------------------------------------------- /0x01-shell_permissions/0-iam_betty: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | su betty 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/1-who_am_i: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | whoami 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/10-mirror_permissions: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chmod --reference=olleh hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/100-change_owner_and_group: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chown -R vincent:staff ./* 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/101-symbolic_link_permissions: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nathanage3/alx-system_engineering-devops/7bc2a3060d7ed3740d86193f14573adbefbfad2e/0x01-shell_permissions/101-symbolic_link_permissions -------------------------------------------------------------------------------- /0x01-shell_permissions/102-if_only: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nathanage3/alx-system_engineering-devops/7bc2a3060d7ed3740d86193f14573adbefbfad2e/0x01-shell_permissions/102-if_only -------------------------------------------------------------------------------- /0x01-shell_permissions/11-directories_permissions: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chmod -R a+x . 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/12-directory_permissions: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | mkdir -m 751 my_dir 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/13-change_group: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chgrp school hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/2-groups: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | id -nG $USER 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/3-new_owner: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chown betty hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/4-empty: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | touch hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/5-execute: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chmod u+x hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/6-multiple_permissions: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chmod ug+x,o+r hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/7-everybody: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chmod 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 second project 2 | -------------------------------------------------------------------------------- /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 . -type d -empty -printf "%f\n" && find . -type f -empty -printf "%f\n" 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/101-gifs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nathanage3/alx-system_engineering-devops/7bc2a3060d7ed3740d86193f14573adbefbfad2e/0x02-shell_redirections/101-gifs -------------------------------------------------------------------------------- /0x02-shell_redirections/102-acrostic: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nathanage3/alx-system_engineering-devops/7bc2a3060d7ed3740d86193f14573adbefbfad2e/0x02-shell_redirections/102-acrostic -------------------------------------------------------------------------------- /0x02-shell_redirections/103-the_biggest_fan: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nathanage3/alx-system_engineering-devops/7bc2a3060d7ed3740d86193f14573adbefbfad2e/0x02-shell_redirections/103-the_biggest_fan -------------------------------------------------------------------------------- /0x02-shell_redirections/11-directories: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | find . -mindepth 1 -type d | wc -l 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/12-newest_files: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | find . -type f | ls -tp | head -10 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/13-unique: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | sort | uniq -u 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/14-findthatword: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cat /etc/passwd | grep 'root' 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/15-countthatword: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cat /etc/passwd | grep 'bin' | wc -l 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/16-whatsnext: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | grep -A 3 "root" /etc/passwd 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/17-hidethisword: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | grep -v "bin" /etc/passwd 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/18-letteronly: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | grep "^[[:alpha:]]" /etc/ssh/sshd_config 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/19-AZ: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | tr 'Ac' 'Ze' 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 | cat /etc/passwd | cut -d: -f1,6 | sort 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/3-twofiles: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cat /etc/passwd /etc/hosts 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/4-lastlines: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | tail /etc/passwd 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/5-firstlines: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | head /etc/passwd 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/6-third_line: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | head -n 3 "iacta" | tail -n 1 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/7-file: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "Best School" >'\\*\\'"Best School"\\'\\\\*$\\?\\*\\*\\*\\*\\*\:\)\' 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/8-cwd_state: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ls -la > ls_cwd_content 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/9-duplicate_last_line: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | tail -n 1 iacta >> iacta 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/README.md: -------------------------------------------------------------------------------- 1 | shell i/o redirection 2 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/0-alias: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | alias ls='rm *' 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/1-hello_you: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo hello $USER 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/10-love_exponent_breath: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo $(($BREATH**$LOVE)) 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/100-decimal_to_hexadecimal: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | printf "%X\n" $DECIMAL 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/101-rot13: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | tr 'A-Za-z' 'N-ZA-Mn-za-m' 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/102-odd: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | awk 'NR % 2 == 1' 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/103-water_and_stir: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nathanage3/alx-system_engineering-devops/7bc2a3060d7ed3740d86193f14573adbefbfad2e/0x03-shell_variables_expansions/103-water_and_stir -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/11-binary_to_decimal: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo $((2#$BINARY)) 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/12-combinations: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo {a..z}{a..z} | tr ' ' '\n' | grep -v 'oo' 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/13-print_float: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | printf "%.2f\n" $NUM 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/2-path: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | export PATH=$PATH:/action 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/3-paths: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo $PATH | tr ':' '\n'| wc -l 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/4-global_variables: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | printenv 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/5-local_variables: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/6-create_local_variable: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | BEST='School' 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/7-create_global_variable: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | export BEST='School' 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/8-true_knowledge: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo $((128 + $TRUEKNOWLEDGE)) 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/9-divide_and_rule: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo $(($POWER / $DIVIDE)) 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/README.md: -------------------------------------------------------------------------------- 1 | 2 | Home | Previous | Contents | Next 3 | Expansion 4 | Each time we type a command line and press the enter key, bash performs several processes upon the text before it carries out our command. We have seen a couple of cases of how a simple character sequence, for example “*”, can have a lot of meaning to the shell. The process that makes this happen is called expansion. With expansion, we type something and it is expanded into something else before the shell acts upon it. To demonstrate what we mean by this, let's take a look at the echo command. echo is a shell builtin that performs a very simple task. It prints out its text arguments on standard output: 5 | 6 | [me@linuxbox me]$ echo this is a test 7 | this is a test 8 | That's pretty straightforward. Any argument passed to echo gets displayed. Let's try another example: 9 | 10 | [me@linuxbox me]$ echo * 11 | Desktop Documents ls-output.txt Music Pictures Public Templates Videos 12 | So what just happened? Why didn't echo print “*”? As we recall from our work with wildcards, the “*” character means match any characters in a filename, but what we didn't see in our original discussion was how the shell does that. The simple answer is that the shell expands the “*” into something else (in this instance, the names of the files in the current working directory) before the echo command is executed. When the enter key is pressed, the shell automatically expands any qualifying characters on the command line before the command is carried out, so the echo command never saw the “*”, only its expanded result. Knowing this, we can see that echo behaved as expected. 13 | 14 | Pathname Expansion 15 | The mechanism by which wildcards work is called pathname expansion. If we try some of the techniques that we employed in our earlier lessons, we will see that they are really expansions. Given a home directory that looks like this: 16 | 17 | [me@linuxbox me]$ ls 18 | Desktop 19 | ls-output.txt 20 | Documents Music 21 | Pictures 22 | Public 23 | Templates 24 | Videos 25 | we could carry out the following expansions: 26 | 27 | [me@linuxbox me]$ echo D* 28 | Desktop Documents 29 | and: 30 | 31 | [me@linuxbox me]$ echo *s 32 | Documents Pictures Templates Videos 33 | or even: 34 | 35 | [me@linuxbox me]$ echo [[:upper:]]* 36 | Desktop Documents Music Pictures Public Templates Videos 37 | and looking beyond our home directory: 38 | 39 | [me@linuxbox me]$ echo /usr/*/share 40 | /usr/kerberos/share /usr/local/share 41 | Tilde Expansion 42 | As we recall from our introduction to the cd command, the tilde character (“~”) has a special meaning. When used at the beginning of a word, it expands into the name of the home directory of the named user, or if no user is named, the home directory of the current user: 43 | 44 | [me@linuxbox me]$ echo ~ 45 | /home/me 46 | If user “foo” has an account, then: 47 | 48 | [me@linuxbox me]$ echo ~foo 49 | /home/foo 50 | Arithmetic Expansion 51 | The shell allows arithmetic to be performed by expansion. This allow us to use the shell prompt as a calculator: 52 | 53 | [me@linuxbox me]$ echo $((2 + 2)) 54 | 4 55 | Arithmetic expansion uses the form: 56 | 57 | $((expression)) 58 | where expression is an arithmetic expression consisting of values and arithmetic operators. 59 | 60 | Arithmetic expansion only supports integers (whole numbers, no decimals), but can perform quite a number of different operations. 61 | 62 | Spaces are not significant in arithmetic expressions and expressions may be nested. For example, to multiply five squared by three: 63 | 64 | [me@linuxbox me]$ echo $(($((5**2)) * 3)) 65 | 75 66 | Single parentheses may be used to group multiple subexpressions. With this technique, we can rewrite the example above and get the same result using a single expansion instead of two: 67 | 68 | [me@linuxbox me]$ echo $(((5**2) * 3)) 69 | 75 70 | Here is an example using the division and remainder operators. Notice the effect of integer division: 71 | 72 | [me@linuxbox me]$ echo Five divided by two equals $((5/2)) 73 | Five divided by two equals 2 74 | [me@linuxbox me]$ echo with $((5%2)) left over. 75 | with 1 left over. 76 | Brace Expansion 77 | Perhaps the strangest expansion is called brace expansion. With it, we can create multiple text strings from a pattern containing braces. Here's an example: 78 | 79 | [me@linuxbox me]$ echo Front-{A,B,C}-Back 80 | Front-A-Back Front-B-Back Front-C-Back 81 | Patterns to be brace expanded may contain a leading portion called a preamble and a trailing portion called a postscript. The brace expression itself may contain either a comma-separated list of strings, or a range of integers or single characters. The pattern may not contain embedded whitespace. Here is an example using a range of integers: 82 | 83 | [me@linuxbox me]$ echo Number_{1..5} 84 | Number_1 Number_2 Number_3 Number_4 Number_5 85 | A range of letters in reverse order: 86 | 87 | [me@linuxbox me]$ echo {Z..A} 88 | Z Y X W V U T S R Q P O N M L K J I H G F E D C B A 89 | Brace expansions may be nested: 90 | 91 | [me@linuxbox me]$ echo a{A{1,2},B{3,4}}b 92 | aA1b aA2b aB3b aB4b 93 | So what is this good for? The most common application is to make lists of files or directories to be created. For example, if we were a photographer and had a large collection of images we wanted to organize into years and months, the first thing we might do is create a series of directories named in numeric “Year-Month” format. This way, the directory names will sort in chronological order. we could type out a complete list of directories, but that's a lot of work and it's error-prone too. Instead, we could do this: 94 | 95 | [me@linuxbox me]$ mkdir Photos 96 | [me@linuxbox me]$ cd Photos 97 | [me@linuxbox Photos]$ mkdir {2017..2019}-{01..12} 98 | [me@linuxbox Photos]$ ls 99 | 2017-01 2017-07 2018-01 2018-07 2019-01 2019-07 100 | 2017-02 2017-08 2018-02 2018-08 2019-02 2019-08 101 | 2017-03 2017-09 2018-03 2018-09 2019-03 2019-09 102 | 2017-04 2017-10 2018-04 2018-10 2019-04 2019-10 103 | 2017-05 2017-11 2018-05 2018-11 2019-05 2019-11 104 | 2017-06 2017-12 2018-06 2018-12 2019-06 2019-12 105 | Pretty slick! 106 | 107 | Parameter Expansion 108 | We're only going to touch briefly on parameter expansion in this lesson, but we'll be covering it more later. It's a feature that is more useful in shell scripts than directly on the command line. Many of its capabilities have to do with the system's ability to store small chunks of data and to give each chunk a name. Many such chunks, more properly called variables, are available for our examination. For example, the variable named “USER” contains our user name. To invoke parameter expansion and reveal the contents of USER we would do this: 109 | 110 | [me@linuxbox me]$ echo $USER 111 | me 112 | To see a list of available variables, try this: 113 | 114 | [me@linuxbox me]$ printenv | less 115 | With other types of expansion, if we mistype a pattern, the expansion will not take place and the echo command will simply display the mistyped pattern. With parameter expansion, if we misspell the name of a variable, the expansion will still take place, but will result in an empty string: 116 | 117 | [me@linuxbox me]$ echo $SUER 118 | [me@linuxbox ~]$ 119 | Command Substitution 120 | Command substitution allows us to use the output of a command as an expansion: 121 | 122 | [me@linuxbox me]$ echo $(ls) 123 | Desktop Documents ls-output.txt Music Pictures Public Templates Videos 124 | A clever one goes something like this: 125 | 126 | [me@linuxbox me]$ ls -l $(which cp) 127 | -rwxr-xr-x 1 root root 71516 2007-12-05 08:58 /bin/cp 128 | Here we passed the results of which cp as an argument to the ls command, thereby getting the listing of of the cp program without having to know its full pathname. We are not limited to just simple commands. Entire pipelines can be used (only partial output shown): 129 | 130 | [me@linuxbox me]$ file $(ls /usr/bin/* | grep bin/zip) 131 | /usr/bin/bunzip2: 132 | /usr/bin/zip: ELF 32-bit LSB executable, Intel 80386, version 1 133 | (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, stripped 134 | /usr/bin/zipcloak: ELF 32-bit LSB executable, Intel 80386, version 1 135 | (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, stripped 136 | /usr/bin/zipgrep: POSIX shell script text executable 137 | /usr/bin/zipinfo: ELF 32-bit LSB executable, Intel 80386, version 1 138 | (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, stripped 139 | /usr/bin/zipnote: ELF 32-bit LSB executable, Intel 80386, version 1 140 | (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, stripped 141 | /usr/bin/zipsplit: ELF 32-bit LSB executable, Intel 80386, version 1 142 | (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, stripped 143 | In this example, the results of the pipeline became the argument list of the file command. There is an alternate syntax for command substitution in older shell programs which is also supported in bash. It uses back-quotes instead of the dollar sign and parentheses: 144 | 145 | [me@linuxbox me]$ ls -l `which cp` 146 | -rwxr-xr-x 1 root root 71516 2007-12-05 08:58 /bin/cp 147 | Quoting 148 | Now that we've seen how many ways the shell can perform expansions, it's time to learn how we can control it. Take for example: 149 | 150 | [me@linuxbox me]$ echo this is a test 151 | this is a test 152 | or: 153 | 154 | [me@linuxbox me]$ [me@linuxbox ~]$ echo The total is $100.00 155 | The total is 00.00 156 | In the first example, word-splitting by the shell removed extra whitespace from the echo command's list of arguments. In the second example, parameter expansion substituted an empty string for the value of “$1” because it was an undefined variable. The shell provides a mechanism called quoting to selectively suppress unwanted expansions. 157 | 158 | Double Quotes 159 | The first type of quoting we will look at is double quotes. If we place text inside double quotes, all the special characters used by the shell lose their special meaning and are treated as ordinary characters. The exceptions are “$”, “\” (backslash), and “`” (back- quote). This means that word-splitting, pathname expansion, tilde expansion, and brace expansion are suppressed, but parameter expansion, arithmetic expansion, and command substitution are still carried out. Using double quotes, we can cope with filenames containing embedded spaces. Imagine we were the unfortunate victim of a file called two words.txt. If we tried to use this on the command line, word-splitting would cause this to be treated as two separate arguments rather than the desired single argument: 160 | 161 | [me@linuxbox me]$ ls -l two words.txt 162 | ls: cannot access two: No such file or directory 163 | ls: cannot access words.txt: No such file or directory 164 | By using double quotes, we can stop the word-splitting and get the desired result; further, we can even repair the damage: 165 | 166 | [me@linuxbox me]$ ls -l "two words.txt" 167 | -rw-rw-r-- 1 me me 18 2020-02-20 13:03 two words.txt 168 | [me@linuxbox me]$ mv "two words.txt" two_words.txt 169 | There! Now we don't have to keep typing those pesky double quotes. Remember, parameter expansion, arithmetic expansion, and command substitution still take place within double quotes: 170 | 171 | [me@linuxbox me]$ echo "$USER $((2+2)) $(cal)" 172 | me 4 173 | February 2020 174 | Su Mo Tu We Th Fr Sa 175 | 1 2 176 | 3 4 5 6 7 8 9 177 | 10 11 12 13 14 15 16 178 | 17 18 19 20 21 22 23 179 | 24 25 26 27 28 29 180 | We should take a moment to look at the effect of double quotes on command substitution. First let's look a little deeper at how word splitting works. In our earlier example, we saw how word-splitting appears to remove extra spaces in our text: 181 | 182 | [me@linuxbox me]$ echo this is a test 183 | this is a test 184 | By default, word-splitting looks for the presence of spaces, tabs, and newlines (linefeed characters) and treats them as delimiters between words. This means that unquoted spaces, tabs, and newlines are not considered to be part of the text. They only serve as separators. Since they separate the words into different arguments, our example command line contains a command followed by four distinct arguments. If we add double quotes: 185 | 186 | [me@linuxbox me]$ echo "this is a test" 187 | this is a test 188 | word-splitting is suppressed and the embedded spaces are not treated as delimiters, rather they become part of the argument. Once the double quotes are added, our command line contains a command followed by a single argument. The fact that newlines are considered delimiters by the word-splitting mechanism causes an interesting, albeit subtle, effect on command substitution. Consider the following: 189 | 190 | [me@linuxbox me]$ echo $(cal) 191 | February 2020 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 192 | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 193 | [me@linuxbox me]$ echo "$(cal)" 194 | February 2020 195 | Su Mo Tu We Th Fr Sa 196 | 1 2 197 | 3 4 5 6 7 8 9 198 | 10 11 12 13 14 15 16 199 | 17 18 19 20 21 22 23 200 | 24 25 26 27 28 29 201 | In the first instance, the unquoted command substitution resulted in a command line containing thirty-eight arguments. In the second, a command line with one argument that includes the embedded spaces and newlines. 202 | 203 | Single Quotes 204 | When we need to suppress all expansions, we use single quotes. Here is a comparison of unquoted, double quotes, and single quotes: 205 | 206 | [me@linuxbox me]$ echo text ~/*.txt {a,b} $(echo foo) $((2+2)) $USER 207 | text /home/me/ls-output.txt a b foo 4 me 208 | [me@linuxbox me]$ echo "text ~/*.txt {a,b} $(echo foo) $((2+2)) $USER" 209 | text ~/*.txt {a,b} foo 4 me 210 | [me@linuxbox me]$ echo 'text ~/*.txt {a,b} $(echo foo) $((2+2)) $USER' 211 | text ~/*.txt {a,b} $(echo foo) $((2+2)) $USER 212 | As we can see, with each succeeding level of quoting, more and more of the expansions are suppressed. 213 | 214 | Escaping Characters 215 | Sometimes we only want to quote a single character. To do this, we can precede a character with a backslash, which in this context is called the escape character. Often this is done inside double quotes to selectively prevent an expansion: 216 | 217 | [me@linuxbox me]$ echo "The balance for user $USER is: \$5.00" 218 | The balance for user me is: $5.00 219 | It is also common to use escaping to eliminate the special meaning of a character in a filename. For example, it is possible to use characters in filenames that normally have special meaning to the shell. These would include “$”, “!”, “&”, “ “, and others. To include a special character in a filename we can to this: 220 | 221 | [me@linuxbox me]$ mv bad\&filename good_filename 222 | To allow a backslash character to appear, escape it by typing “\\”. Note that within single quotes, the backslash loses its special meaning and is treated as an ordinary character. 223 | 224 | More Backslash Tricks 225 | If we look at the man pages for any program written by the GNU project, we will see that in addition to command line options consisting of a dash and a single letter, there are also long option names that begin with two dashes. For example, the following are equivalent: 226 | 227 | ls -r 228 | ls --reverse 229 | Why do they support both? The short form is for lazy typists on the command line and the long form is mostly for scripts though some options may only be available in long form. Sometimes it is better to use a long option when the option is obscure or we want to document more clearly what an option is. This is especially useful when writing scripts where maximum readability is desired, and besides, anytime we can save ourselves a trip to the man page is a good thing. 230 | 231 | As we might suspect, using the long form options can make a single command line very long. To combat this problem, we can use a backslash to get the shell to ignore a newline character like this: 232 | 233 | ls -l \ 234 | --reverse \ 235 | --human-readable \ 236 | --full-time 237 | Using the backslash in this way allows us to embed newlines in our command. Note that for this trick to work, the newline must be typed immediately after the backslash. If we put a space after the backslash, the space will be ignored, not the newline. Backslashes are also used to insert special characters into our text. These are called backslash escape characters. Here are the common ones: 238 | 239 | Escape Character Name Possible Uses 240 | \n newline Adding blank lines to text 241 | \t tab Inserting horizontal tabs to text 242 | \a alert Makes our terminal beep 243 | \\ backslash Inserts a backslash 244 | \f formfeed Sending this to our printer ejects the page 245 | The use of the backslash escape characters is very common. This idea first appeared in the C programming language. Today, the shell, C++, Perl, python, awk, tcl, and many other programming languages use this concept. Using the echo command with the -e option will allow us to demonstrate: 246 | 247 | [me@linuxbox me]$ echo -e "Inserting several blank lines\n\n\n" 248 | Inserting several blank lines 249 | 250 | [me@linuxbox me]$ echo -e "Words\tseparated\tby\thorizontal\ttabs." 251 | Words separated by horizontal tabs 252 | [me@linuxbox me]$ echo -e "\aMy computer went \"beep\"." 253 | My computer went "beep". 254 | [me@linuxbox me]$ echo -e "DEL C:\\WIN2K\\LEGACY_OS.EXE" 255 | DEL C:\WIN2K\LEGACY_OS.EXE 256 | Top | Previous | Contents | Next 257 | © 2000-2023, William E. Shotts, Jr. Verbatim copying and distribution of this entire article is permitted in any medium, provided this copyright notice is preserved. 258 | 259 | Linux® is a registered trademark of Linus Torvalds. 260 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/0-RSA_public_key.pub: -------------------------------------------------------------------------------- 1 | ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDEkhZotsVuqf6fIKT1aO0g4swou+Sd2yP8/9zQdKOlb8n5nS9cTCp9/sLMPUQwiG31gbtccn3DM+i8ZeVpCZ8WgkHoNQSi4vFmDMMox1LnflSX5O2HllaPNJsIn/vBHlklgMGU17SdeVXKzjnEQCWKt6NiBmXXoIeoVzpBCsYGLVJqOoWNr7bvqwk05Y3L6XrOlzBajZ4zUaAHVL/Mli5UhqClqkqSstPspx8JSspNICRbLVUbXt3I9mv8ahfUK71uohkvfpuq6ZITXKD7DKNBBqmSXwuDwBA8l2eFIie24sS7tcproyCgPL6jCEXfaMQS8NJ82h3XR8UFFg+yAo96DQqeJ52EAaB6+o9PieiKRgmBP3gkw21UtspvsGiAvrs/5A1n7zdiDum39ss7rl0RFW/B0Yrdm56SKRdhSSOtITwf3x+OHC1kUYWq/49iGn10KEHnkwtoM7R8NPrjOILtqPjV/E0IkM+KatGyZ0RvJZOVmEuBOEi/odp3TzN7Ke0= sisay954@DESKTOP-LESCVLV 2 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/1-for_best_school: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # This script is displaying "Best School" 10 times 3 | 4 | for _ in {1..10}; do 5 | echo "Best School" 6 | done 7 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/10-fizzbuzz: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # a Bash script that displays numbers from 1 to 100. 3 | # Displays FizzBuzz when the number is a multiple of 3 and 5 4 | # Displays Fizz when the number is multiple of 3 5 | # Displays Buzz when the number is a multiple of 5 6 | # Otherwise, displays the number, In a list format 7 | 8 | for i in {1..100} 9 | do 10 | if ((i % 15 == 0)) 11 | then 12 | echo "FizzBuzz" 13 | elif ((i % 5 == 0)) 14 | then 15 | echo "Buzz" 16 | elif (( i % 3 == 0)) 17 | then 18 | echo "Fizz" 19 | else 20 | echo "$i" 21 | fi 22 | done 23 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/2-while_best_school: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # This script is displaying "Best School" 10 times 3 | i=1 4 | while [ "$i" -le 10 ]; do 5 | echo "Best School" 6 | i=$((i + 1)) 7 | done 8 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/3-until_best_school: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # This script is displaying "Best School" 10 times 3 | 4 | counter=0 5 | 6 | until [ $counter -ge 10 ]; do 7 | echo "Best School" 8 | ((counter++)) 9 | done 10 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/4-if_9_say_hi: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # This script is displaying "Best School" 10 times 3 | 4 | count=1 5 | while [ $count -le 10 ]; do 6 | if [ $count -eq 9 ]; then 7 | echo "Best School" 8 | echo "Hi" 9 | else 10 | echo "Best School" 11 | fi 12 | count=$((count + 1)) 13 | done 14 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/5-4_bad_luck_8_is_your_chance: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # This script is displaying "Best School" 10 times 3 | 4 | count=1 5 | 6 | while [ $count -le 10 ]; do 7 | if [ $count -eq 4 ]; then 8 | echo "bad luck" 9 | elif [ $count -eq 8 ]; then 10 | echo "good luck" 11 | else 12 | echo "Best School" 13 | fi 14 | count=$((count + 1)) 15 | done 16 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/6-superstitious_numbers: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Bash script that displays numbers from 1 to 20 and: 3 | # displays 4 and then bad luck from China for the 4th loop iteration 4 | # displays 9 and then bad luck from Japan for the 9th loop iteration 5 | # displays 17 and then bad luck from Italy for the 17th loop iteration 6 | i="1" 7 | while [ $i -le 20 ] 8 | do 9 | case $i in 10 | 4) echo $i 11 | echo "bad luck from China" 12 | ;; 13 | 9) echo $i 14 | echo "bad luck from Japan" 15 | ;; 16 | 17)echo $i 17 | echo "bad luck from Italy" 18 | ;; 19 | *) 20 | echo $i 21 | esac 22 | i=$((i+1)) 23 | done 24 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/7-clock: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #Write a Bash script that displays the time for 12 hours and 59 minutes: 3 | 4 | i=0 5 | while [ $i -le 12 ]; do 6 | echo "Hour: $i" 7 | j=1 8 | while [ $j -le 59 ]; do 9 | echo $j 10 | j=$((j + 1)) 11 | done 12 | i=$((i + 1)) 13 | done 14 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/8-for_ls: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #Where only the part of the name after the first dash is displayed 3 | 4 | for file in *; do 5 | if [ -f "$file" ]; then 6 | after_dash=${file#*-} 7 | echo "$after_dash" 8 | fi 9 | done 10 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/9-to_file_or_not_to_file: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays information about the file `school`. 3 | 4 | if [ -e "school" ] 5 | then 6 | echo "school file exists" 7 | if [ -s "school" ] 8 | then 9 | echo "school file is not empty" 10 | else 11 | echo "school file is empty" 12 | fi 13 | 14 | if [ -f "school" ] 15 | then 16 | echo "school is a regular file" 17 | fi 18 | else 19 | echo "school file does not exist" 20 | fi 21 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/README.md: -------------------------------------------------------------------------------- 1 | Shellcheck 2 | Shellcheck is a tool that will help you write proper Bash scripts. It will make recommendations on your syntax and semantics and provide advice on edge cases that you might not have thought about. Shellcheck is your friend! All your Bash scripts must pass Shellcheck without any error or you will not get any points on the task. 3 | 4 | Shellcheck is available on the school’s computers. If you want to use it on your own computer, here is how to install it. 5 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/0-what-is-my-pid: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays its own process ID. 3 | 4 | echo $$ 5 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/1-list_your_processes: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #Write a Bash script that displays a list of currently running processes. 3 | 4 | ps auxf 5 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/2-show_your_bash_pid: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # write a Bash script that displays lines containing the bash word, thus allowing you to easily get the PID of your Ba sh process. 3 | # shellcheck disable=SC2009 4 | ps auxf | grep bash 5 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/3-show_your_bash_pid_made_easy: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # displays the PID, along with the process name, of processes 3 | # whose name contain the word bash 4 | 5 | pgrep -l bash 6 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/4-to_infinity_and_beyond: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Write a Bash script that displays To infinity and beyond indefinitely. 3 | 4 | while true; do 5 | echo "To infinity and beyond" 6 | sleep 2 7 | done 8 | 9 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/5-dont_stop_me_now: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # kills the infinity and beyond program using sigkill signal 3 | 4 | # Get the pid of the program 5 | id=$(pgrep "bash ./4-to_infinity_and_beyond" -f) 6 | 7 | # Terminate the infinate process 8 | if [ -n "$id" ] 9 | then 10 | kill -15 "$id" 11 | fi 12 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/6-stop_me_if_you_can: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # kills the infinity and beyond program using sigkill signal 3 | 4 | # Terminate the infinite process 5 | pkill -15 "bash ./4-to_infinity_and_beyond" -f 6 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/7-highlander: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # prints the message infinity and beyond for 3 | # eternity unless it is killed, not so ethernal after all :) 4 | 5 | # Handle SIGTERM 6 | trap "echo 'I am invincible!!!'" 15 7 | 8 | 9 | # print the message forever 10 | while true; 11 | do 12 | echo "To infinity and beyond"; 13 | sleep 2 14 | done 15 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/8-beheaded_process: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # kills the infinity and beyond program using sigkill signal 3 | 4 | # Terminate the infinate process 5 | pkill -9 "bash ./7-highlander" -f 6 | -------------------------------------------------------------------------------- /0x06-regular_expressions/0-simply_match_school.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | puts ARGV[0].scan(/School/).join 3 | -------------------------------------------------------------------------------- /0x06-regular_expressions/1-repetition_token_0.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | puts ARGV[0].scan(/^hbt*n$/).join 3 | -------------------------------------------------------------------------------- /0x06-regular_expressions/100-textme.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | log_entry = ARGV[0] 3 | from = log_entry.scan(/\[from:(.*?)\]/).flatten[0] 4 | to = log_entry.scan(/\[to:(.*?)\]/).flatten[0] 5 | flags = log_entry.scan(/\[flags:(.*?)\]/).flatten[0] 6 | 7 | puts "#{from},#{to},#{flags}" 8 | -------------------------------------------------------------------------------- /0x06-regular_expressions/2-repetition_token_1.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | puts ARGV[0].scan(/^(htn||hbtn)$/).join 3 | -------------------------------------------------------------------------------- /0x06-regular_expressions/3-repetition_token_2.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | puts ARGV[0].scan(/^hb*t+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(/[A-Z]/).join 3 | -------------------------------------------------------------------------------- /0x06-regular_expressions/README.md: -------------------------------------------------------------------------------- 1 | Regular expressions (regex or regexp) are a powerful tool for pattern matching and text processing in computing. They enable the identification, extraction, manipulation, or replacement of specified patterns in text. Regular expressions are employed in programming languages, text editors, advanced search engines, and other applications for complex text processing tasks. 2 | 3 | Key Concepts of Regular Expressions: 4 | 5 | Basic Patterns: The simplest form of regular expressions. These are direct text matches. For example, the regex "cat" would match the string "cat" in any text. 6 | 7 | Metacharacters: Symbols or sequences that have special meaning in regex, such as . (matches any single character), * (matches zero or more of the preceding element), and + (matches one or more of the preceding element). 8 | 9 | Character Classes: Enclosed in square brackets [], character classes match any one of the enclosed characters. For example, [abc] matches "a", "b", or "c". 10 | 11 | Alternation: The pipe symbol | works as a logical OR. For example, "cat|dog" matches either "cat" or "dog". 12 | 13 | Quantifiers: Indicate how many instances of a character, group, or character class must be present for a match. Common quantifiers include * (0 or more), + (1 or more), ? (0 or 1), and {n} (exactly n times). 14 | 15 | Anchors: Special characters that indicate the position in the text relative to a line break or the beginning/end of a string. For example, ^ matches the start of a string, and $ matches the end. 16 | 17 | Grouping and Capturing: Parentheses () are used to define groups, which can be referenced later in the expression or in replacement patterns. This is useful for extracting information or reorganizing the text. 18 | 19 | Escape Character: The backslash \ is used to escape characters that otherwise have a special meaning in regex syntax, allowing them to be treated as literal characters. 20 | 21 | Lookahead and Lookbehind: These are zero-length assertions that match a pattern only if it is followed or preceded by another pattern. 22 | 23 | Flags/Modifiers: These alter how the regular expression is processed. Common flags include i for case-insensitive matching, m for multi-line mode, and g for global search. 24 | 25 | Regular expressions can be very concise but may also become complex and hard to read, making them a bit of a double-edged sword. They are extremely useful for validation (like email or password formats), searching and replacing in text, and parsing data from complex texts. 26 | -------------------------------------------------------------------------------- /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 | #Write a Bash script that displays listening ports: 3 | netstat --listening --program 4 | -------------------------------------------------------------------------------- /0x07-networking_basics/5-is_the_host_on_the_network: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # ping command usage 3 | if [ "$1" ]; then 4 | ping -c 5 "$1" 5 | else 6 | echo "Usage: 5-is_the_host_on_the_network {IP_ADDRESS}" 7 | fi 8 | -------------------------------------------------------------------------------- /0x07-networking_basics/README.md: -------------------------------------------------------------------------------- 1 | Networking Basics 2 | 1. Definition of networking: 3 | Networking in the context of computers refers to the practice of connecting computers, servers, mainframes, network devices, peripherals, or other devices to share data and resources. 4 | 2. Key Components: 5 | 6 | Nodes: Any device connected to a network (computers, printers, servers, etc.). 7 | Router: Directs data packets between networks. 8 | Switch: Connects devices within a single network, managing data flow. 9 | Modem: Connects networks to the internet through various means (DSL, cable, fiber). 10 | 3. Types of Networks: 11 | 12 | Local Area Network (LAN): Covers a small geographical area like a home, office, or building. 13 | Wide Area Network (WAN): Covers larger geographical areas, potentially worldwide. 14 | Metropolitan Area Network (MAN): Spans a city or large campus. 15 | Personal Area Network (PAN): Very small network for personal use, typically within a range of a few meters. 16 | 4. Networking Protocols: 17 | 18 | Protocols are rules and standards that define how data is transmitted. Examples include TCP/IP, HTTP, FTP, and SMTP. 19 | 5. IP Addressing: 20 | 21 | Devices are assigned an IP address (Internet Protocol address) for identification and location addressing. 22 | 6. Network Topologies: 23 | 24 | The arrangement of network devices. Common topologies include star, mesh, bus, and ring. 25 | 7. Data Transfer Methods: 26 | 27 | Wired: Through cables (Ethernet, coaxial, fiber optic). 28 | Wireless: Via radio waves (Wi-Fi, Bluetooth). 29 | 8. Network Security: 30 | 31 | Measures to protect data integrity, availability, and confidentiality. Includes firewalls, encryption, and secure passwords. 32 | 9. Internet of Things (IoT): 33 | 34 | Refers to the growing network of devices connected to the internet, extending networking to everyday objects. 35 | Understanding these basics provides a foundation for delving deeper into the complex and ever-evolving world of computer networks. 36 | -------------------------------------------------------------------------------- /0x08-networking_basics_2/0-change_your_home_IP: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Change localhost address 3 | cp /etc/hosts ~/hosts.new 4 | sed -i "s/^127[0-9.]*\slocalhost/127.0.0.2 localhost/" ~/hosts.new 5 | sed -i "$ a\8.8.8.8 facebook.com" ~/hosts.new 6 | cp -f ~/hosts.new /etc/hosts 7 | -------------------------------------------------------------------------------- /0x08-networking_basics_2/1-show_attached_IPs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # displays all active IPv4 IPs on the machine it’s executed on 3 | ifconfig | awk -F "[: ]+" '/inet addr:/ { print $4 }' 4 | -------------------------------------------------------------------------------- /0x08-networking_basics_2/100-port_listening_on_localhost: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Listens to the port 98 on localhost 3 | nc -l 98 4 | -------------------------------------------------------------------------------- /0x08-networking_basics_2/README.md: -------------------------------------------------------------------------------- 1 | localhost is a hostname that refers to the computer or device you are currently using. It is a loopback network interface, meaning it is a network interface that a computer uses to communicate with itself. The concept is primarily used in networking and software development to test network software. 2 | 3 | Here are some key points about localhost: 4 | 5 | IP Address: localhost is typically associated with the IP address 127.0.0.1 in IPv4, and ::1 in IPv6. These addresses are reserved for loopback. Network traffic that a computer sends to these addresses is effectively sent back to itself. 6 | 7 | Testing and Development: Developers often use localhost for testing applications, especially web applications. For example, a web developer might start a web server on their local machine and access it via http://localhost to test their application. 8 | 9 | Networking: localhost is used to establish network connections without involving the local network interface hardware. It’s a convenient way to determine if the network stack of an operating system is working correctly. 10 | 11 | Security: Because localhost refers to the local machine, it is generally secure from external access. Connections made to localhost do not leave the machine nor can they be intercepted by external devices. 12 | 13 | Use in Software: Many software applications use localhost for various purposes, including proxy settings, local server hosting, and database connections. 14 | 15 | Understanding localhost is fundamental in network programming, system administration, and web development, as it is a standard part of the IP networking protocol that is used universally. 16 | -------------------------------------------------------------------------------- /0x09-web_infrastructure_design/0-simple_web_stack.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nathanage3/alx-system_engineering-devops/7bc2a3060d7ed3740d86193f14573adbefbfad2e/0x09-web_infrastructure_design/0-simple_web_stack.pdf -------------------------------------------------------------------------------- /0x09-web_infrastructure_design/0-simple_web_stack.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nathanage3/alx-system_engineering-devops/7bc2a3060d7ed3740d86193f14573adbefbfad2e/0x09-web_infrastructure_design/0-simple_web_stack.png -------------------------------------------------------------------------------- /0x09-web_infrastructure_design/1-distributed_web_infrastructure: -------------------------------------------------------------------------------- 1 | Assign IP Addresses: 2 | 3 | Each server, including the database server, should have a unique IP address. For example: 4 | Server 1 (Nginx): 192.168.1.2 5 | Server 2 (Application Server): 192.168.1.3 6 | Database Server (MySQL): 192.168.1.4 7 | Ensure Network Connectivity: 8 | 9 | Make sure all servers are on the same network or are reachable from each other. 10 | Configure the Load Balancer (HAproxy): 11 | 12 | HAproxy should be set up to distribute incoming traffic to both the Nginx and Application servers. 13 | Use the IP addresses of these servers in the HAproxy configuration. 14 | Software Configuration 15 | Nginx Server Setup: 16 | 17 | Configure Nginx to handle incoming requests and possibly to reverse proxy requests to the Application Server. 18 | Set up proxy settings in Nginx to redirect to the Application Server’s IP (192.168.1.3). 19 | Application Server Configuration: 20 | 21 | Configure your application server's software to connect to the Database Server. 22 | Set the Database Server's IP address (192.168.1.4) in your application's database configuration. 23 | Database Server Configuration: 24 | 25 | Configure MySQL to accept connections from the Application Server's IP address. 26 | Modify MySQL settings (e.g., bind-address in my.cnf) and set appropriate user privileges. 27 | Security Configuration 28 | Firewalls: 29 | 30 | Implement firewalls on each server. 31 | Configure them to allow traffic specific to each server’s role (e.g., HTTP/HTTPS for Nginx, database connections for MySQL). 32 | Secure Connections: 33 | 34 | Use encrypted connections for sensitive operations, especially database interactions. 35 | Testing the Configuration 36 | Load Balancer Testing: 37 | 38 | Test by making web requests to your HAproxy IP and ensure they are correctly processed by your servers. 39 | Database Connectivity: 40 | 41 | Verify that your Application Server can successfully connect and interact with the Database Server. 42 | Overall Functionality: 43 | 44 | Ensure that each part of the infrastructure works as intended, including the load distribution by HAproxy. 45 | -------------------------------------------------------------------------------- /0x09-web_infrastructure_design/1-distributed_web_infrastructure.pdf: -------------------------------------------------------------------------------- 1 | Assign IP Addresses: 2 | 3 | Each server, including the database server, should have a unique IP address. For example: 4 | Server 1 (Nginx): 192.168.1.2 5 | Server 2 (Application Server): 192.168.1.3 6 | Database Server (MySQL): 192.168.1.4 7 | Ensure Network Connectivity: 8 | 9 | Make sure all servers are on the same network or are reachable from each other. 10 | Configure the Load Balancer (HAproxy): 11 | 12 | HAproxy should be set up to distribute incoming traffic to both the Nginx and Application servers. 13 | Use the IP addresses of these servers in the HAproxy configuration. 14 | Software Configuration 15 | Nginx Server Setup: 16 | 17 | Configure Nginx to handle incoming requests and possibly to reverse proxy requests to the Application Server. 18 | Set up proxy settings in Nginx to redirect to the Application Server’s IP (192.168.1.3). 19 | Application Server Configuration: 20 | 21 | Configure your application server's software to connect to the Database Server. 22 | Set the Database Server's IP address (192.168.1.4) in your application's database configuration. 23 | Database Server Configuration: 24 | 25 | Configure MySQL to accept connections from the Application Server's IP address. 26 | Modify MySQL settings (e.g., bind-address in my.cnf) and set appropriate user privileges. 27 | Security Configuration 28 | Firewalls: 29 | 30 | Implement firewalls on each server. 31 | Configure them to allow traffic specific to each server’s role (e.g., HTTP/HTTPS for Nginx, database connections for MySQL). 32 | Secure Connections: 33 | 34 | Use encrypted connections for sensitive operations, especially database interactions. 35 | Testing the Configuration 36 | Load Balancer Testing: 37 | 38 | Test by making web requests to your HAproxy IP and ensure they are correctly processed by your servers. 39 | Database Connectivity: 40 | 41 | Verify that your Application Server can successfully connect and interact with the Database Server. 42 | Overall Functionality: 43 | 44 | Ensure that each part of the infrastructure works as intended, including the load distribution by HAproxy. 45 | -------------------------------------------------------------------------------- /0x09-web_infrastructure_design/1-distributed_web_infrastructure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nathanage3/alx-system_engineering-devops/7bc2a3060d7ed3740d86193f14573adbefbfad2e/0x09-web_infrastructure_design/1-distributed_web_infrastructure.png -------------------------------------------------------------------------------- /0x09-web_infrastructure_design/README.md: -------------------------------------------------------------------------------- 1 | Web Infrastructure Design 2 | Web infrastructure design refers to the planning and structuring of the hardware, software, resources, and services required to deliver web-based services and applications. It's a comprehensive framework that ensures the efficient functioning, scalability, reliability, and security of web applications. 3 | 4 | Key Components: 5 | 6 | Servers: Central to web infrastructure, servers host applications, manage requests, and deliver content. They can be dedicated, virtual, or cloud-based. 7 | 8 | Web Servers: Software like Apache or Nginx that handle HTTP requests, serving static content like HTML, CSS, and images to clients. 9 | 10 | Application Servers: Handle the execution of application logic, process dynamic content, and manage interactions between users and backend databases. 11 | 12 | Database Servers: Store and manage data needed by web applications, like user information, content, and transaction data. 13 | 14 | Network Infrastructure: Includes routers, switches, and load balancers to ensure smooth data flow and traffic management. 15 | 16 | DNS and Domain Management: Translates domain names into IP addresses, directing users to the correct server. 17 | 18 | Security Components: Firewalls, SSL/TLS encryption, and other security protocols to protect data and applications. 19 | 20 | Key Considerations: 21 | 22 | Scalability: Ability to handle increased load, often achieved through clustering, load balancing, or cloud-based solutions. 23 | Reliability: Ensuring uptime and consistent performance, often through redundant systems and backup strategies. 24 | Security: Protecting against threats and vulnerabilities, ensuring data integrity and privacy. 25 | Maintenance: Regular updates, backups, and monitoring for optimal performance. 26 | Challenges: 27 | 28 | Single Point of Failure (SPOF): Identifying and mitigating any single component whose failure could bring down the entire system. 29 | Traffic Management: Dealing with varying traffic loads efficiently. 30 | Cost Management: Balancing performance needs with budget constraints. 31 | In essence, web infrastructure design is about creating a robust, flexible, and secure environment for web applications, ensuring they perform well and are accessible to users at all times. 32 | -------------------------------------------------------------------------------- /0x0A-configuration_management/0-create_a_file.pp: -------------------------------------------------------------------------------- 1 | #Create a file in /tmp 2 | 3 | file { 'school': 4 | ensure => 'present', 5 | path => '/tmp/school', 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 | # install_flask.pp 2 | 3 | package { 'python3-pip': 4 | ensure => 'installed', 5 | } 6 | 7 | exec { 'install_flask': 8 | command => '/usr/bin/pip3 install Flask==2.1.0 Werkzeug==2.0.3', 9 | path => '/usr/bin', 10 | require => Package['python3-pip'], 11 | } 12 | -------------------------------------------------------------------------------- /0x0A-configuration_management/2-execute_a_command.pp: -------------------------------------------------------------------------------- 1 | #Kills a process named killmenow 2 | exec{'pkill -f killmenow': 3 | path => '/usr/bin/:/usr/local/bin/:/bin/' 4 | } 5 | -------------------------------------------------------------------------------- /0x0A-configuration_management/README.md: -------------------------------------------------------------------------------- 1 | Configuration Management (CM) is a discipline that ensures the consistency and integrity of a system or software product throughout its lifecycle. It involves the systematic management of configurations, including hardware, software, documentation, and any other components, to maintain a reliable and efficient system. 2 | 3 | Key Objectives: 4 | 5 | Version Control: 6 | 7 | CM involves versioning to track changes in the configuration items (CIs) over time. This allows for easy retrieval of previous versions and helps in identifying and resolving issues. 8 | Change Management: 9 | 10 | Ensures that changes to the system are controlled, documented, and implemented in a way that minimizes risk and maximizes benefits. This involves assessing the impact of changes and obtaining necessary approvals. 11 | Baseline Management: 12 | 13 | Establishing and maintaining baselines (snapshots) of the system at various points in its lifecycle. Baselines serve as reference points, facilitating reproducibility and ensuring that the system can be reconstructed in a known state. 14 | Traceability: 15 | 16 | CM provides traceability to link requirements, design, implementation, and testing artifacts. This traceability helps in understanding the impact of changes and ensures that every component aligns with the defined requirements. 17 | Auditing and Reporting: 18 | 19 | CM includes mechanisms for auditing changes and generating reports to provide visibility into the configuration status. This is crucial for compliance, quality assurance, and identifying trends or areas for improvement. 20 | Release Management: 21 | 22 | Coordinating the release of software or system updates in a controlled and efficient manner. This involves planning, scheduling, and deploying releases while minimizing disruptions to ongoing operations. 23 | Documentation Management: 24 | 25 | Managing documentation related to the configuration, including specifications, user manuals, and technical documentation. Ensures that documentation is consistent with the actual state of the system. 26 | Key Components: 27 | 28 | Configuration Items (CIs): 29 | 30 | These are the individual elements that make up the configuration, such as source code, libraries, hardware components, and documentation. 31 | Configuration Baselines: 32 | 33 | A set of configuration items that have been formally reviewed and agreed upon. Baselines provide a stable reference for future changes. 34 | Change Requests: 35 | 36 | Formal proposals for modifications to the configuration. These requests go through a defined change management process, including evaluation, approval, and implementation. 37 | Version Control System: 38 | 39 | Software tools that manage different versions of source code, documents, and other artifacts. Examples include Git, Subversion, and Mercurial. 40 | Audit Trail: 41 | 42 | A record of changes made to the configuration items, including who made the change, when it was made, and the nature of the change. 43 | Benefits of Configuration Management: 44 | 45 | Increased Stability and Reliability: 46 | 47 | CM ensures that changes are controlled and thoroughly tested, reducing the likelihood of introducing errors into the system. 48 | Efficient Collaboration: 49 | 50 | Version control and baseline management facilitate collaboration among development teams, allowing them to work on the same codebase simultaneously. 51 | Compliance and Documentation: 52 | 53 | Helps organizations meet regulatory requirements by providing accurate and up-to-date documentation of the system's configuration. 54 | Risk Mitigation: 55 | 56 | By tracking changes and maintaining baselines, CM minimizes the risk of system failures and makes it easier to identify and rectify issues. 57 | Improved Traceability: 58 | 59 | Provides a clear traceability matrix, linking requirements to design, implementation, and testing, aiding in better project management. 60 | In conclusion, Configuration Management is a critical aspect of software and system development, ensuring that changes are controlled, documented, and implemented in a systematic and organized manner, ultimately contributing to the success and reliability of a product or system. 61 | 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /0x0B-ssh/0-use_a_private_key: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #A script to connect to the remote server 3 | 4 | ssh -i ~/.ssh/school ubuntu@52.204.95.133 5 | -------------------------------------------------------------------------------- /0x0B-ssh/1-create_ssh_key_pair: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Define the key file name and passphrase 3 | KEY_FILE="school" 4 | BITS=4096 5 | PASSPHRASE="betty" 6 | 7 | # Check if the key file already exists 8 | if [ -e "$KEY_FILE" ]; then 9 | echo "Error: Key file '$KEY_FILE' already exists." 10 | exit 1 11 | fi 12 | 13 | # Generate the RSA key pair with the specified requirements 14 | ssh-keygen -t rsa -b "$BITS" -f "$KEY_FILE" -N "$PASSPHRASE" 15 | 16 | echo "RSA key pair created successfully." 17 | -------------------------------------------------------------------------------- /0x0B-ssh/100-puppet_ssh_config.pp: -------------------------------------------------------------------------------- 1 | # puppet script - configure ssh authentication: 2 | 3 | file_line { 'Turn off passwd auth': 4 | path => '/etc/ssh/ssh_config', 5 | line => 'PasswordAuthentication no', 6 | } 7 | 8 | file_line { 'Declare identity file': 9 | path => '/etc/ssh/ssh_config', 10 | line => 'IdentityFile ~/.ssh/school', 11 | } 12 | 13 | service { 'ssh': 14 | ensure => running, 15 | enable => true, 16 | } 17 | -------------------------------------------------------------------------------- /0x0B-ssh/2-ssh_config: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # uses ssh to connect to your server using 3 | #the private key ~/.ssh/school with the user ubuntu 4 | 5 | Host 208899-web-01 6 | HostName 52.204.95.133 7 | User ubuntu 8 | IdentityFile ~/.ssh/school 9 | PasswordAuthentication no 10 | -------------------------------------------------------------------------------- /0x0B-ssh/PasswordAuthentication no,: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nathanage3/alx-system_engineering-devops/7bc2a3060d7ed3740d86193f14573adbefbfad2e/0x0B-ssh/PasswordAuthentication no, -------------------------------------------------------------------------------- /0x0B-ssh/README.md: -------------------------------------------------------------------------------- 1 | hard readm 2 | -------------------------------------------------------------------------------- /0x0B-ssh/school: -------------------------------------------------------------------------------- 1 | -----BEGIN OPENSSH PRIVATE KEY----- 2 | b3BlbnNzaC1rZXktdjEAAAAACmFlczI1Ni1jdHIAAAAGYmNyeXB0AAAAGAAAABCXO34CB8 3 | g67XMEfuTZMmc0AAAAEAAAAAEAAAIXAAAAB3NzaC1yc2EAAAADAQABAAACAQDZy2HLI5/P 4 | DqQi8P8kLiSV9LWLImAkR1Vm7RmNTURTPdoly/KmnT9EZWWISn4glRlpgsrh6qsNkVKdhB 5 | gyBgWq068oXTA1F39PMUg+4v3h4Xl/jJURMJQoVfX89tSGJOR1x+pLmjhZJY0N8//jtsIP 6 | WheZDLXGBey4eJPLVwaEDVSWQUhrcL5MgwX/NpyUuTnKPPrwyi6upLGOptrZwMgLRNc17w 7 | ajEmRLlaP+v6O5w3EiSX8sTEom3+fRh//lSUn33EDDxEReIERYsiMKglyfw7l7x8A7Nqy1 8 | XaNbvdIZgtfk5u8pFbTPNxTeN4mMu7VB2+tpJDBvz+WYt8xa2Z2n9uKjORO/dZL63uJJcW 9 | UXJ4INW+4bOLJEEgZpSbgGWlSEEY0/QYYoXwEJvesvWxyQtb9Lp7rdozgChXLeYVJiIsEZ 10 | kj+7x1AmiR/ANHhACE/kq2Zu3Og7XtnIoDO4kADnhUjmgBlt84UX5IgWkx+ni86ywXVBXl 11 | h94t+jRJqRylOZ69HDg6sQdhCE7CihCc36s4gr43wxkszvbbQTwR9t6zj/h2WbswflSQRS 12 | wnPc4uth5BvinJ/MickMyyAENeoriGNB2e05XqSdecO/HSv1P0IIOhkbIoIKN4eeSIwMXd 13 | tZYopYohBK1lIywbVb3Ve+I9nifB1zls5hVqz4S5L0/wAAB1D8v+tm7BMoUehn8jwr99fq 14 | qZWhRKqfasfDp0xvOXL8z3MMCduSBFd0XQnZqSYr048w93fOXzKQdfTJIn6NbuepMXTxPA 15 | ACJ39rbx/40853GvvL7Z/Qcr6yCiuKqRuhdlg6Nb+G4KVASVGHxIQ36NnCpyEuch8toL+5 16 | 9pj2lF0Bw+yRTChC7+axqjJh3CketOspUCfXLPzUzapBGG9Otdb5UPIwhw4tKL0HqmrUIK 17 | lbGVm7I/IvpyWwW5+vosusAfv7/muiNibwjwwe7W0hTsg0qOD/PYGeAs34COUgrJu0fxNc 18 | MIyanFdK1yZLITNYPqK4dNW8+kcYYbXANllhmBVwL5jY8E34PiQhMujRGlYnlcRcE197QA 19 | 1rhZWrUNApTFBpwJ8FZjXnXD2g8fPBWu2dsxKs8lACeDz2WlUjDsDJmml7Rmr7XVISLam9 20 | 6qRE8mI6whIII5BN+17gjgNirzu40o91KhigFnMwAJ8Ov1cSg+14tiP70hO2aphYTZb9TL 21 | fzupMudL7/ciigrbV4LpDiRNSTyDOIeAHQxX67Oe0ngZ4U2jmX4ghnPC8HuHlpYUF6q9tN 22 | bxtVjv0ps5M1Fcroze6QYFidjNo03SJdqjnlRafPEPKFXkXUDV5Gxtg7Try8mdFD7WZgnQ 23 | TJtIIyJuseKb9J3bkMAAJciqv9mtdRbk5z+4/WWRzUxg3j4Q77j0JXjt3K4aX9DOFqlDQk 24 | IYIaqAaFXaK5cbE2SyGHRmHYKFq5LjxD3VgBcvLoUkNQh5lIqYo6ql55DmLKfCftZ0eTV1 25 | wf+x5X0v1ft8LSShyOwzExrIXxewU7nYd8/Nq6kPw70fIA91RaGngG/qqdttwp9EOQj/93 26 | uzh44Q4V02SJOow6O4GFStE5VqLbh3NuqFhjz1CV3ceRJyqQFa2t1i+eISCmfQ2HjsAUSr 27 | lrcXO4VUgAonrv66M7BvpqLf6153xghOPclLYD49T3q6vG0dPOJOa7FpslmPEXzhB8aRO9 28 | YZYw1lsQ2306X2Wbl43Tg4WHluT4+VXIOIMFHDX5gst7pgsm5GRZoStFFsYsQ8lnAUwd5I 29 | pDnIuEJ9fwwzE6gTt2xaZzB5uLjwaTEsEnauvyxmKMiT0404wmq4f5KPRK204aT68PExYE 30 | r3+d1qlec49pDYhzXo5grVvu3s1TggZfG2svBweMyznoZR+FsYar+QLoPMB75MG8iayoKV 31 | cYjlBrzE9vXp4P4+IoiEe+lZ56gj9QVOwMhWhoL8mUvNzF2Fqp4xEcwYQbc5cGhz3OOT0H 32 | vmRgJH/tm+bQAaZXRjmbZujluBRvGCobqrn8MmbbkIGe3+XMPH0HnFjHegSkbMjNTB32ad 33 | DPoh3CsHhf/mCssD3tFdNK2u4RqjxLcdEAb29eWe4SLat10Rod+AumlCESbaPttoqsbQIp 34 | SzhYVtFFpnDOpKycnc+DrRLvYpiJNWmUlMfNWa3yTTGRpNUra1XOiTr/qp1ASFHzGTd4Ia 35 | rr2oAXc/ZTjktRkh/AlfrKYL5LPWkXs1hf4zB4VT4ayDInEAsiE3cBD+YYyGox4MAO1tuH 36 | MUMvsGKRZhtzAnplcS75P6aat15vgt4s5IorBqPA5EIzfa453ijJNbq/pXLrq9hb3EEigB 37 | iQX+eqgaZz/hDP9ph9F1SyWaZUmmi8KJSVAsrhlG1V8miV3P4e7yANr8dHTXDB40IYzcjo 38 | wbQuNNd+eW9YjX9CNN3cNKxWDUNDl+4JE87UNTgKbvOWs4I8hAX4ojibKgogSzgVIjCpvs 39 | FePMwlbyW+4xlZXXq8abaYeLfLxk5S4cOZ8MZ2FxBN8cxAwzYlAVGnFXRf5sTHSMD6UwSW 40 | RUJ1LpzYF49f/OuKLzRALqNk5Nr85T+6B+KxUxuqoMzVNeZNUiV//BT0qfd4A0HyKCyVqi 41 | IzBHKmiYOZQtdkfX64TUN9PMmPVCUw7doCUzs2CNLSGAT4E3jAFCAfUjFZprgUgeprrJPQ 42 | Uea/xjExZJs8Y+Tuk0dIKHLcWeuhWRJ/ObgAE1kmKkPt1lzo+SdBcydcHv66L6RYaXL1sW 43 | d6elbALHo4CeF9RNOJGP2v9qeC7mx2nXkpgLPHTJTm8bwfkxdCUiMJB2PJ9mp3ZrpWGH8T 44 | 590ZMxYMzefgtAbMx8CyqYwKNCclZ19+Rg6l/8D/53v+4D3FK8cnaEpwlvu/JRS4hvXkxh 45 | fbN2/RGv1WJlc5wK8nl7T41CmesIXPqOAhBHBOtCbZFlq42+JuuUDpMnjl/hemFdSCVZ0e 46 | Q9N2ZhDHZC1PkpNscQwVnqUDc2sop8TSANVREAEZnDsHf0To7XPU4ByBN+1luXW5JxXOve 47 | 3wv8et4nYQSa7+P5MBS1IpY7eUKLmbUVk5un2+GkADKMWFa/EjwKnIS6lWj6SrimuCKN1C 48 | tUV8sgbIDuBZfuENVoCN20+NzvmqcEIRpeOHGNJ3MIJlTU6Rc81qOrktIwKZ0cxBnNOUi8 49 | G0O1GmkCfM9d8/8xUwZ1HIk4k= 50 | -----END OPENSSH PRIVATE KEY----- 51 | -------------------------------------------------------------------------------- /0x0B-ssh/school.pub: -------------------------------------------------------------------------------- 1 | ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDZy2HLI5/PDqQi8P8kLiSV9LWLImAkR1Vm7RmNTURTPdoly/KmnT9EZWWISn4glRlpgsrh6qsNkVKdhBgyBgWq068oXTA1F39PMUg+4v3h4Xl/jJURMJQoVfX89tSGJOR1x+pLmjhZJY0N8//jtsIPWheZDLXGBey4eJPLVwaEDVSWQUhrcL5MgwX/NpyUuTnKPPrwyi6upLGOptrZwMgLRNc17wajEmRLlaP+v6O5w3EiSX8sTEom3+fRh//lSUn33EDDxEReIERYsiMKglyfw7l7x8A7Nqy1XaNbvdIZgtfk5u8pFbTPNxTeN4mMu7VB2+tpJDBvz+WYt8xa2Z2n9uKjORO/dZL63uJJcWUXJ4INW+4bOLJEEgZpSbgGWlSEEY0/QYYoXwEJvesvWxyQtb9Lp7rdozgChXLeYVJiIsEZkj+7x1AmiR/ANHhACE/kq2Zu3Og7XtnIoDO4kADnhUjmgBlt84UX5IgWkx+ni86ywXVBXlh94t+jRJqRylOZ69HDg6sQdhCE7CihCc36s4gr43wxkszvbbQTwR9t6zj/h2WbswflSQRSwnPc4uth5BvinJ/MickMyyAENeoriGNB2e05XqSdecO/HSv1P0IIOhkbIoIKN4eeSIwMXdtZYopYohBK1lIywbVb3Ve+I9nifB1zls5hVqz4S5L0/w== root@ab4f4928422a 2 | -------------------------------------------------------------------------------- /0x0C-web_server/0-transfer_file: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #transfers a file from our client to a server: 3 | #Accepts 4 parameters 4 | #The path to the file to be transferred 5 | #The IP of the server we want to transfer the file to 6 | 7 | if [ "$#" -lt 4 ]; then 8 | echo "Usage: $0 PATH_TO_FILE IP USERNAME PATH_TO_SSH_KEY" 9 | exit 1 10 | fi 11 | 12 | # Assign parameters to variables 13 | file_path=$1 14 | server_ip=$2 15 | username=$3 16 | ssh_key_path=$4 17 | 18 | # Construct the SCP command 19 | scp -o StrictHostKeyChecking=no -i "$ssh_key_path" "$file_path" "$username@$server_ip":~/ 20 | 21 | # Check the exit status of the SCP command 22 | if [ "$?" -eq 0 ]; then 23 | echo "File transferred successfully." 24 | else 25 | echo "Error transferring the file." 26 | fi 27 | -------------------------------------------------------------------------------- /0x0C-web_server/1-install_nginx_web_server: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # bash: script install and configure Nginx web server: 3 | apt-get update 4 | 5 | # Install nginx 6 | apt-get install -y nginx 7 | 8 | # Create a basic HTML file with "Hello World!" 9 | echo "
Hello World!" > /var/www/html/index.html 10 | 11 | # Configure Nginx to listen on port 80 and serve the HTML file 12 | echo "server { 13 | listen 80; 14 | server_name localhost; 15 | 16 | location / { 17 | root /var/www/html; 18 | index index.html; 19 | } 20 | }" > /etc/nginx/sites-available/default 21 | 22 | # Restart Nginx (without using systemctl) 23 | kill -s HUP $(cat /var/run/nginx.pid) 24 | 25 | # Done 26 | echo "Nginx installed and configured. You can test by running 'curl localhost'." -------------------------------------------------------------------------------- /0x0C-web_server/2-setup_a_domain_name: -------------------------------------------------------------------------------- 1 | anbesa.tech 2 | -------------------------------------------------------------------------------- /0x0C-web_server/3-redirection: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Create the necessary directories if they don't exist 4 | mkdir -p /data/ 5 | mkdir -p /data/web_static/ 6 | mkdir -p /data/web_static/releases/ 7 | mkdir -p /data/web_static/shared/ 8 | mkdir -p /data/web_static/releases/test/ 9 | 10 | # Create a fake HTML file for testing 11 | echo "Hello, world!" > /data/web_static/releases/test/index.html 12 | 13 | # Create a symbolic link 14 | ln -sf /data/web_static/releases/test/ /data/web_static/current 15 | 16 | # Set ownership and permissions 17 | chown -R ubuntu:ubuntu /data/ 18 | chmod -R 755 /data/ 19 | 20 | # Update the Nginx configuration 21 | config_file="/etc/nginx/sites-available/default" 22 | 23 | # Remove any existing configuration related to serving the static content 24 | sed -i '/location \/hbnb_static/ d' "$config_file" 25 | 26 | # Add the new configuration for serving the static content 27 | echo " 28 | location /hbnb_static { 29 | alias /data/web_static/current/; 30 | index index.html; 31 | }" >> "$config_file" 32 | 33 | # Restart Nginx 34 | service nginx restart -------------------------------------------------------------------------------- /0x0C-web_server/4-not_found_page_404: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #Configure your Nginx server to have a custom 404 page that contains the string Ceci n'est pas une page. 3 | 4 | STRING="Hello World!" 5 | 6 | REDIRECT="\n\tlocation /redirect_me {\n\t\treturn 301 https://youtu.be/dQw4w9WgXcQ;\n\t}\n" 7 | FILE="/etc/nginx/sites-available/default" 8 | 9 | ERRORFILE="/usr/share/nginx/html/404error.html" 10 | FOUR="Ceci n'est pas une page" 11 | ERRORREDIRECT="\n\terror_page 404 /404error.html;\n\tlocation = /404error.html {\n\t\troot /usr/share/nginx/html;\n\t\tinternal;\n\t}\n" 12 | 13 | apt-get -y update 14 | apt-get -y install nginx 15 | ufw allow 'Nginx HTTP' 16 | sudo echo "$STRING" > /var/www/html/index.nginx-debian.html 17 | sed -i "37i\ $REDIRECT" "$FILE" 18 | 19 | echo "$FOUR" > "$ERRORFILE" 20 | sed -i "37i\ $ERRORREDIRECT" "$FILE" 21 | 22 | service nginx restart -------------------------------------------------------------------------------- /0x0C-web_server/7-puppet_install_nginx_web_server.pp: -------------------------------------------------------------------------------- 1 | #setup nginx 2 | 3 | package { 4 | 'nginx': 5 | ensure => installed, 6 | } 7 | 8 | file {'/var/www/html/index.nginx-debian.html': 9 | content => 'Hello World!', 10 | } 11 | 12 | file_line {'configure redirection': 13 | path => '/etc/nginx/sites-available/default', 14 | after => 'server_name _;', 15 | line => "\n\tlocation /redirect_me {\n\t\treturn 301 https://youtu.be/dQw4w9WgXcQ;\n\t}\n", 16 | } 17 | 18 | service {'nginx': 19 | ensure => running, 20 | } -------------------------------------------------------------------------------- /0x0C-web_server/README.md: -------------------------------------------------------------------------------- 1 | Web Server Basics 2 | Definition: 3 | A web server is a software application or hardware device that stores, processes, and delivers web content to clients over the Internet. It plays a fundamental role in enabling the accessibility of websites and web applications. 4 | 5 | Key Components: 6 | 1. HTTP (Hypertext Transfer Protocol): 7 | The foundation of communication on the World Wide Web. 8 | Facilitates the exchange of information between clients (web browsers) and servers. 9 | 2. Server Software: 10 | Examples include Apache, Nginx, Microsoft IIS, and others. 11 | Responsible for handling incoming requests, processing them, and delivering the appropriate response. 12 | 3. Document Root: 13 | The main directory on the server where web content (HTML, CSS, images, etc.) is stored. 14 | Clients access content by requesting specific files within this directory. 15 | 4. IP Address and Domain Name: 16 | Servers are identified on the Internet by their IP addresses. 17 | Domain names provide human-readable aliases for IP addresses. 18 | 5. Port: 19 | Servers listen on specific ports for incoming connections. 20 | Default HTTP port is 80; HTTPS uses port 443. 21 | 6. Protocols: 22 | HTTPS (HTTP Secure) encrypts data during transmission, enhancing security. 23 | SSL/TLS protocols are commonly used for secure communication. 24 | Server-Side Scripting and Databases: 25 | 1. Server-Side Scripting: 26 | Dynamic content generation using server-side languages (e.g., PHP, Python, Ruby). 27 | Allows customization of content based on user requests. 28 | 2. Databases: 29 | Storage and retrieval of data to support dynamic web applications. 30 | Common databases include MySQL, PostgreSQL, and MongoDB. 31 | Security Considerations: 32 | 1. Firewalls and Security Software: 33 | Protects the server from unauthorized access and malicious activities. 34 | 2. Regular Software Updates: 35 | Ensures that the server software and operating system have the latest security patches. 36 | 3. Access Controls: 37 | Restricts access to sensitive files and directories. 38 | Uses authentication mechanisms to verify user identity. 39 | Scalability: 40 | 1. Load Balancing: 41 | Distributes incoming traffic across multiple servers to optimize performance and prevent overload. 42 | 2. Caching: 43 | Stores frequently accessed content to reduce server load and improve response times. 44 | Monitoring and Logging: 45 | 1. Log Files: 46 | Record information about server activity, errors, and user interactions. 47 | Essential for troubleshooting and performance analysis. 48 | 2. Monitoring Tools: 49 | Keep track of server health, resource usage, and potential issues. 50 | Examples include Nagios, New Relic, and Prometheus. 51 | -------------------------------------------------------------------------------- /0x0C-web_server/some_page.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nathanage3/alx-system_engineering-devops/7bc2a3060d7ed3740d86193f14573adbefbfad2e/0x0C-web_server/some_page.html -------------------------------------------------------------------------------- /0x0D-web_stack_debugging_0/0-give_me_a_page: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Fix Apache not serving the expected page 3 | 4 | # Start the Docker container with port mapping 5 | docker run -p 8080:80 -d -it holbertonschool/265-0 6 | 7 | # Connect to the running container 8 | docker exec -it