├── 0x00-shell_basics ├── 0-current_working_directory ├── 1-listit ├── 10-back ├── 100-lets_move ├── 101-clean_emacs ├── 102-tree ├── 103-commas ├── 11-lists ├── 12-file_type ├── 13-symbolic_link ├── 14-copy_html ├── 2-bring_me_home ├── 3-listfiles ├── 4-listmorefiles ├── 5-listfilesdigitonly ├── 6-firstdirectory ├── 7-movethatfile ├── 8-firstdelete ├── 9-firstdirdeletion ├── README.md └── school.mgc ├── 0x01-shell_permissions ├── 0-iam_betty ├── 1-who_am_i ├── 10-mirror_permissions ├── 100-change_owner_and_group ├── 101-symbolic_link_permissions ├── 102-if_only ├── 103-Star_Wars ├── 11-directories_permissions ├── 12-directory_permissions ├── 13-change_group ├── 2-groups ├── 3-new_owner ├── 4-empty ├── 5-execute ├── 6-multiple_permissions ├── 7-everybody ├── 8-James_Bond ├── 9-John_Doe └── README.md ├── 0x02-shell_redirections ├── 0-hello_world ├── 1-confused_smiley ├── 10-no_more_js ├── 100-empty_casks ├── 101-gifs ├── 102-acrostic ├── 103-the_biggest_fan ├── 11-directories ├── 12-newest_files ├── 13-unique ├── 14-findthatword ├── 15-countthatword ├── 16-whatsnext ├── 17-hidethisword ├── 18-letteronly ├── 19-AZ ├── 2-hellofile ├── 20-hiago ├── 21-reverse ├── 22-users_and_homes ├── 3-twofiles ├── 4-lastlines ├── 5-firstlines ├── 6-third_line ├── 7-file ├── 8-cwd_state ├── 9-duplicate_last_line └── README.md ├── 0x03-shell_variables_expansions ├── 0-alias ├── 1-hello_you ├── 10-love_exponent_breath ├── 100-decimal_to_hexadecimal ├── 101-rot13 ├── 102-odd ├── 103-water_and_stir ├── 11-binary_to_decimal ├── 12-combinations ├── 13-print_float ├── 2-path ├── 3-paths ├── 4-global_variables ├── 5-local_variables ├── 6-create_local_variable ├── 7-create_global_variable ├── 8-true_knowledge ├── 9-divide_and_rule └── README.md ├── 0x04-loops_conditions_and_parsing ├── 0-RSA_public_key.pub ├── 1-for_best_school ├── 10-fizzbuzz ├── 100-read_and_cut ├── 101-tell_the_story_of_passwd ├── 102-lets_parse_apache_logs ├── 103-dig_the-data ├── 2-while_best_school ├── 3-until_best_school ├── 4-if_9_say_hi ├── 5-4_bad_luck_8_is_your_chance ├── 6-superstitious_numbers ├── 7-clock ├── 8-for_ls ├── 9-to_file_or_not_to_file └── README.md ├── 0x05-processes_and_signals ├── 0-what-is-my-pid ├── 1-list_your_processes ├── 100-process_and_pid_file ├── 101-manage_my_process ├── 102-zombie.c ├── 2-show_your_bash_pid ├── 3-show_your_bash_pid_made_easy ├── 4-to_infinity_and_beyond ├── 5-dont_stop_me_now ├── 6-stop_me_if_you_can ├── 7-highlander ├── 8-beheaded_process ├── README.md ├── manage_my_process └── zombie ├── 0x06-regular_expressions ├── 0-simply_match_school.rb ├── 1-repetition_token_0.rb ├── 100-textme.rb ├── 2-repetition_token_1.rb ├── 3-repetition_token_2.rb ├── 4-repetition_token_3.rb ├── 5-beginning_and_end.rb ├── 6-phone_number.rb ├── 7-OMG_WHY_ARE_YOU_SHOUTING.rb ├── README.md └── example.rb ├── 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 ├── 0x0A-configuration_management ├── 0-create_a_file.pp ├── 1-install_a_package.pp ├── 2-execute_a_command.pp ├── README.md └── killmenow ├── 0x0B-ssh ├── 0-use_a_private_key ├── 1-create_ssh_key_pair ├── 100-puppet_ssh_config.pp ├── 2-ssh_config └── README.md ├── 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 ├── 1-install_load_balancer ├── 2-puppet_custom_http_response-header.pp └── README.md ├── 0x10-https_ssl ├── 0-world_wide_web ├── 1-haproxy_ssl_termination ├── 100-redirect_http_to_https └── README.md ├── 0x11-what_happens_when_your_type_google_com_in_your_browser_and_press_enter ├── 0-blog_post ├── 1-what_happen_when_diagram ├── 2-contribution-to_what-happens-when_github_answer └── README.md ├── 0x12-web_stack_debugging_2 ├── 0-iamsomeonelese ├── 1-run_nginx_as_nginx ├── 100-fix_in_7_lines_or_less └── README.md ├── 0x13-firewall ├── 0-block_all_incoming_traffic_but ├── 100-port_forwarding └── README.md ├── 0x14-mysql ├── 4-mysql_configuration_primary ├── 4-mysql_configuration_replica ├── 5-mysql_backup └── README.md ├── 0x15-api ├── 0-gather_data_from_an_API.py ├── 1-export_to_CSV.py ├── 2-export_to_JSON.py ├── 3-dictionary_of_list_of_dictionaries.py └── README.md └── README.md /0x00-shell_basics/0-current_working_directory: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | pwd 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/1-listit: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ls 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/10-back: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd - 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/100-lets_move: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | mv [[:upper:]]* /tmp/u 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/101-clean_emacs: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | rm *~ 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/102-tree: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | mkdir -p welcome/to/school 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/103-commas: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ls -map 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/11-lists: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ls -al . .. /boot 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/12-file_type: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | file /tmp/iamafile 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/13-symbolic_link: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ln -s /bin/ls __ls__ 3 | -------------------------------------------------------------------------------- /0x00-shell_basics/14-copy_html: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cp -R *.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 2 | ## I learned 3 | 4 | 5 | ### What is the Shell 6 | * What is the shell 7 | * What is the difference between a terminal and a shell 8 | * What is the shell prompt 9 | * How to use the history (the basics) 10 | ### Navigation 11 | * What do the commands or built-ins cd, pwd, ls, ls -l, ls -la do 12 | * How to navigate the filesystem 13 | * What are the . and .. directories 14 | * What is the working directory, how to print it and how to change it 15 | * What is the root directory 16 | * What is the home directory, and how to go there 17 | * What is the difference between the root directory and the home directory of the user root 18 | * What are the characteristics of hidden files and how to list them 19 | * What does the command cd - do 20 | ### Looking Around 21 | * What do the commands ls, less, file do 22 | * How do you use options and arguments with commands 23 | * What does the ln command do 24 | * What do you find in the most common/important directories 25 | ### Manipulating Files 26 | * What do the commands cp, mv, rm, mkdir do 27 | * What are wildcards and how do they work 28 | * How to use wildcards 29 | ### Working with Commands 30 | * What do type, which, help, man commands do 31 | * What are the different kinds of commands 32 | * What is an alias 33 | * When do you use the command help instead of man 34 | ### Reading Man Pages 35 | * How to read a man page 36 | * What are man page sections 37 | ### Genereal 38 | * What does LTS mean? 39 | * What does RTFM mean? 40 | * What is a Shebang 41 | 42 | 43 | 44 |

Connect with me:

45 |

46 | techbydami 47 | agboola-olawale-damilola-7b2132246 48 | 19747131 49 | techbydami 50 | @techbydami 51 | techbydami 52 | 5007 53 |

54 | -------------------------------------------------------------------------------- /0x00-shell_basics/school.mgc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TechByDami/alx-system_engineering-devops/908fb5b0bd20ce2571c070ab876dff54173442e2/0x00-shell_basics/school.mgc -------------------------------------------------------------------------------- /0x01-shell_permissions/0-iam_betty: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | su betty 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/1-who_am_i: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 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: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chown -h vincent:staff _hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/102-if_only: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chown --from=guillaume betty hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/103-Star_Wars: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | telnet towel.blinkenlights.nl 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/11-directories_permissions: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chmod ugo+x */ 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/12-directory_permissions: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | mkdir -m 751 my_dir 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/13-change_group: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chgrp school hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/2-groups: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | groups 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/3-new_owner: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chown betty hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/4-empty: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | touch hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/5-execute: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chmod u+x hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/6-multiple_permissions: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chmod u+x,g+x,o+r hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/7-everybody: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chmod ugo+x hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/8-James_Bond: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chmod 007 hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/9-John_Doe: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | chmod 753 hello 3 | -------------------------------------------------------------------------------- /0x01-shell_permissions/README.md: -------------------------------------------------------------------------------- 1 | ## 0x01. Shell, permissions 2 | 3 | ![permussion ](https://user-images.githubusercontent.com/110563322/188001806-1060b5aa-30ac-4c83-b06c-27485abc3b39.jpg) 4 | 5 | [0-iam_betty](./0-iam_betty) - Create a script that switch the current user to the user betty. 6 | You should use exactly 8 characters for your command (+1 character for the new line). 7 | You can assume that the user betty will exist when we will run your script 8 | 9 | [1-who_am_i](./1-who_am_i) - Write a script that prints the effective user of the current user. 10 | 11 | [2-groups](./2-groups) - Write a script that prints all the groups the current user is part of. 12 | 13 | [3-new_owner](./3-new_owner) - Write a script that changes the owner of the file hello to the user betty. 14 | 15 | [4-empty](./4-empty) - Write a script that creates an empty file called hello. 16 | 17 | [5-execute](./5-execute) - Write a script that adds execute permission to the owner of the file hello. 18 | The file hello will be in the working directory 19 | 20 | [6-multiple_permissions](./6-multiple_permissions) - Write a script that adds execute permission to the owner and the group owner, and read permission to other users, to the file hello. 21 | The file hello will be in the working directory. 22 | 23 | ![permission](https://user-images.githubusercontent.com/110563322/188001858-e47b0197-4b1a-4f8d-924e-3350da08d874.png) 24 | 25 | [7-everybody](./7-everybody) - Write a script that adds execution permission to the owner, the group owner and the other users, to the file hello. 26 | The file hello will be in the working directory, You are not allowed to use commas for this script 27 | 28 | [8-James_Bond](./8-James_Bond) - Write a script that sets the permission to the file hello as follows: 29 | Owner: no permission at all 30 | Group: no permission at all 31 | Other users: all the permissions 32 | The file hello will be in the working directory You are not allowed to use commas for this script 33 | 34 | [9-John_Doe](./9-John_Doe) - Write a script that sets the mode of the file hello to this: 35 | -rwxr-x-wx 1 julien julien 23 Sep 20 14:25 hello 36 | The file hello will be in the working directory 37 | You are not allowed to use commas for this script 38 | 39 | 40 | ![number permission](https://user-images.githubusercontent.com/110563322/188002135-aa5f3bd3-2e33-4f95-bfa9-e2726451ee43.png) 41 | 42 | [10-mirror_permissions](./10-mirror_permissions) - Write a script that sets the mode of the file hello the same as olleh’s mode. 43 | The file hello will be in the working directory 44 | The file olleh will be in the working directory 45 | 46 | [11-directories_permissions](./11-directories_permissions) - Create a script that adds execute permission to all subdirectories of the current directory for the owner, the group owner and all other users. Regular files should not be changed. 47 | 48 | [12-directory_permissions](./12-directory_permissions) - Create a script that creates a directory called my_dir with permissions 751 in the working directory. 49 | 50 | [13-change_group](./13-change_group) - Write a script that changes the group owner to school for the file hello 51 | The file hello will be in the working directory 52 | 53 | [100-change_owner_and_group](./100-change_owner_and_group) - Write a script that changes the owner to vincent and the group owner to staff for all the files and directories in the working directory. 54 | 55 | [101-symbolic_link_permissions](./101-symbolic_link_permissions) - Write a script that changes the owner and the group owner of the file _hello to vincent and staff respectively. 56 | The file _hello is in the working directory 57 | The file _hello is a symbolic link 58 | 59 | [102-if_only](./102-if_only) - Write a script that changes the owner of the file hello to betty only if it is owned by the user guillaume. 60 | The file hello will be in the working directory 61 | 62 | [103-Star_Wars](./103-Star_Wars) - Write a script that will play the StarWars IV episode in the terminal. 63 | 64 | 65 | 66 |

Connect with me:

67 |

68 | techbydami 69 | agboola-olawale-damilola-7b2132246 70 | 19747131 71 | techbydami 72 | @techbydami 73 | techbydami 74 | 5007 75 |

76 | 77 | -------------------------------------------------------------------------------- /0x02-shell_redirections/0-hello_world: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "Hello, World" 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/1-confused_smiley: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "\"(Ôo)'" 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/10-no_more_js: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | find . -type f -name '*.js' -delete 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/100-empty_casks: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | find . -empty -printf "%f\n" 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/101-gifs: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | find . -type f -name "*.gif" -printf "%f\n" | rev | cut -d '.' -f2- | rev | LC_ALL=C sort -f 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/102-acrostic: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "$(cut -c 1 | tr -d '\n')" 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/103-the_biggest_fan: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | tail -n +2 | cut -f 1 | sort | uniq -c | sort -nr | head -11 | cut -c 9- 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/11-directories: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | find . -mindepth 1 -type d | wc -l 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/12-newest_files: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ls -t1 | head -n 10 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/13-unique: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | sort | uniq -u 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/14-findthatword: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | egrep 'root' /etc/passwd 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/15-countthatword: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | egrep -c 'bin' /etc/passwd 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/16-whatsnext: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | egrep -A 3 'root' /etc/passwd 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/17-hidethisword: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | egrep -v 'bin' /etc/passwd 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/18-letteronly: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | egrep ^[[:alpha:]] /etc/ssh/sshd_config 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/19-AZ: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | tr 'A' 'Z' | tr 'c' 'e' 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/2-hellofile: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cat /etc/passwd 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/20-hiago: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | tr -d "cC" 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/21-reverse: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | rev 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/22-users_and_homes: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cut -f 1,6 -d ':' /etc/passwd | sort 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/3-twofiles: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cat /etc/passwd /etc/hosts 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/4-lastlines: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | tail -n 10 /etc/passwd 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/5-firstlines: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | head -n 10 /etc/passwd 3 | -------------------------------------------------------------------------------- /0x02-shell_redirections/6-third_line: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | head -n3 iacta |tail -n1 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 | ## 0x02. Shell, I/O Redirections and filters 2 | 3 | [0-hello_world](./0-hello_world) - Write a script that prints “Hello, World”, followed by a new line to the standard output. 4 | 5 | [1-confused_smiley](./1-confused_smiley) - Write a script that displays a confused smiley "(Ôo)'. 6 | 7 | [2-hellofile](./2-hellofile) - Display the content of the /etc/passwd file. 8 | 9 | [3-twofiles](./3-twofiles) - Display the content of /etc/passwd and /etc/hosts 10 | 11 | [4-lastlines](./4-lastlines) - Display the last 10 lines of /etc/passwd 12 | 13 | [5-firstlines](./5-firstlines) - Display the first 10 lines of /etc/passwd 14 | 15 | [6-third_line](./6-third_line) - Write a script that displays the third line of the file iacta. 16 | The file iacta will be in the working directory. 17 | You’re not allowed to use sed 18 | 19 | [7-file](./7-file) - Write a shell script that creates a file named exactly \*\\'"Best School"\'\\*$\?\*\*\*\*\*:) containing the text Best School ending by a new line. 20 | 21 | [8-cwd_state](./8-cwd_state) - Write a script that writes into the file ls_cwd_content the result of the command ls -la. If the file ls_cwd_content already exists, it should be overwritten. If the file ls_cwd_content does not exist, create it. 22 | 23 | [9-duplicate_last_line](./9-duplicate_last_line) - Write a script that duplicates the last line of the file iacta 24 | The file iacta will be in the working directory 25 | 26 | [10-no_more_js](./10-no_more_js)- Write a script that deletes all the regular files (not the directories) with a .js extension that are present in the current directory and all its subfolders. 27 | 28 | [11-directories](./11-directories) - Write a script that counts the number of directories and sub-directories in the current directory. 29 | The current and parent directories should not be taken into account 30 | Hidden directories should be counted 31 | 32 | [12-newest_files](./12-newest_files) - Create a script that displays the 10 newest files in the current directory. 33 | Requirements: 34 | One file per line 35 | Sorted from the newest to the oldest 36 | 37 | [13-unique](./13-unique) - Create a scripts that takes a list of words as input and prints only words that appear exactly once. 38 | Input format: One line, one word 39 | Output format: One line, one word 40 | Words should be sorted 41 | 42 | [14-findthatword](./14-findthatword) - Display lines containing the pattern “root” from the file /etc/passwd (grep it) 43 | 44 | [15-countthatword](./15-countthatword) - Display the number of lines that contain the pattern “bin” in the file /etc/passwd 45 | 46 | [16-whatsnext](./16-whatsnext) - Display lines containing the pattern “root” and 3 lines after them in the file /etc/passwd. 47 | 48 | [17-hidethisword](./17-hidethisword) - Display all the lines in the file /etc/passwd that do not contain the pattern “bin”. 49 | 50 | [18-letteronly](./18-letteronly) - Display all lines of the file /etc/ssh/sshd_config starting with a letter. 51 | include capital letters as well 52 | 53 | [19-AZ](./19-AZ) - Replace all characters A and c from input to Z and e respectively. 54 | 55 | [20-hiago](./20-hiago) - Create a script that removes all letters c and C from input. 56 | 57 | [21-reverse](./21-reverse) - Write a script that reverse its input. 58 | 59 | [22-users_and_homes](./22-users_and_homes) - Write a script that displays all users and their home directories, sorted by users. 60 | Based on the the /etc/passwd file 61 | 62 | [100-empty_casks](./100-empty_casks) - Write a command that finds all empty files and directories in the current directory and all sub-directories. 63 | Only the names of the files and directories should be displayed (not the entire path) 64 | Hidden files should be listed 65 | One file name per line 66 | The listing should end with a new line 67 | You are not allowed to use basename, grep, egrep, fgrep or rgrep 68 | 69 | [101-gifs](./101-gifs) - Write a script that lists all the files with a .gif extension in the current directory and all its sub-directories. 70 | Hidden files should be listed 71 | Only regular files (not directories) should be listed 72 | The names of the files should be displayed without their extensions 73 | The files should be sorted by byte values, but case-insensitive (file aaa should be listed before file bbb, file .b should be listed before file a, and file Rona should be listed after file jay) 74 | One file name per line 75 | The listing should end with a new line 76 | You are not allowed to use basename, grep, egrep, fgrep or rgrep 77 | 78 | [102-acrostic](./102-acrostic) - An acrostic is a poem (or other form of writing) in which the first letter (or syllable, or word) of each line (or paragraph, or other recurring feature in the text) spells out a word, message or the alphabet. The word comes from the French acrostiche from post-classical Latin acrostichis). As a form of constrained writing, an acrostic can be used as a mnemonic device to aid memory retrieval. Read more. 79 | Create a script that decodes acrostics that use the first letter of each line. 80 | The ‘decoded’ message has to end with a new line 81 | You are not allowed to use grep, egrep, fgrep or rgrep 82 | 83 | [103-the_biggest_fan](./103-the_biggest_fan) - Write a script that parses web servers logs in TSV format as input and displays the 11 hosts or IP addresses which did the most requests. 84 | Order by number of requests, most active host or IP at the top 85 | You are not allowed to use grep, egrep, fgrep or rgrep 86 | 87 | 88 | 89 | 90 | 91 |

Connect with me:

92 |

93 | techbydami 94 | agboola-olawale-damilola-7b2132246 95 | 19747131 96 | techbydami 97 | @techbydami 98 | techbydami 99 | 5007 100 |

101 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/0-alias: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | alias ls="rm *" 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/1-hello_you: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "hello $USER" 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/10-love_exponent_breath: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo $((BREATH**LOVE)) 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/100-decimal_to_hexadecimal: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | printf "%x\n" $DECIMAL 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/101-rot13: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | tr 'A-Za-z' 'N-ZA-Mn-za-m' 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/102-odd: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | paste -d, - - | cut -d, -f1 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/103-water_and_stir: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo $(printf %o $(($((5#$(echo $WATER | tr 'water' '01234'))) + $((5#$(echo $STIR | tr 'stir.' '01234'))))) | tr '01234567' 'bestchol') 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/11-binary_to_decimal: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo $((2#$BINARY)) 3 | -------------------------------------------------------------------------------- /0x03-shell_variables_expansions/12-combinations: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo {a..z}{a..z} | tr " " "\n" | egrep -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 | # 0x03 Shell, init files, variables and expansions 3 | 4 | ## Resources 5 | 6 | - Shell [Expansion](http://linuxcommand.org/lc3_lts0080.php). 7 | - Shell [Arithmetic](https://www.gnu.org/software/bash/manual/html_node/Shell-Arithmetic.html). 8 | - Bash [Variable](https://tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_02.html). 9 | - Bash [Shell initialization files](https://tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_01.html). 10 | - [The alias Command](http://www.linfo.org/alias.html). 11 | 12 | ## Tasks 13 | 14 | 0. [\](./0-alias) : A script that creates an alias. 15 | - Name of alias: `ls` 16 | - Value: `rm *` 17 | 18 | 1. [Hello you](./1-hello_you) : A script that prints `hello user`, where user is the current Linux user. 19 | 20 | 2. [The path to success is to take massive, determined action](./2-path) : A script that adds `/action` to the `PATH`. `/action` should be the last directory the shell looks into when looking for a program. 21 | 22 | 3. [If the path be beautiful, let us not ask where it leads](./3-paths) : A script that counts the number of directories in the `PATH`. 23 | 24 | 4. [Global variables](./4-global_variables) : A script that prints all the enviroment variables. 25 | 26 | 5. [Local variables ](./5-local_variables) : A script that lists all local variables and enviroment variables, and functions. 27 | 28 | 6. [Local variable](./6-create_local_variable) : A script that creates a new local variable. 29 | - Name : `BEST` 30 | - Value : `School` 31 | 32 | 7. [Global variable](./7-create_global_variable) : A script that creates a new global variable. 33 | - Name : `BEST` 34 | - Value : `School` 35 | 36 | 8. [Every addition to true knowledge is an addition to human power](./8-true_knowledge) : A script that prints the results of the addition of 128 with the value stored in the enviroment variable `TRUEKNOWLEDGE`, followed by a new line. 37 | 38 | 9. [Divide and rule](./9-divide_and_rule) : A script that prints the result of `POWER` divide by `DIVIDE`, followed by a new line. 39 | - `POWER` and `DIVIDE` are environment variables. 40 | 41 | 10. [Love is anterior to life, posterior to death, initial of creation, and the exponent of breath](./10-love_exponent_breath) : A script that displays the result of `BREATH` to the power of `LOVE`. 42 | - `BREATH` and `LOVE` are enviroment variables. 43 | - The script should display the result, followed by a new line. 44 | 45 | 11. [There are 10 types of people in the world -- Those who understand binary, and those who don't](./11-binary_to_decimal) : A script that converts a number from base 2 to base 10. 46 | - The number in base 2 is stored in the enviroment variable `BINARY`. 47 | - The script should display the number in base 10, followed by a new line. 48 | 49 | 12. [Combination](./12-combinations) : A script that prints all possible combinations of two letters, except `oo`. 50 | - Letters are lower cases, from `a` to `z`. 51 | - One combination per line. 52 | - The output should be alpha ordered, starting with `aa`. 53 | - Do not print `oo`. 54 | - Your script file should contain maximum 64 characters. 55 | 56 | 13. [Floats](./13-print_float) : A script that prints a number with two decimal places, followed by a new line. 57 | - The number will be stored in the enviroment variable `NUM`. 58 | 59 | 14. [Decimal to Hexadecimal](./100-decimal_to_hexadecimal) : A script that converts a number from base 10 to base 16. 60 | - The number is base 10 is stored in the enviroment variable `DECIMAL`. 61 | - The script should display the number in base 16, followed by a new line. 62 | 63 | 15. [Everyone is a proponent of strong encryption](./101-rot13) : A script that encodes and decodes text using the rot13 encryption. Assume ASCII. 64 | 65 | 16. [The eggs of the brood need to be an odd number](./102-odd) : A script that prints every other line from the input, starting with the first line. 66 | 67 | 17. [I'm an instant star. Just add water and stir.](./103-water_and_stir) : A script that adds the two numbers stored in the enviroment variables `WATER` and `STIR` and prints the results. 68 | - `WATER` is in base `water`. 69 | - `STIR` is in base `stir`. 70 | - The result should be in base `bestchol`. 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 |

Connect with me:

79 |

80 | techbydami 81 | agboola-olawale-damilola-7b2132246 82 | 19747131 83 | techbydami 84 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/0-RSA_public_key.pub: -------------------------------------------------------------------------------- 1 | ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDW1InM0YRi7dmLpkO/4tzxfV0DcSA7hKPIx7XY+nIZoxUIHPO+pa8S0Buv7n6RHnoOhxAQs1AgIBa3BXzxjBkJE+NZWWPlSGwqELYbljo5ZMeknwFf4NDpOrLyhW1/NrYtiabIzGjPow2LItpL2bSupJW3kjffQO7KTRn4MJ8eK2IlCD/EA5nvm5hkp2/Qj0gqoSWsBvYIpWD8fHdxIMjhdzlcqx+VZ/1/BJfqs3H7jD62reVIrACEdT90dZbWe6Pj6D07wJKd56VV/9CdIGLYuzjkwBjQg54F7AV/xEsOlRMb4Sinh3TsumVQwwwVnNBUuukW+1AhQ2oiONg+QUcq0UIQRdE3VIKOn73ug0oOsUZy95q6y3vmMNijXwP2PkG4Ixa/t9qByXt4RdboG7mMXzawvrt9hXM/lehnPIgUhO7Ki8e/Y4486P3aZ3oL7Vd6IPmwC+RKE1EWOpQgHxZybtwDBYh24S5bfit4goBQRnZXa+OTIc8xIe0Nz+Xo9M0= firdaus@Firdaus-PC -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/1-for_best_school: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays 'Best School' in stdout 10 times 3 | 4 | for (( i=0; i<10; i++ )) 5 | do 6 | echo "Best School" 7 | done 8 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/10-fizzbuzz: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays numbers from 1 to 100 in list format. 3 | # Displays "FizzBuzz" when the number is a multiple of 3 and 5. 4 | # Displays "Fizz" when the number is a multiple of 3. 5 | # Displays "Buzz" when the number is a multiple of 5. 6 | # Otherwise, displays the number. 7 | 8 | for num in {1..100} 9 | do 10 | if (( num % 3 == 0 && num % 5 == 0 )) 11 | then 12 | echo "FizzBuzz" 13 | elif (( num % 3 == 0 )) 14 | then 15 | echo "Fizz" 16 | elif (( num % 5 == 0 )) 17 | then 18 | echo "Buzz" 19 | else 20 | echo "$num" 21 | fi 22 | done 23 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/100-read_and_cut: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays the contents of the file `/etc/passwd`. 3 | # Only displays the username, user id, and user home directory path. 4 | 5 | while read -r passwd; do 6 | echo "$passwd" | cut -d ':' -f1,3,6 7 | done < "/etc/passwd" 8 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/101-tell_the_story_of_passwd: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Tells a story based on the contents of the `/etc/passwd` file. 3 | 4 | while IFS=':' read -r username password uid gid info home shell; do 5 | echo "The user $username is part of the $gid gang,"\ 6 | "lives in $home and rides $shell."\ 7 | "$uid's place is protected by the passcode $password,"\ 8 | "more info about the user here: $info" 9 | done < "/etc/passwd" 10 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/102-lets_parse_apache_logs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Parses Apache log files in list format. 3 | # Displays the IP and HTTP status code. 4 | 5 | awk '{print $1 " " $9}' apache-access.log 6 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/103-dig_the-data: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Parses Apache log files in list format. 3 | # Groups visitors by IP and HTTP status code. 4 | # Displays the number of occurrences, IP, and HTTP status 5 | #+ code of each log, in sorted order. 6 | 7 | awk '{ print $1 " " $9}' apache-access.log | sort | uniq -c | sort -rn 8 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/2-while_best_school: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays 'Best School' in stdout 10 times using a while loop 3 | 4 | index=0 5 | 6 | while [ $index -lt 10 ] 7 | do 8 | echo "Best School" 9 | ((index++)) 10 | done 11 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/3-until_best_school: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays 'Best School' in stdout 10 times using the until loop 3 | 4 | index=0 5 | 6 | until [ $index -eq 10 ] 7 | do 8 | echo "Best School" 9 | ((index++)) 10 | done 11 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/4-if_9_say_hi: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays 'Best School'. Displays Hi on the 9th iteration 3 | 4 | index=0 5 | 6 | while [ $index -lt 10 ] 7 | do 8 | if [ $index -eq 9 ] 9 | then 10 | echo "Hi" 11 | fi 12 | echo "Best School" 13 | (( index++ )) 14 | done 15 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/5-4_bad_luck_8_is_your_chance: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Loops from 1 to 10 and displays: 3 | # "bad luck" for the 4th iteration 4 | # "good luck" for the 8th iteration 5 | # "Best School" for all other iterations 6 | 7 | count=0 8 | 9 | while [ $count -lt 10 ] 10 | do 11 | if [ $count -eq 3 ] 12 | then 13 | echo "bad luck" 14 | elif [ $count -eq 7 ] 15 | then 16 | echo "good luck" 17 | else 18 | echo "Best School" 19 | fi 20 | (( count++ )) 21 | done 22 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/6-superstitious_numbers: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays numbers from 1 to 20 in addition to: 3 | # "bad luck from China" for the 4th iteration 4 | # "bad luck from Japan" for the 9th iteration 5 | # "bad luck from Italy" for the 17th loop iteration 6 | 7 | count=1 8 | 9 | while [ $count -le 20 ] 10 | do 11 | echo "$count" 12 | case $count in 13 | "4") echo "bad luck from China";; 14 | "9") echo "bad luck from Japan";; 15 | "17") echo "bad luck from Italy";; 16 | esac 17 | (( count++ )) 18 | done 19 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/7-clock: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays the time for 12 horus and 59 minutes. 3 | # Displays hours from 0 to 12 4 | # Displays minutes from 1 to 59 5 | 6 | hour=0 7 | 8 | while [ $hour -le 12 ] 9 | do 10 | echo "Hour: $hour" 11 | minute=1 12 | while [ $minute -le 59 ] 13 | do 14 | echo "$minute" 15 | (( minute++ )) 16 | done 17 | (( hour++ )) 18 | done 19 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/8-for_ls: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays the contents of the current directory in list format. 3 | # Only displays the part of the name after the first dash. 4 | 5 | list=$(ls) 6 | for i in $list; do 7 | echo "$i" | cut -d '-' -f2 8 | done 9 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/9-to_file_or_not_to_file: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays information about the file `school`. 3 | 4 | if [ -e "school" ] 5 | then 6 | echo "school file exists" 7 | if [ -s "school" ] 8 | then 9 | echo "school file is not empty" 10 | else 11 | echo "school file is empty" 12 | fi 13 | 14 | if [ -f "school" ] 15 | then 16 | echo "school is a regular file" 17 | fi 18 | else 19 | echo "school file does not exist" 20 | fi 21 | -------------------------------------------------------------------------------- /0x04-loops_conditions_and_parsing/README.md: -------------------------------------------------------------------------------- 1 | ## 0x04. Loops, conditions and parsing 2 | 3 | **What you should learn from this project** 4 | 5 | At the end of this project you are expected to be able to explain, 6 | without the help of Google: 7 | 8 | * How to create SSH keys 9 | * What is the advantage of using #!/usr/bin/env bash over #!/bin/bash 10 | * How to use while, until and for loops 11 | * How to use if, else, elif and case condition statements 12 | * How to use the cut command 13 | * What are files and other comparison operators, and how to use them 14 | 15 | **Exercises** 16 | 17 | **0. Create a SSH RSA key pair** 18 | 19 | **1. For Holberton School loop** 20 | 21 | Write a Bash script that displays Holberton School 10 times. 22 | 23 | Requirement: 24 | 25 | * You must use the for loop (while and until are forbidden) 26 | 27 | **2. While Holberton School loop** 28 | 29 | Write a Bash script that displays Holberton School 10 times. 30 | 31 | Requirements: 32 | 33 | * You must use the while loop (for and until are forbidden) 34 | 35 | **3. Until Holberton School loop** 36 | 37 | Write a Bash script that displays Holberton School 10 times. 38 | 39 | Requirements: 40 | 41 | * You must use the until loop (for and while are forbidden) 42 | 43 | **4. If 9, say Hi!** 44 | 45 | Write a Bash script that displays Holberton School 10 times, but for the 46 | 9th iteration, displays Holberton School and then Hi on a new line. 47 | 48 | Requirements: 49 | 50 | * You must use the while loop (for and until are forbidden) 51 | * You must use the if statement 52 | 53 | **5. 4 bad luck, 8 is your chance** 54 | 55 | Write a Bash script that loops from 1 to 10 and: 56 | 57 | * displays bad luck for the 4th loop iteration 58 | * displays good luck for the 8th loop iteration 59 | * displays Holberton School for the other iterations 60 | Requirements: 61 | 62 | * You must use the while loop (for and until are forbidden) 63 | * You must use the if, elif and else statements 64 | 65 | **6. Superstitious numbers** 66 | 67 | Write a Bash script that displays numbers from 1 to 20 and: 68 | 69 | * displays bad luck from China for the 4th loop iteration 70 | * displays bad luck from Japan for the 9th loop iteration 71 | * displays bad luck from Italy for the 17th loop iteration 72 | Requirements: 73 | 74 | * You must use the while loop (for and until are forbidden) 75 | * You must use the case statement 76 | 77 | **7. Clock** 78 | 79 | Write a Bash script that displays the time for 12 hours and 59 minutes: 80 | 81 | * display hours from 0 to 12 82 | * display minutes from 1 to 59 83 | Requirements: 84 | 85 | * You must use the while loop (for and until are forbidden) 86 | Note that in this example, we only display the first 70 lines using the 87 | head command. 88 | 89 | **8. For ls** 90 | 91 | Write a Bash script that displays: 92 | 93 | * The content of the current directory 94 | * In a list format 95 | * Where only the part of the name after the first dash is displayed 96 | (refer to the example) 97 | Requirements: 98 | 99 | * You must use the for loop (while and until are forbidden) 100 | * Do not display hidden files 101 | 102 | **9. To file, or not to file** 103 | 104 | Write a Bash script that gives you information about the holbertonschool file. 105 | 106 | Requirements: 107 | 108 | * You must use if and, else (case is forbidden) 109 | * Your Bash script should check if the file exists and print: 110 | * if the file exists: holbertonschool file exists 111 | * if the file does not exist: holbertonschool file does not exist 112 | * If the file exists, print: 113 | * if the file is empty: holbertonschool file is empty 114 | * if the file is no empty: holbertonschool file is not empty 115 | * if the file is a regular file: holbertonschool is a regular file 116 | * if the file is not a regular file: (nothing) 117 | 118 | **10. FizzBuzz** 119 | 120 | Write a Bash script that displays numbers from 1 to 100. 121 | 122 | Requirements: 123 | 124 | * Displays FizzBuzz when the number is a multiple of 3 and 5 125 | * Displays Fizz when the number is multiple of 3 126 | * Displays Buzz when the number is a multiple of 5 127 | * Otherwise, displays the number 128 | * In a list format 129 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/0-what-is-my-pid: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays its own PID. 3 | 4 | echo $$ 5 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/1-list_your_processes: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays a list of currently running processes. 3 | # Shows all processes, for all users, including those 4 | #+ which might not have a TTY. 5 | 6 | ps -auxf 7 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/100-process_and_pid_file: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Does the following: 3 | # Create a file /var/run/myscript.pid containing the script PID. 4 | # Displays "To infinity and beyond" indefinitely 5 | # Displays "I hate the kill command" upon receiving a SIGTERM 6 | # Displays "Y U no love me?!" upon receiving a SIGINT 7 | # Deletes the file /var/run/myscript.pid and terminates upon 8 | #+ receiving a SIGQUIT or SIGTERM. 9 | 10 | terminator() { 11 | rm /var/run/myscript.pid 12 | exit 13 | } 14 | 15 | echo "$$" > /var/run/myscript.pid 16 | 17 | while true 18 | do 19 | echo "To infinity and beyond" 20 | sleep 2 21 | trap 'echo "Y U no love me?!"' SIGINT 22 | trap 'echo "I hate the kill command" && terminator' SIGTERM 23 | trap 'terminator' SIGQUITgit 24 | done 25 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/101-manage_my_process: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Manages the script manage_my_process. 3 | # When passed the argument `start`: 4 | # 1. Starts manage_my_process 5 | # 2. Creates a file containings its PID in /var/run/my_process.pid 6 | # 3. Displays "manage_my_process started" 7 | # When passed the argument `stop`: 8 | # 1. Stops manage_my_process 9 | # 2. Deletes the file /var/run/my_process.pid 10 | # 3. Displays "manage_my_process stopped" 11 | # When passed the argument `restart`: 12 | # 1. Stops manage_my_process 13 | # 2. Deletes the file /var/run/my_process.pid 14 | # 3. Starts manage_my_process 15 | # 4. Creates a file containing its PID in /var/run/my_process.pid 16 | # 5. Displays "manage_my_process restarted" 17 | # If any other or no arguments are passed, displays 18 | #+ "Usage: manage_my_process {start|stop|restart}" 19 | 20 | if [ "$1" == "start" ] 21 | then 22 | ./manage_my_process & 23 | echo $$ > /var/run/my_process.pid 24 | echo "manage_my_process started" 25 | 26 | elif [ "$1" == "stop" ] 27 | then 28 | kill "$(pgrep -f /manage_my_process)" 29 | rm /var/run/my_process.pid 30 | echo "manage_my_process stopped" 31 | 32 | elif [ "$1" == "restart" ] 33 | then 34 | kill "$(pgrep -f /manage_my_process)" 35 | rm /var/run/my_process.pid 36 | ./manage_my_process & 37 | echo $$ > /var/run/my_process.pid 38 | echo "manage_my_process restarted" 39 | 40 | else 41 | echo "Usage: manage_my_process {start|stop|restart}" 42 | fi 43 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/102-zombie.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | /** 8 | * infinite_while - Run an infinite while loop. 9 | * 10 | * Return: Always 0. 11 | */ 12 | int infinite_while(void) 13 | { 14 | while (1) 15 | { 16 | sleep(1); 17 | } 18 | return (0); 19 | } 20 | 21 | /** 22 | * main - Creates five zombie processes. 23 | * 24 | * Return: Always 0. 25 | */ 26 | int main(void) 27 | { 28 | pid_t pid; 29 | char count = 0; 30 | 31 | while (count < 5) 32 | { 33 | pid = fork(); 34 | if (pid > 0) 35 | { 36 | printf("Zombie process created, PID: %d\n", pid); 37 | sleep(1); 38 | count++; 39 | } 40 | else 41 | exit(0); 42 | } 43 | 44 | infinite_while(); 45 | 46 | return (EXIT_SUCCESS); 47 | } 48 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/2-show_your_bash_pid: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays a list of currently running processes containing the bash keyword. 3 | # shellcheck disable=SC2009 4 | 5 | ps -aux | grep bash 6 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/3-show_your_bash_pid_made_easy: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays the PID along with the process name, of 3 | #+ processes whose name contains the word "bash". 4 | 5 | pgrep bash -l 6 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/4-to_infinity_and_beyond: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays "To infinity and beyond" indefinitely with 3 | #+ a sleep 2 in between each iteration. 4 | 5 | while true 6 | do 7 | echo "To infinity and beyond" 8 | sleep 2 9 | done 10 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/5-dont_stop_me_now: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Kills the 4-to_infinity_and_beyond process 3 | 4 | kill "$(pgrep -f 4-to_infinity_and_beyond)" 5 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/6-stop_me_if_you_can: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Kills the 4-to_infinity_and_beyond process. 3 | 4 | pkill -f 4-to_infinity_and_beyond 5 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/7-highlander: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays "To infinity and beyond" indefinitely with 3 | #+ a sleep 2 in between each iteration. 4 | # Displays "I am invincible!!!" in between each iteration. 5 | 6 | while true 7 | do 8 | echo "To infinity and beyond" 9 | sleep 2 10 | trap 'echo "I am invincible!!!"' SIGTERM 11 | done 12 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/8-beheaded_process: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Kills the process 7-highlander. 3 | 4 | pkill -f -SIGKILL 7-highlander 5 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/README.md: -------------------------------------------------------------------------------- 1 | ## 0x05. Processes and signals 2 | 3 | **What you should learn from this project** 4 | 5 | At the end of this project you are expected to be able to explain, 6 | without the help of Google: 7 | 8 | * What is a PID 9 | * What is a process 10 | * How to find a process PID 11 | * How to kill a process 12 | * What is a signal 13 | * What are the 2 signals that cannot be ignored 14 | 15 | ## Exercises 16 | 17 | **0. What is my PID** 18 | 19 | Write a Bash script that displays its PID. 20 | 21 | **1. List your processes** 22 | 23 | Write a Bash script that displays a list of currently running processes. 24 | 25 | Requirements: 26 | 27 | * Must show all processes, for all users, including those which might not have a TTY 28 | * Display a user-oriented format 29 | * Show process hierarchy 30 | 31 | **2. Show your Bash PID** 32 | 33 | Using your previous exercise command, write a Bash script that displays line 34 | containing the bash word, this allowing you to easily get the PID of your 35 | Bash process 36 | 37 | Requirements: 38 | 39 | * You cannot use pgrep 40 | * The third line of your script must be # shellcheck disable=SC2009 41 | (for more info about ignoring shellcheck error here) 42 | 43 | **3. Show your Bash PID made easy** 44 | 45 | Write a Bash script that displays the PID, along with the process name, of 46 | processes which name contains the word bash. 47 | 48 | Requirements: 49 | 50 | * You cannot use ps 51 | 52 | **4. To infinity and beyond** 53 | 54 | Write a Bash script that displays To infinity and beyond indefinitely. 55 | 56 | Requirements: 57 | 58 | * In between each iteration of the loop, add a sleep 2 59 | 60 | 61 | **5. Kill me now** 62 | 63 | We killed our 4-to_infinity_and_beyond process using ctrl+c in the previous 64 | task, there is actually another way to do this. 65 | 66 | Write a Bash script that kills 4-to_infinity_and_beyond process. 67 | 68 | Requirements: 69 | 70 | * You must use kill 71 | 72 | **6. Kill me now made easy** 73 | 74 | Write a Bash script that kills 4-to_infinity_and_beyond process. 75 | 76 | Requirements: 77 | 78 | * You cannot use kill or killall 79 | 80 | **7. Highlander** 81 | 82 | Write a Bash script that displays: 83 | 84 | * To infinity and beyond indefinitely 85 | * With a sleep 2 in between each iteration 86 | * I am invincible!!! when receiving a SIGTERM signal 87 | 88 | **8. Beheaded process** 89 | 90 | Write a Bash script that kills the process 7-highlander 91 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/manage_my_process: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Indefinitely writes "I am alive" to the file /tmp/my_process. 3 | # Pauses two seconds in between each message. 4 | 5 | while true 6 | do 7 | echo "I am alive!" >> /tmp/my_process 8 | sleep 2 9 | done 10 | -------------------------------------------------------------------------------- /0x05-processes_and_signals/zombie: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TechByDami/alx-system_engineering-devops/908fb5b0bd20ce2571c070ab876dff54173442e2/0x05-processes_and_signals/zombie -------------------------------------------------------------------------------- /0x06-regular_expressions/0-simply_match_school.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | puts ARGV[0].scan(/School/).join 3 | -------------------------------------------------------------------------------- /0x06-regular_expressions/1-repetition_token_0.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | puts ARGV[0].scan(/hbt{2,5}n/).join 3 | -------------------------------------------------------------------------------- /0x06-regular_expressions/100-textme.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | puts ARGV[0].scan(/\[from:(.*?)\] \[to:(.*?)\] \[flags:(.*?)\]/).join(",") 3 | -------------------------------------------------------------------------------- /0x06-regular_expressions/2-repetition_token_1.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | puts ARGV[0].scan(/hb?t?n/).join 3 | -------------------------------------------------------------------------------- /0x06-regular_expressions/3-repetition_token_2.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | puts ARGV[0].scan(/hbt+n/).join 3 | -------------------------------------------------------------------------------- /0x06-regular_expressions/4-repetition_token_3.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | puts ARGV[0].scan(/hbt*n/).join 3 | -------------------------------------------------------------------------------- /0x06-regular_expressions/5-beginning_and_end.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | puts ARGV[0].scan(/^h.n$/).join 3 | -------------------------------------------------------------------------------- /0x06-regular_expressions/6-phone_number.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | puts ARGV[0].scan(/^\d{10,10}$/).join 3 | -------------------------------------------------------------------------------- /0x06-regular_expressions/7-OMG_WHY_ARE_YOU_SHOUTING.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | puts ARGV[0].scan(/[A-Z]*/).join 3 | -------------------------------------------------------------------------------- /0x06-regular_expressions/README.md: -------------------------------------------------------------------------------- 1 | ## 0x06. Regular expression 2 | 3 | ![](https://intranet.hbtn.io/images/contents/sysadmin/concepts/29/regex_now_2_problems.jpg) 4 | 5 | A regular expression, commonly called a “regexp”, is a sequence of characters that define a search pattern. It is mainly for use in pattern matching with strings, or string matching (i.e. it operates like a “find and replace” command). While it is a very powerful tool, it is also very dangerous because of its complexity. 6 | 7 | More about regexp: 8 | * http://www.regular-expressions.info/ 9 | * http://www.w3schools.com/jsref/jsref_obj_regexp.asp Play with regexp (or compose them): 10 | * Ruby: http://rubular.com/ 11 | * PHP/Javascript/Python: https://regex101.com/ 12 | 13 | ## Exercises 14 | 15 | **0. Simply matching Holberton** 16 | ![](https://s3.amazonaws.com/intranet-projects-files/holbertonschool-sysadmin_devops/78/just-match-Holberton.png) 17 | 18 | Requirements: 19 | 20 | The regular expression must match Holberton 21 | Using the project instructions, create a Ruby script that accepts one argument and pass it to a regular expression matching method 22 | 23 | **1. Repetition Token #0** 24 | ![](https://s3.amazonaws.com/intranet-projects-files/holbertonschool-sysadmin_devops/78/repetition-token-0.png) 25 | 26 | Requirements: 27 | 28 | Find the regular expression that will match the above cases 29 | Using the project instructions, create a Ruby script that accepts one argument and pass it to a regular expression matching method 30 | 31 | **2. Repetition Token #1** 32 | ![](https://s3.amazonaws.com/intranet-projects-files/holbertonschool-sysadmin_devops/78/repetition-token-1.png) 33 | -------------------------------------------------------------------------------- /0x06-regular_expressions/example.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | puts ARGV[0].scan(/127.0.0.[0-9]/).join -------------------------------------------------------------------------------- /0x07-networking_basics/0-OSI_model: -------------------------------------------------------------------------------- 1 | 2 2 | 2 3 | -------------------------------------------------------------------------------- /0x07-networking_basics/1-types_of_network: -------------------------------------------------------------------------------- 1 | 3 2 | 2 3 | 1 4 | -------------------------------------------------------------------------------- /0x07-networking_basics/2-MAC_and_IP_address: -------------------------------------------------------------------------------- 1 | 2 2 | 1 3 | -------------------------------------------------------------------------------- /0x07-networking_basics/3-UDP_and_TCP: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 1 4 | -------------------------------------------------------------------------------- /0x07-networking_basics/4-TCP_and_UDP_ports: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays listening ports. Includes listening sockets too 3 | # + as the PID and name of the program to which each socket belongs. 4 | 5 | netstat -l --program 6 | -------------------------------------------------------------------------------- /0x07-networking_basics/5-is_the_host_on_the_network: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Pings an IP address received as a string argument 5 times. 3 | 4 | if [ "$#" -eq 0 ] 5 | then 6 | echo "Usage: 5-is_the_host_on_the_network {IP_ADDRESS}" 7 | else 8 | ping -c 5 "$1" 9 | fi 10 | -------------------------------------------------------------------------------- /0x07-networking_basics/README.md: -------------------------------------------------------------------------------- 1 | # 0x07. Networking basics #0 2 | 3 | ## In this project I learnt about 4 | - OSI Model 5 | - What it is 6 | - How many layers it has 7 | - How it is organized 8 | - What is a LAN 9 | - Typical usage 10 | - Typical geographical size 11 | - What is a WAN 12 | - Typical usage 13 | - Typical geographical size 14 | - What is the Internet 15 | - What is an IP address 16 | - What are the 2 types of IP address 17 | - What is localhost 18 | - What is a subnet 19 | - Why IPv6 was created 20 | - TCP/UDP 21 | - What are the 2 mainly used data transfer protocols for IP (transfer level on the OSI schema) 22 | - What is the main difference between TCP and UDP 23 | - What is a port 24 | - Memorize SSH, HTTP and HTTPS port numbers 25 | - What tool/protocol is often used to check if a device is connected to a network 26 | 27 | ## Useful resources 28 | [OSI Model Explained | OSI Animation | Open System Interconnection Model | OSI 7 layers](https://www.youtube.com/watch?v=vv4y_uOneC0) 29 | -------------------------------------------------------------------------------- /0x08-networking_basics_2/0-change_your_home_IP: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Configures an Ubuntu server as follows: 3 | # - localhost resolves to 127.0.0.2 4 | # - facebook.com resolves to 8.8.8.8 5 | 6 | cp /etc/hosts ~/hosts.new 7 | sed -i 's/127.*$/127.0.0.2 localhost\n8.8.8.8 facebook.com/' ~/hosts.new 8 | cp -f ~/hosts.new /etc/hosts 9 | -------------------------------------------------------------------------------- /0x08-networking_basics_2/1-show_attached_IPs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Displays all acive IPv4 addresses. 3 | 4 | ifconfig | grep -Eo "inet (addr:)?([0-9]*\.){3}[0-9]*" | cut -b 11- 5 | -------------------------------------------------------------------------------- /0x08-networking_basics_2/100-port_listening_on_localhost: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Listens on port 98 on localhost. 3 | 4 | nc -l localhost 98 5 | -------------------------------------------------------------------------------- /0x08-networking_basics_2/README.md: -------------------------------------------------------------------------------- 1 | ## 0x08. Networking basics #1 2 | 3 | ![](https://s3.amazonaws.com/intranet-projects-files/holbertonschool-sysadmin_devops/285/s7kpNYq.png) 4 | 5 | **What you should learn from this project** 6 | 7 | At the end of this project you are expected to be able to explain, 8 | without the help of Google: 9 | 10 | * What is localhost/127.0.0.1 11 | * What is 0.0.0.0 12 | * What is /etc/hosts 13 | * How to display your machine’s active network interfaces 14 | 15 | **0. Localhost** 16 | 17 | What is localhost? 18 | 19 | 1. A hostname that means this IP 20 | 2. A hostname that means this computer 21 | 3. An IP attached to a computer 22 | 23 | **1. All IPs** 24 | 25 | What is 0.0.0.0? 26 | 27 | * All IPv4 addresses on the local machine 28 | * All the IPs 29 | * It means null in networking 30 | 31 | **2. Change your home IP** 32 | 33 | Write a Bash script that configures a Ubuntu server with the below 34 | requirements. 35 | 36 | Requirements: 37 | 38 | * localhost resolves to 127.0.0.2 39 | * facebook.com resolves to 8.8.8.8. 40 | 41 | **3. Show attached IPs** 42 | 43 | Write a Bash script that displays all active IPv4 IPs on the machine 44 | it’s executed on. 45 | 46 | **4. Port listening on localhost** 47 | 48 | Write a Bash script that listens on port 98 on localhost. 49 | -------------------------------------------------------------------------------- /0x0A-configuration_management/0-create_a_file.pp: -------------------------------------------------------------------------------- 1 | # creates a file in /tmp 2 | 3 | file { '/tmp/school': 4 | content =>'I love Puppet', 5 | mode => '0744', 6 | owner => 'www-data', 7 | group => 'www-data', 8 | } 9 | -------------------------------------------------------------------------------- /0x0A-configuration_management/1-install_a_package.pp: -------------------------------------------------------------------------------- 1 | #!/usr/bin/pup 2 | # Install an especific version of flask (2.1.0) 3 | package {'flask': 4 | ensure => '2.1.0', 5 | provider => 'pip3' 6 | } 7 | -------------------------------------------------------------------------------- /0x0A-configuration_management/2-execute_a_command.pp: -------------------------------------------------------------------------------- 1 | # kill process killmenow 2 | 3 | exec { 'pkill': 4 | command => 'pkill killmenow', 5 | provider => 'shell', 6 | } 7 | -------------------------------------------------------------------------------- /0x0A-configuration_management/README.md: -------------------------------------------------------------------------------- 1 | # Configuration management 2 | 3 | In this project, I started working with Puppet as a configuration management 4 | tool. I practiced writing Puppet manifest files to create a file, install a 5 | package, and execute a command. 6 | 7 | ## Tasks :page_with_curl: 8 | 9 | * **0. Create a file** 10 | * [0-create_a_file.pp](./0-create_a_file.pp): Puppet manifest file that 11 | creates a file `school` in the `/tmp` directory. 12 | * File permissions: `0744`. 13 | * File group: `www-data`. 14 | * File owner: `www-data`. 15 | * File content: `I love Puppet`. 16 | 17 | * **1. Install a package** 18 | * [1-install_a_package.pp](./1-install_a_package.pp): Puppet manifest file 19 | that install `flask` from pip3. 20 | 21 | * **2. Execute a command** 22 | * [2-execute_a_command.pp](./2-execute_a_command.pp): Puppet manifest file 23 | that kills the process `killmenow`. 24 | -------------------------------------------------------------------------------- /0x0A-configuration_management/killmenow: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | while [[ true ]] 3 | do 4 | sleep 2 5 | done 6 | -------------------------------------------------------------------------------- /0x0B-ssh/0-use_a_private_key: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Connects to server 34.138.32.248 with key in ~/.ssh/school 3 | 4 | ssh -i ~/.ssh/school ubuntu@34.138.32.248 -------------------------------------------------------------------------------- /0x0B-ssh/1-create_ssh_key_pair: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Creates RSA key pair 3 | 4 | ssh-keygen -b 4096 -f school -t rsa -N betty -------------------------------------------------------------------------------- /0x0B-ssh/100-puppet_ssh_config.pp: -------------------------------------------------------------------------------- 1 | # Seting up my client config file 2 | include stdlib 3 | 4 | file_line { 'Turn off passwd auth': 5 | ensure => present, 6 | path => '/etc/ssh/ssh_config', 7 | line => ' PasswordAuthentication no', 8 | replace => true, 9 | } 10 | 11 | file_line { 'Delare identity file': 12 | ensure => present, 13 | path => '/etc/ssh/ssh_config', 14 | line => ' IdentityFile ~/.ssh/school', 15 | replace => true, 16 | } 17 | -------------------------------------------------------------------------------- /0x0B-ssh/2-ssh_config: -------------------------------------------------------------------------------- 1 | # ssh config file 2 | Host * 3 | PasswordAuthentication no 4 | IdentifyFile ~/.ssh/school -------------------------------------------------------------------------------- /0x0B-ssh/README.md: -------------------------------------------------------------------------------- 1 | # SSH 2 | 3 | In this project, I became familiar connecting to and working 4 | with servers using the SSH protocol. I worked on a server 5 | provided by ALX. 6 | 7 | ## Tasks :page_with_curl: 8 | 9 | * **0. Use a private key** 10 | * [0-use_a_private_key](./0-use_a_private_key): Bash script that uses `ssh` to connect to my 11 | Holberton-provided server. 12 | 13 | * **1. Create an SSH key pair** 14 | * [1-create_ssh_key_pair](./1-create_ssh_key_pair): Bash script that creates an RSA key pair. 15 | 16 | * **2. Client configuration file** 17 | * [2-ssh_config](./2-ssh_config): SSH configuration file configured to use the private key 18 | `~/.ssh/holberton` and to refuse authentication using a password. 19 | -------------------------------------------------------------------------------- /0x0D-web_stack_debugging_0/0-give_me_a_page: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # run apache on designated container 3 | 4 | echo "ServerName localhost" >> /etc/apache2.conf 5 | service apache2 start 6 | -------------------------------------------------------------------------------- /0x0D-web_stack_debugging_0/README.md: -------------------------------------------------------------------------------- 1 | # Web stack debugging #0 2 | 3 | This was the first in a series of web stack debugging projects. In these 4 | projects, I was given broken/bugged webstacks in isolated containers, 5 | and tasked with fixing the web stack to a working state. For each 6 | task, I wrote a script automating the commands necessary to fix the 7 | web stack. 8 | 9 | ## Tasks :page_with_curl: 10 | 11 | * **0. Give me a page!** 12 | * [0-give_me_a_page](./0-give_me_a_page): Bash script that runs Apache on a 13 | web server and gets it to respond to queries to the root. 14 | -------------------------------------------------------------------------------- /0x0E-web_stack_debugging_1/0-nginx_likes_port_80: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Configures an Nginx server to listen on port 80. 3 | 4 | rm /etc/nginx/sites-enabled/default 5 | ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default 6 | service nginx restart 7 | -------------------------------------------------------------------------------- /0x0E-web_stack_debugging_1/1-debugging_made_short: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Configures an Nginx server to listen on port 80. 3 | ln -sf /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default 4 | service nginx start 5 | kill "$(pgrep 'nginx' | head -1)" 6 | -------------------------------------------------------------------------------- /0x0E-web_stack_debugging_1/README.md: -------------------------------------------------------------------------------- 1 | # Web stack debugging #1 2 | 3 | This was the second in a series of web stack debugging projects. In these 4 | projects, I was given broken/bugged webstacks in isolated containers, 5 | and tasked with fixing the web stack to a working state. For each 6 | task, I wrote a script automating the commands necessary to fix the 7 | web stack. 8 | 9 | ## Tasks :page_with_curl: 10 | 11 | * **0. Nginx likes port 80** 12 | * [0-nginx_likes_port_80](./0-nginx_likes_port_80): Bash script that 13 | configures Nginx to run and listen to port 80 on all of a server's active IPv4's. 14 | 15 | * **1. Make it sweet and short** 16 | * [1-debugging_made_short](./1-debugging_made_short): Bash script that 17 | configures Nginx to listen to port 80 without running on all of a server's 18 | active IPv4's. 19 | -------------------------------------------------------------------------------- /0x0F-load_balancer/1-install_load_balancer: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Installs and setup haproxy 3 | 4 | apt-get install -y software-properties-common 5 | add-apt-repository -y ppa:vbernat/haproxy-1.8 6 | apt-get -y update 7 | apt-get install -y haproxy=1.8.\* 8 | 9 | echo "ENABLED=1" > /etc/default/haproxy 10 | 11 | # Listen to web1 and web2 servers 12 | echo " 13 | listen load_balancer 14 | bind *:80 15 | mode http 16 | balance roundrobin 17 | option httpclose 18 | option forwardfor 19 | server 17272-web-01 44.200.83.158:80 check 20 | server 17272-web-02 3.237.16.226:80 check 21 | " >> /etc/haproxy/haproxy.cfg 22 | 23 | service haproxy start 24 | -------------------------------------------------------------------------------- /0x0F-load_balancer/2-puppet_custom_http_response-header.pp: -------------------------------------------------------------------------------- 1 | # Installs a Nginx server with custome HTTP header 2 | 3 | exec {'update': 4 | provider => shell, 5 | command => 'sudo apt-get -y update', 6 | before => Exec['install Nginx'], 7 | } 8 | 9 | exec {'install Nginx': 10 | provider => shell, 11 | command => 'sudo apt-get -y install nginx', 12 | before => Exec['add_header'], 13 | } 14 | 15 | exec { 'add_header': 16 | provider => shell, 17 | environment => ["HOST=${hostname}"], 18 | command => 'sudo sed -i "s/include \/etc\/nginx\/sites-enabled\/\*;/include \/etc\/nginx\/sites-enabled\/\*;\n\tadd_header X-Served-By \"$HOST\";/" /etc/nginx/nginx.conf', 19 | before => Exec['restart Nginx'], 20 | } 21 | 22 | exec { 'restart Nginx': 23 | provider => shell, 24 | command => 'sudo service nginx restart', 25 | } -------------------------------------------------------------------------------- /0x0F-load_balancer/README.md: -------------------------------------------------------------------------------- 1 | # Load Balancer -------------------------------------------------------------------------------- /0x10-https_ssl/0-world_wide_web: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Usage: ./1-world_wide_web 3 | # Display information about subdomains. 4 | 5 | domain_information () { 6 | line=$(dig "$2"."$1" | grep -A1 'ANSWER SECTION:' | tr '\t' '\n' | tail -2 | tr '\n' ' ') 7 | echo "$2 $line" | awk '{print "The subdomain " $1 " is a " $2 " record and points to " $3}' 8 | } 9 | 10 | if [ "$#" == 1 ] 11 | then 12 | domain_information "$1" "www" 13 | domain_information "$1" "lb-01" 14 | domain_information "$1" "web-01" 15 | domain_information "$1" "web-02" 16 | elif [ "$#" == 2 ] 17 | then 18 | domain_information "$1" "$2" 19 | fi 20 | -------------------------------------------------------------------------------- /0x10-https_ssl/1-haproxy_ssl_termination: -------------------------------------------------------------------------------- 1 | global 2 | log /dev/log local0 3 | maxconn 2048 4 | user haproxy 5 | group haproxy 6 | tune.ssl.default-dh-param 2048 7 | 8 | defaults 9 | log global 10 | mode http 11 | option httplog 12 | option dontlognull 13 | retries 3 14 | option redispatch 15 | timeout connect 5000 16 | timeout client 10000 17 | timeout server 10000 18 | option forwardfor 19 | option http-server-close 20 | 21 | frontend www-http 22 | bind 0.0.0.0:80 23 | reqadd X-Forwarded-Proto:\ http 24 | default_backend www-backend 25 | 26 | frontend www-https 27 | bind 0.0.0.0:443 ssl crt /etc/haproxy/certs/www.bdbnb.site.pem 28 | reqadd X-Forwarded-Proto:\ https 29 | acl letsencrypt-acl path_beg /.well-known/acme-challenge/ 30 | use_backend letsencrypt-backend if letsencrypt-acl 31 | default_backend www-backend 32 | 33 | backend www-backend 34 | balance roundrobin 35 | redirect scheme https if !{ ssl_fc } 36 | server 375-web-01 104.196.168.90:80 check 37 | server 375-web-02 35.196.46.172:80 check 38 | 39 | backend letsencrypt-backend 40 | server letsencrypt 127.0.0.1:54321 41 | -------------------------------------------------------------------------------- /0x10-https_ssl/100-redirect_http_to_https: -------------------------------------------------------------------------------- 1 | global 2 | log /dev/log local0 3 | maxconn 2048 4 | user haproxy 5 | group haproxy 6 | tune.ssl.default-dh-param 2048 7 | 8 | defaults 9 | log global 10 | mode http 11 | option httplog 12 | option dontlognull 13 | retries 3 14 | option redispatch 15 | timeout connect 5000 16 | timeout client 10000 17 | timeout server 10000 18 | option forwardfor 19 | option http-server-close 20 | 21 | frontend www-http 22 | bind 0.0.0.0:80 23 | reqadd X-Forwarded-Proto:\ http 24 | default_backend www-backend 25 | redirect scheme https code 301 if !{ ssl_fc } 26 | 27 | frontend www-https 28 | bind 0.0.0.0:443 ssl crt /etc/haproxy/certs/www.bdbnb.site.pem 29 | reqadd X-Forwarded-Proto:\ https 30 | acl letsencrypt-acl path_beg /.well-known/acme-challenge/ 31 | use_backend letsencrypt-backend if letsencrypt-acl 32 | default_backend www-backend 33 | 34 | backend www-backend 35 | balance roundrobin 36 | redirect scheme https if !{ ssl_fc } 37 | server 375-web-01 104.196.168.90:80 check 38 | server 375-web-02 35.196.46.172:80 check 39 | 40 | backend letsencrypt-backend 41 | server letsencrypt 127.0.0.1:54321 42 | -------------------------------------------------------------------------------- /0x10-https_ssl/README.md: -------------------------------------------------------------------------------- 1 | # HTTPS SSL 2 | 3 | In this project, I learned about the importance of HTTPS and how it works. I 4 | configured my HolbertonBnB web servers with `certbot` certificate and HAproxy 5 | SSL termination. 6 | 7 | ## Tasks :page_with_curl: 8 | 9 | 10 | * **0. World wide web** 11 | * [1-world_wide_web](./0-world_wide_web): Bash script that displays 12 | information about subdomains on my configured servers. 13 | * Usage: `./1-world_wide_web ` 14 | * Output: `The subdomain [SUB_DOMAIN] is a [RECORD_TYPE] record and 15 | points to [DESTINATION]` 16 | * If no `subdomain` parameter is passed, displays information about the 17 | subdomains `www`, `lb-01`, `web-01` and `web-02`, in that order. 18 | 19 | * **2. HAproxy SSL termination** 20 | * [2-haproxy_ssl_termination](./2-haproxy_ssl_termination): HAproxy 21 | configuration file that accepts encrypted SSL traffic for the subdomain 22 | `www.` on TCP port 443. 23 | 24 | * **3. No loophole in your website traffic** 25 | * [100-redirect_http_to_https](./100-redirect_http_to_https): HAproxy 26 | configuration file that automatically redirects HTTP traffic to HTTPS. 27 | -------------------------------------------------------------------------------- /0x11-what_happens_when_your_type_google_com_in_your_browser_and_press_enter/0-blog_post: -------------------------------------------------------------------------------- 1 | https://medium.com/@fakunletolulope05/what-happens-when-you-type-google-com-in-your-browser-and-press-enter-b91559c4178d 2 | -------------------------------------------------------------------------------- /0x11-what_happens_when_your_type_google_com_in_your_browser_and_press_enter/1-what_happen_when_diagram: -------------------------------------------------------------------------------- 1 | https://im.ge/i/1ecIxa 2 | -------------------------------------------------------------------------------- /0x11-what_happens_when_your_type_google_com_in_your_browser_and_press_enter/2-contribution-to_what-happens-when_github_answer: -------------------------------------------------------------------------------- 1 | https://github.com/alex/what-happens-when/pull/385 2 | -------------------------------------------------------------------------------- /0x11-what_happens_when_your_type_google_com_in_your_browser_and_press_enter/README.md: -------------------------------------------------------------------------------- 1 | # Web Infrastructure 2 | -------------------------------------------------------------------------------- /0x12-web_stack_debugging_2/0-iamsomeonelese: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Runs the whoami command under the user passed as argument. 3 | sudo -u "$1" whoami 4 | -------------------------------------------------------------------------------- /0x12-web_stack_debugging_2/1-run_nginx_as_nginx: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Fixes a web server to run Nginx as the nginx user listening on port 8080. 3 | sed -i "s/#user www-data/user nginx/" /etc/nginx/nginx.conf 4 | sed -i "s/80/8080/g" /etc/nginx/sites-available/default 5 | chmod 644 /etc/nginx/nginx.conf 6 | pkill apache2 7 | sudo -u nginx service nginx start 8 | -------------------------------------------------------------------------------- /0x12-web_stack_debugging_2/100-fix_in_7_lines_or_less: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Fixes a web server to run Nginx as the nginx user listening on port 8080. 3 | sed -i "s/#user www-data/user nginx/" /etc/nginx/nginx.conf 4 | sed -i "s/80/8080/g" /etc/nginx/sites-available/default 5 | chmod 644 /etc/nginx/nginx.conf 6 | pkill apache2 7 | sudo -u nginx service nginx start 8 | -------------------------------------------------------------------------------- /0x12-web_stack_debugging_2/README.md: -------------------------------------------------------------------------------- 1 | # Web stack debugging #2 2 | 3 | This was the third in a series of web stack debugging projects. In these 4 | projects, I was given broken/bugged webstacks in isolated containers, 5 | and tasked with fixing the web stack to a working state. For each 6 | task, I wrote a script automating the commands necessary to fix the 7 | web stack. 8 | 9 | ## Tasks :page_with_curl: 10 | 11 | * **0. Run software as another user** 12 | * [0-iamsomeonelese](./0-iamsomeonelese): Bash script that runs the command 13 | `whoami` under the user passed as argument. 14 | * Usage: `./0-iamsomeonelese ` 15 | 16 | * **1. Run Nginx as Nginx** 17 | * [1-run_nginx_as_nginx](./1-run_nginx_as_nginx): Bash script that fixes a 18 | web server to run Nginx listening on port `8080` as the `nginx` user. 19 | 20 | * **2. 7 lines or less** 21 | * [100-fix_in_7_lines_or_less](./100-fix_in_7_lines_or_less): Bash script 22 | that fixes a web server to run Nginx listening on port `8080` as the `nginx` 23 | user. 24 | * 7 lines long. 25 | -------------------------------------------------------------------------------- /0x13-firewall/0-block_all_incoming_traffic_but: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Configures a ufw firewall to block all incoming traffic 3 | #+ except for TCP ports 22, 443 and 80. 4 | 5 | apt-get install ufw 6 | sed -i 's/IPV6=.*/IPV6=yes/' /etc/default/ufw 7 | ufw disable 8 | ufw enable 9 | ufw default deny incoming 10 | ufw default allow outgoing 11 | ufw allow 22/tcp 12 | ufw allow 443/tcp 13 | ufw allow 80/tcp 14 | -------------------------------------------------------------------------------- /0x13-firewall/100-port_forwarding: -------------------------------------------------------------------------------- 1 | # 2 | # rules.before 3 | # 4 | # Rules that should be run before the ufw command line added rules. Custom 5 | # rules should be added to one of these chains: 6 | # ufw-before-input 7 | # ufw-before-output 8 | # ufw-before-forward 9 | # 10 | 11 | *nat 12 | :PREROUTING ACCEPT [0:0] 13 | -A PREROUTING -p tcp --dport 8080 -j REDIRECT --to-port 80 14 | 15 | # Don't delete these required lines, otherwise there will be errors 16 | *filter 17 | :ufw-before-input - [0:0] 18 | :ufw-before-output - [0:0] 19 | :ufw-before-forward - [0:0] 20 | :ufw-not-local - [0:0] 21 | # End required lines 22 | 23 | 24 | # allow all on loopback 25 | -A ufw-before-input -i lo -j ACCEPT 26 | -A ufw-before-output -o lo -j ACCEPT 27 | 28 | # quickly process packets for which we already have a connection 29 | -A ufw-before-input -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT 30 | -A ufw-before-output -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT 31 | -A ufw-before-forward -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT 32 | 33 | # drop INVALID packets (logs these in loglevel medium and higher) 34 | -A ufw-before-input -m conntrack --ctstate INVALID -j ufw-logging-deny 35 | -A ufw-before-input -m conntrack --ctstate INVALID -j DROP 36 | 37 | # ok icmp codes for INPUT 38 | -A ufw-before-input -p icmp --icmp-type destination-unreachable -j ACCEPT 39 | -A ufw-before-input -p icmp --icmp-type source-quench -j ACCEPT 40 | -A ufw-before-input -p icmp --icmp-type time-exceeded -j ACCEPT 41 | -A ufw-before-input -p icmp --icmp-type parameter-problem -j ACCEPT 42 | -A ufw-before-input -p icmp --icmp-type echo-request -j ACCEPT 43 | 44 | # ok icmp code for FORWARD 45 | -A ufw-before-forward -p icmp --icmp-type destination-unreachable -j ACCEPT 46 | -A ufw-before-forward -p icmp --icmp-type source-quench -j ACCEPT 47 | -A ufw-before-forward -p icmp --icmp-type time-exceeded -j ACCEPT 48 | -A ufw-before-forward -p icmp --icmp-type parameter-problem -j ACCEPT 49 | -A ufw-before-forward -p icmp --icmp-type echo-request -j ACCEPT 50 | 51 | # allow dhcp client to work 52 | -A ufw-before-input -p udp --sport 67 --dport 68 -j ACCEPT 53 | 54 | # 55 | # ufw-not-local 56 | # 57 | -A ufw-before-input -j ufw-not-local 58 | 59 | # if LOCAL, RETURN 60 | -A ufw-not-local -m addrtype --dst-type LOCAL -j RETURN 61 | 62 | # if MULTICAST, RETURN 63 | -A ufw-not-local -m addrtype --dst-type MULTICAST -j RETURN 64 | 65 | # if BROADCAST, RETURN 66 | -A ufw-not-local -m addrtype --dst-type BROADCAST -j RETURN 67 | 68 | # all other non-local packets are dropped 69 | -A ufw-not-local -m limit --limit 3/min --limit-burst 10 -j ufw-logging-deny 70 | -A ufw-not-local -j DROP 71 | 72 | # allow MULTICAST mDNS for service discovery (be sure the MULTICAST line above 73 | # is uncommented) 74 | -A ufw-before-input -p udp -d 224.0.0.251 --dport 5353 -j ACCEPT 75 | 76 | # allow MULTICAST UPnP for service discovery (be sure the MULTICAST line above 77 | # is uncommented) 78 | -A ufw-before-input -p udp -d 239.255.255.250 --dport 1900 -j ACCEPT 79 | 80 | # don't delete the 'COMMIT' line or these rules won't be processed 81 | COMMIT 82 | -------------------------------------------------------------------------------- /0x13-firewall/README.md: -------------------------------------------------------------------------------- 1 | # Firewall 2 | 3 | In this project, I used `ufw` to configure firewalls on my issued web servers. 4 | 5 | ## Tasks :page_with_curl: 6 | 7 | * **0. Block all incoming traffic but** 8 | * [0-block_all_incoming_traffic_but](./0-block_all_incoming_traffic_but): Bash 9 | script that installs a `ufw` firewall to block all incoming traffic except for 10 | ports `22`, `443` and `80` on a web server. 11 | 12 | * **2. Port forwarding** 13 | * [100-port_forwarding](./100-port_forwarding): `ufw` configuration file that 14 | configures a firewall to redirect port `8080/TCP` to port `80/TCP`. 15 | -------------------------------------------------------------------------------- /0x14-mysql/4-mysql_configuration_primary: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. 2 | # 3 | # This program is free software; you can redistribute it and/or modify 4 | # it under the terms of the GNU General Public License, version 2.0, 5 | # as published by the Free Software Foundation. 6 | # 7 | # This program is also distributed with certain software (including 8 | # but not limited to OpenSSL) that is licensed under separate terms, 9 | # as designated in a particular file or component or in included license 10 | # documentation. The authors of MySQL hereby grant you an additional 11 | # permission to link the program and your derivative works with the 12 | # separately licensed software that they have included with MySQL. 13 | # 14 | # This program is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License, version 2.0, for more details. 18 | # 19 | # You should have received a copy of the GNU General Public License 20 | # along with this program; if not, write to the Free Software 21 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | 23 | # 24 | # The MySQL Server configuration file. 25 | # 26 | # For explanations see 27 | # http://dev.mysql.com/doc/mysql/en/server-system-variables.html 28 | 29 | [mysqld] 30 | pid-file = /var/run/mysqld/mysqld.pid 31 | socket = /var/run/mysqld/mysqld.sock 32 | datadir = /var/lib/mysql 33 | log-error = /var/log/mysql/error.log 34 | 35 | 36 | # By default we only accept connections from localhost 37 | #--disabled inorder to enable mysql replication 38 | #bind-address = 127.0.0.1 39 | 40 | # Disabling symbolic-links is recommended to prevent assorted security risks 41 | symbolic-links=0 42 | 43 | # setting server id 44 | server-id = 1 45 | 46 | # setting the base name & location of mysql bunary log file 47 | log_bin = /var/log/mysql/mysql-bin.log 48 | 49 | # name of database to replicate 50 | binlog_do_db = tyrell_corp -------------------------------------------------------------------------------- /0x14-mysql/4-mysql_configuration_replica: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. 2 | # 3 | # This program is free software; you can redistribute it and/or modify 4 | # it under the terms of the GNU General Public License, version 2.0, 5 | # as published by the Free Software Foundation. 6 | # 7 | # This program is also distributed with certain software (including 8 | # but not limited to OpenSSL) that is licensed under separate terms, 9 | # as designated in a particular file or component or in included license 10 | # documentation. The authors of MySQL hereby grant you an additional 11 | # permission to link the program and your derivative works with the 12 | # separately licensed software that they have included with MySQL. 13 | # 14 | # This program is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License, version 2.0, for more details. 18 | # 19 | # You should have received a copy of the GNU General Public License 20 | # along with this program; if not, write to the Free Software 21 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | 23 | # 24 | # The MySQL Server configuration file. 25 | # 26 | # For explanations see 27 | # http://dev.mysql.com/doc/mysql/en/server-system-variables.html 28 | 29 | [mysqld] 30 | pid-file = /var/run/mysqld/mysqld.pid 31 | socket = /var/run/mysqld/mysqld.sock 32 | datadir = /var/lib/mysql 33 | log-error = /var/log/mysql/error.log 34 | 35 | # By default we only accept connections from localhost 36 | # bind-address = 127.0.0.1 37 | 38 | # setting server id 39 | server-id = 2 40 | 41 | # Disabling symbolic-links is recommended to prevent assorted security risks 42 | symbolic-links=0 43 | 44 | # setting the base name & location of mysql bunary log file 45 | log_bin = /var/log/mysql/mysql-bin.log 46 | 47 | # name of database to replicate 48 | binlog_do_db = tyrell_corp 49 | 50 | # setting location of the replica's relay log file 51 | relay-log = /var/log/mysql/mysql-relay-bin.log 52 | -------------------------------------------------------------------------------- /0x14-mysql/5-mysql_backup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # backup and compress my databases 3 | mysqldump --all-databases -u root --password="$1" > backup.sql 4 | day=$(date +"%d") 5 | month=$(date +"%m") 6 | year=$(date +"%Y") 7 | file_name="$day-$month-$year.tar.gz" 8 | tar -czvf "$file_name" backup.sql 9 | -------------------------------------------------------------------------------- /0x14-mysql/README.md: -------------------------------------------------------------------------------- 1 | # Mysql 2 | 3 | This project involved learning how to configure database servers in a 4 | primary-replica model. I configured the two servers provided to me by 5 | ALX in a MySQL primary-replica setup with a dummy database, and wrote 6 | a Bash script to automate generation of database backups. 7 | 8 | ## Tasks :page_with_curl: 9 | 10 | * [4-mysql_configuration_primary](./4-mysql_configuration_primary): The MySQL 11 | `my.conf` configuration file used to set up my first server as a primary database 12 | server on the database `tyrell_corp`. 13 | 14 | * [4-mysql_configuration_replica](./4-mysql_configuration_replica): The MySQL 15 | `my.conf` configuration file used to set up my second server as the replica 16 | database server on the database `tyrell_corp`. 17 | 18 | * [5-mysql_backup](./5-mysql_backup): Bash script that generates a compressed 19 | `tar.gz` archive from a MySQL dump. 20 | * Usage: `./5-mysql_backup ` 21 | * Generates a dump containing all MySQL databases on the root server. 22 | * Names the resulting tar archive in the format `day-month-year.tar.gz`. 23 | -------------------------------------------------------------------------------- /0x15-api/0-gather_data_from_an_API.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Returns to-do list information for a given employee ID.""" 3 | import requests 4 | import sys 5 | 6 | if __name__ == "__main__": 7 | url = "https://jsonplaceholder.typicode.com/" 8 | user = requests.get(url + "users/{}".format(sys.argv[1])).json() 9 | todos = requests.get(url + "todos", params={"userId": sys.argv[1]}).json() 10 | 11 | completed = [t.get("title") for t in todos if t.get("completed") is True] 12 | print("Employee {} is done with tasks({}/{}):".format( 13 | user.get("name"), len(completed), len(todos))) 14 | [print("\t {}".format(c)) for c in completed] 15 | -------------------------------------------------------------------------------- /0x15-api/1-export_to_CSV.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Exports to-do list information for a given employee ID to CSV format.""" 3 | import csv 4 | import requests 5 | import sys 6 | 7 | if __name__ == "__main__": 8 | user_id = sys.argv[1] 9 | url = "https://jsonplaceholder.typicode.com/" 10 | user = requests.get(url + "users/{}".format(user_id)).json() 11 | username = user.get("username") 12 | todos = requests.get(url + "todos", params={"userId": user_id}).json() 13 | 14 | with open("{}.csv".format(user_id), "w", newline="") as csvfile: 15 | writer = csv.writer(csvfile, quoting=csv.QUOTE_ALL) 16 | [writer.writerow( 17 | [user_id, username, t.get("completed"), t.get("title")] 18 | ) for t in todos] 19 | -------------------------------------------------------------------------------- /0x15-api/2-export_to_JSON.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Exports to-do list information for a given employee ID to JSON format.""" 3 | import json 4 | import requests 5 | import sys 6 | 7 | if __name__ == "__main__": 8 | user_id = sys.argv[1] 9 | url = "https://jsonplaceholder.typicode.com/" 10 | user = requests.get(url + "users/{}".format(user_id)).json() 11 | username = user.get("username") 12 | todos = requests.get(url + "todos", params={"userId": user_id}).json() 13 | 14 | with open("{}.json".format(user_id), "w") as jsonfile: 15 | json.dump({user_id: [{ 16 | "task": t.get("title"), 17 | "completed": t.get("completed"), 18 | "username": username 19 | } for t in todos]}, jsonfile) 20 | -------------------------------------------------------------------------------- /0x15-api/3-dictionary_of_list_of_dictionaries.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Exports to-do list information of all employees to JSON format.""" 3 | import json 4 | import requests 5 | 6 | if __name__ == "__main__": 7 | url = "https://jsonplaceholder.typicode.com/" 8 | users = requests.get(url + "users").json() 9 | 10 | with open("todo_all_employees.json", "w") as jsonfile: 11 | json.dump({ 12 | u.get("id"): [{ 13 | "task": t.get("title"), 14 | "completed": t.get("completed"), 15 | "username": u.get("username") 16 | } for t in requests.get(url + "todos", 17 | params={"userId": u.get("id")}).json()] 18 | for u in users}, jsonfile) 19 | -------------------------------------------------------------------------------- /0x15-api/README.md: -------------------------------------------------------------------------------- 1 | # API 2 | 3 | This project was further practice in working with API's. I collected data from the 4 | [JSONPlaceholder REST API](https://jsonplaceholder.typicode.com/), and learned how 5 | to export it to either CSV or JSON format. 6 | 7 | ## Tasks :page_with_curl: 8 | 9 | * **0. Gather data from an API** 10 | * [0-gather_data_from_an_API.py](./0-gather_data_from_an_API.py): Python script 11 | that returns information on the to-do list progress of a given employee ID. 12 | * Usage: `python3 0-gather_data_from_an_API.py `. 13 | * Output: `Employee is done with tasks(<# completed tasks>/):` 14 | 15 | * **1. Export to CSV** 16 | * [1-export_to_CSV.py](./1-export_to_CSV.py): Python script exports to-do list 17 | information of a given employee ID to CSV format. 18 | * Usage: `python3 1-export_to_CSV.py ` 19 | * File name: `.csv`. 20 | * Format: `"","","",""`. 21 | 22 | * **2. Export to JSON** 23 | * [2-export_to_JSON.py](./2-export_to_JSON.py): Python script that exports 24 | to-do list information of a given employee ID to JSON format. 25 | * Usage: `python3 2-export_to_JSON.py ` 26 | * File name: `.json` 27 | * Format: `{ "": [ {"task": "", "completed": , "username": ""}}, ... ]}` 28 | 29 | * **3. Dictionary of list of dictionaries** 30 | * [3-dictionary_of_list_of_dictionaries.py](./3-dictionary_of_list_of_dictionaries.py): 31 | Python script that exports to-do list information for all employees to JSON format. 32 | * Usage: `python3 3-dictionary_of_list_of_dictionaries.py` 33 | * File name: `todo_all_employees.json` 34 | * Format: `{ "": [ {"username": "", "task": "", "completed": }, {"username": "", "task": "", "completed": }, ... ], "": [ {"username": "", "task": "", "completed": }, {"username": "", "task": "", "completed": }, ... ]}` 35 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # ALX-system_engineering-devops 3 | 4 | ![alx](https://user-images.githubusercontent.com/110563322/187611536-93373cfb-4350-4351-acf5-d1b081a13987.jpeg) 5 | 6 | 7 | ## This repo contain tasks on Shell basics and scripting. 8 | 9 | # What is shell Scripting? 10 | #### A shell script is small computer program that is designed to be run or executed by the Unix shell, which is a command-line interpreter. A shell script is basically a set of commands that the shell in a Unix-based operating system follows. Like actual programs, the commands in the shell script can contain parameters and subcommands that tell the shell what to do. The shell script is usually contained in a simple text file. 11 | 12 | ![shell](https://user-images.githubusercontent.com/110563322/187611911-1204f46c-de58-4288-b47c-5180b87153ef.jpeg) 13 | 14 | A shell script is program composed of a series of operating system commands that are executed by the command-line interpreter or the shell in sequence. It is called a shell script because the individual commands are combined to form a "script" that the shell follows and executes, very much like how an actor/actress follows the script written for him/her. 15 | A shell script is useful for repetitive tasks that would become time consuming if manually typed in then executed one at a time. For example, programmers and developers use shell scripts to automate their code compile process so that instead of typing in a series of long commands, they just execute the shell script. This is especially helpful for them because they often compile and test code, sometimes multiple times, in one single minute. 16 | 17 | ![shell script](https://user-images.githubusercontent.com/110563322/187611568-07481f78-5495-4589-9895-6b63b4321923.png) 18 | 19 | 20 | ### Scripts start with a bash bang. 21 | Scripts are also identified with a shebang. Shebang is a combination of bash # and bang !  followed the the bash shell path. This is the first line of the script. Shebang tells the shell to execute it via bash shell. Shebang is simply an absolute path to the bash interpreter. 22 | Below is an example of the shebang statement. 23 | 24 | 25 | #### #! /bin/bash 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 |

Connect with me:

39 |

40 | techbydami 41 | agboola-olawale-damilola-7b2132246 42 | 19747131 43 | techbydami 44 | @techbydami 45 | techbydami 46 | 5007 47 |

48 | --------------------------------------------------------------------------------