-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path04-Bash.Rmd
84 lines (64 loc) · 2.64 KB
/
04-Bash.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# BASH
On this section we will write some hints on the Bourne Again Shell (BASH), a command interpreter used in several *nix systems, such as Linux, Unix, MacOS and recently incorporated into Windows through PowerShell. This will be more of a collection of hints, and not substituting a full knowledge of BASH and the Operating System in which is running.
## Screen
Screen is a tool you can use to keep a ssh session run through BASH alive. Why it is useful(?):
1. When you have unreliable internet connections connections (ex.: Wifi, cellphone);
2. Power outages;
3. Your local machine freezes, or have any other issue, and your connection is killed;
4. Any random reason that blocks your local terminal to access the remote ssh session.
### How to use it
Some useful description is available in [this website](https://web.archive.org/web/20230606181644/https://www.networkworld.com/article/3441777/how-the-linux-screen-tool-can-save-your-tasks-and-your-sanity-if-ssh-is-interrupted.html), and on the app documentation. But you can proceed as follows:
### Creating a session
You create a new session, named _session_01_ as:
```{bash, eval=FALSE}
screen -S session_01
```
### See all available sessions
```{bash, eval=FALSE}
screen -ls
```
You probably will see something like this:
```
There are screens on:
6617.session_00 (09/26/2019 04:35:30 PM) (Detached)
1946.session_01 (09/26/2019 02:51:50 PM) (Detached)
2 Sockets in /run/screen/S-shs
```
### Reattach to a previously established session
Let's say you want to attach to _session_00_:
```{bash, eval=FALSE}
screen -r session_00
```
### Finishing a session
Let's say you want to finish _session_01_. You first enter in another session, and:
```{bash, eval=FALSE}
screen -XS 1946 quit
```
If the session you are aiming to finish is the last one, then:
* **ctrl + A**;
* **k**;
* and **y**.
## Watch
Watch is a program that runs commands using a clock. In our case, watch is kind
of useful when needing to monitor an application shell output. Common cases in HPC
are when you need to see updates in `nvidia-smi` or slurm `squeue` command.
The base syntax is:
```{bash, eval=FALSE}
watch -n XX command
```
In which:
* **XX** is the refresh rate in seconds;
* **command** is the bash command you want to refresh the output
### Slurm queue example
The base syntax is:
```{bash, eval=FALSE}
watch -n 5 squeue -u username
```
In which:
* **username** is the username in the slurm cluster;
### NVIDIA card output
The base syntax is:
```{bash, eval=FALSE}
watch -n 5 nvidia-smi
```
It refreshes every 5 seconds the running info from the NVIDIA card in the node (this will fail on CPU-only nodes)