diff --git a/src/day_2/tasks.md b/src/day_2/tasks.md index 732c4c9..7346648 100644 --- a/src/day_2/tasks.md +++ b/src/day_2/tasks.md @@ -30,7 +30,13 @@ We will use the program `inotifywait`. This program can monitor a directory and 1. Based on the output, choose an event that you want to listen to with `inotifywait` that tells you when a file is _completely_ added to the directory `jobs`. Use the manual to read more about specific events. 1. Find an option that lets you tell `inotifywait` to only notify when the choosen event occurs. 1. Find an option that lets you format the output of the notification of `inotifywait`. Since we only listen on one event and monitor only one directory, an output that shows only the name of the new file should be enough. -1. Enter the command that you have until now in a script. Now extend it by using a `while` loop that continously listens on the notifications of `inotifywait`. +1. Enter the command that you have until now in a script. Now extend it by using a `while` loop that continously listens on the notifications of `inotifywait`. Use the following snippet while replacing the sections with `(...)`: + ```bash + inotifywait (...) | while read FILENAME + do + (...) + done + ``` 1. After a notification, the body of the `while` loop should first print the name of the script that was added. From now on, we only want to add scripts to the `jobs` directory. 1. After printing the script name, run the script! 1. Save the standard output and standard error of the script into two separate files in the `logs` directory. If the name of the script is `job.sh` for example, then the output should be in the files `logs/job.sh.out` and `logs/job.sh.err`. @@ -56,6 +62,33 @@ If the name of the job script is `job.sh` for example, the job script should be Use variables to write the script to make it more understandable. +#### Help + +To save the output of a command into a variable, use you have to use the following syntax: + +```bash +DATE=$(date ...) +``` + +Replace `...` with your code. + +To read the `n`-th argument that is provided to a script you write, you have to use `$n`. + +Example script called `arg.sh`: + +```bash +#!/usr/bin/bash + +echo "The first argument is: $1" +``` + +When you run this script with an argument: + +```console +$ ./arg.sh "Hello" +The first argument is: Hello +``` + ## Task: Submit a job Write a small scripts of your choice that require a long time to run and submit them using the script from the last task. Make sure that the scheduler is running in the background.