mirror of
https://codeberg.org/Mo8it/How_To_Linux.git
synced 2024-11-25 01:41:36 +00:00
Add tipps to the tasks of day 2
This commit is contained in:
parent
70d0129f5b
commit
89e2a5745c
1 changed files with 34 additions and 1 deletions
|
@ -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. 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 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. 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 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. 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`.
|
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.
|
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
|
## 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.
|
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.
|
||||||
|
|
Loading…
Reference in a new issue