Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions subjects/devops/append-output/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

### Instructions

Create a file `append-output.sh` that will get the output of a file and parse it, and then write it to a file with a specific format using a single command.
Create a shell script named `append-output.sh` that processes the content of an existing file and writes the result into another file using a single command.

Get the content of the file `songs.txt`, parse it with the `grep` command to filter the file in order to get all the songs from the artist whose names start with `J`, and write the output to the existing file `results.txt`, check the example below:
Specifically, read the contents of the file `songs.txt`, filter them with the `grep` command to select only the songs by artists whose names begin with the letter **J**, and append the filtered output to the file `results.txt`.

### Usage

Expand Down
2 changes: 1 addition & 1 deletion subjects/devops/auto-exec-bin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ $ ls -l ~/myBins # the binary
01exec
$ 01exec
error: command not found: 01exec
$ ./auto-exec-bin.sh
$ source ./auto-exec-bin.sh
$ 01exec
Hello 01 Scripting Pool
$ cd /{random-path} && 01exec
Expand Down
57 changes: 57 additions & 0 deletions subjects/devops/candidates-checker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
## Candidates checker

### Instructions

Create a file `candidates_checker.py` which will receive the number of candidates as the only argument.
If a wrong number of arguments is passed the script will print `Error: wrong number of arguments` and exit with `1`.

When provided, the argument will always be convertible to `int`, the script will then ask for each candidate the name as string and the age as number.

Once the information for each candidate is retrieved for each of them the script will check the age and print one of the following results:

- `"[name] is not eligible (underaged)"` when the age is less than 18.
- `"[name] is not eligible (over the legal age)"` when the age is more than 60.
- `"[name] is eligible"` when the age is between 18 and 60 (included).

> You must use dictionaries to save the data about the candidates.

### Usage

Here is an example of your script running:

```console
$ python3 candidates_checker.py 3
Add a new candidate:
name: Edoardo
age: 17
Add a new candidate:
name: Michele
age: 60
Add a new candidate:
name: Lea
age: 61
Edoardo is not eligible (underaged)
Michele is eligible
Lea is not eligible (over the legal age)
$
```

Here is an example of bad usage:

```console
$ python3 candidates_checker.py
Error: wrong number of arguments
$
```

### Hints

- In order to succeed your script should print **exactly** the same output as the one in the usage section. So `Add a new candidate:`, `name: ` and `age: ` should be written in the exact same way and order.

- Tough it is not mandatory you could use `if __name__ == '__main__':` to specify the entrypoint of your script.

### References

- [Function strip()](https://docs.python.org/3.11/library/stdtypes.html?highlight=strip#str.strip)
- [String multiplication](https://www.geeksforgeeks.org/create-multiple-copies-of-a-string-in-python-by-using-multiplication-operator/)
- [Entrypoint for a Python script](https://realpython.com/if-name-main-python/)
12 changes: 6 additions & 6 deletions subjects/devops/check-user/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

### Instructions

In this exercise you will make a script `check-user.sh` that will take 2 arguments and return information about the selected user, always ended by a new line.
In this exercise, you will create a script called `check-user.sh` that accepts two arguments and returns information about a specified user. Each output should end with a newline.

The first argument will be a flag defining the behavior of the script:
The **first argument** is a flag that defines the script’s behavior:

- `-e`: check if the user exists, returns `yes` or `no` appropriately.
- `-i`: returns information about the user.
- `-e`: Check if the user exists, returning `yes` or `no` accordingly.
- `-i`: Display information about the user.

The second argument will be the name of the checked user.
The **second argument** is the username to be checked.

> The information about the user will be formatted in the same way it appears in `/etc/passwd`.
The user information must be displayed in the same format as it appears in `/etc/passwd`.

### Usage

Expand Down
15 changes: 15 additions & 0 deletions subjects/devops/cl-camp3/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## cl-camp3

### Instructions

"start looking ..."

Create a file `look`, which will look for and show, in the current directory and its sub-folders:

- everything that starts with an `a` or,
- all the files ending with a `z` or,
- all files starting with `z` and ending with `a!`.

### Hint

Read the `find` man...
15 changes: 15 additions & 0 deletions subjects/devops/cl-camp6/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## cl-camp6

### Instructions

"Now, do your inventory"

Create a file `countfiles.sh`, which will print the number **(and only the number)** of regular files and folders contained in the current directory and its sub-folders (the current directory must be included in the count):

### Usage

```console
$ ./countfiles.sh | cat -e
12$
$
```
11 changes: 11 additions & 0 deletions subjects/devops/cl-camp8/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## cl-camp8

### Instructions

"pick your equipment"

Write a command line in a `skip.sh` file that prints the result of a `ls -l` skipping 1 line out of 2, starting with the **first** one.

### Hint

`awk` or `sed` can do the job.
38 changes: 38 additions & 0 deletions subjects/devops/clean-the-list/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
## Clean the list

### Instructions

Create a file `clean_the_list.py` that contains a function `clean_list` which takes and returns a list of strings and performs the following operations on each list item:

- Removes all spaces before and after (but not between words).

- Capitalizes the first letter (first letter only, other ones should be to lowercase).

- Adds its index number before a separator `x/ `.

- An empty list as input should return an empty list as output.

- And don't forget the milk! (add it at the end of the list if missing).

### Usage

Here is an example of how to use the `clean_list` function:

```python
import clean_the_list
shopping_list = ['tomatoes', 'pastas', 'milk', 'salt']
print(clean_the_list.clean_list(shopping_list))
```

This will output:

```console
$ python test.py
['1/ Tomatoes', '2/ Pastas', '3/ Milk', '4/ Salt']
$
```

### References

[String strip method](https://www.w3schools.com/python/ref_string_strip.asp)
[String capitalize method](https://www.w3schools.com/python/ref_string_capitalize.asp)
32 changes: 32 additions & 0 deletions subjects/devops/concat-string/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
## concat_string

### Instructions

Create a file `concat_string.py` that contains a function `concat` which takes in two strings as parameters and performs the following operations:

- Concatenates the two strings by adding a comma and space between them.

- Returns the resulting string.

### Usage

Here is an example of how to use the `concat` function in a `test.py` script:

```python
import concat_string
string1 = "Hello"
string2 = "World"
print(concat_string.concat(string1, string2))
```

Below is the expected output:

```console
$ python3 test.py
Hello, World
$
```

### References

[string concatenation](https://docs.python.org/3/tutorial/introduction.html#text)
64 changes: 64 additions & 0 deletions subjects/devops/credentials-searches/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
## credentials_searches

### Instructions

Create a file `credentials_searches.py` that contains a function `credentials_search` which takes no parameters and searches for the keys `password` and `secret` in a file called `logs.json`.

- If both keys are found, the function should create a new json file named `credentials.json` and save the values of those keys in it.

- If only one of the keys is found, the function should create a new json file named `credentials.json` and save the value of that key in it.

- If neither key is found, the function should not create the `credentials.json` file.

- If the `logs.json` file is empty or is not a json file, the function should not create the `credentials.json` file.

- If the `logs.json` file does not exist, the function should not create the `credentials.json` file.

- If the keys are found in a nested object, the function should create the `credentials.json` file and save the values of the keys in it.

### Usage

Here is an example of how to use the credentials_search function:

With this file `logs.json`:

```json
{
"password": "test_password",
"other": "value",
"secret": "test_secret"
}
```

If you run your function:

```python
credentials_search()
```

Your function should generate this file `credentials.json`:

```json
{
"password": "test_password",
"secret": "test_secret"
}
```

### Hints

- The `json` module can be used to read and write JSON files.

- The `os` module can be used to check if a file exists and remove a file.

- Remember that the function should be able to search for the keys `password` and `secret` in nested json objects.

- Using the `isinstance` function could be useful to check if a value is for example a dict.

### References

- [json module](https://www.w3schools.com/python/python_json.asp)

- [os module](https://docs.python.org/3/library/os.html)

- [isinstance function](https://www.w3schools.com/python/ref_func_isinstance.asp)
99 changes: 99 additions & 0 deletions subjects/devops/custom-calendar/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
## Custom calendar

### Instructions

Create a file `custom_calendar.py` which will have 2 functions:

- `day_from_number(day_number)`
- `day_to_number(day)`

Those functions perform conversion between day `index` and day `word`:

- 1 = Monday
- 2 = Tuesday
- 3 = Wednesday
- 4 = Thursday
- 5 = Friday
- 6 = Saturday
- 7 = Sunday

You should return `None` if the input is invalid (invalid number or day string).

### Usage

Here is a possible `test.py` to test your functions:

```python
import custom_calendar

print(custom_calendar.day_from_number(2))
print(custom_calendar.day_from_number(1))
print(custom_calendar.day_from_number(1000))
print(custom_calendar.day_to_number('Sunday'))
print(custom_calendar.day_to_number('invalid day'))
```

```console
$ python test.py
Tuesday
Monday
None
7
None
$
```

### Hints

Dictionaries:

A dictionary is a data type similar to arrays, but works with keys and values instead of indexes. Each value stored in a dictionary can be accessed using a key, which is any type of object (a string, a number, a list, etc.) instead of using its index to address it.

For example, a database of phone numbers could be stored using a dictionary like this:

```python
phonebook = {}
phonebook["John"] = 938477566
phonebook["Jack"] = 938377264
phonebook["Jill"] = 947662781
print(phonebook)
```

output:

```console
{'John': 938477566, 'Jack': 938377264, 'Jill': 947662781}
```

Alternatively, a dictionary can be initialized with the same values in the following notation:

```python
phonebook = {
"John" : 938477566,
"Jack" : 938377264,
"Jill" : 947662781
}
print(phonebook)
```

Dictionaries can be iterated over, just like a list. To iterate over key value pairs, use the following syntax:

```python
phonebook = {"John": 938477566, "Jack": 938377264, "Jill": 947662781}
for name, number in phonebook.items():
print("Phone number of %s is %d" % (name, number))
```

output:

```console
Phone number of John is 938477566
Phone number of Jack is 938377264
Phone number of Jill is 947662781
```

### References

- [None type](https://www.w3schools.com/python/ref_keyword_none.asp)
- [Dictionaries](https://docs.python.org/3/tutorial/datastructures.html#dictionaries)
- [Access an item in dictionary](https://www.w3schools.com/python/python_dictionaries_access.asp)
2 changes: 1 addition & 1 deletion subjects/devops/custom-ls/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Expected behavior:
```console
$ custom-ls
error: command not found: custom-ls
$ ./custom-ls.sh
$ source ./custom-ls.sh
$ custom-ls .
total ...
7784 -rw-r--r-- 1 <user> 3983261 Dec 17 22:02 .file1 # just an example
Expand Down
Loading
Loading