diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..20f3d97 Binary files /dev/null and b/.DS_Store differ diff --git a/markdown/Deep Dive: Discord-Linux Automated Container Platform.md b/markdown/Deep Dive: Discord-Linux Automated Container Platform.md index 07d60fa..82bf2d0 100644 --- a/markdown/Deep Dive: Discord-Linux Automated Container Platform.md +++ b/markdown/Deep Dive: Discord-Linux Automated Container Platform.md @@ -915,6 +915,38 @@ await cmd('bash /home/scripts/check_exist.sh ' + sshSurfID).then(out => { }); ``` +## The check_exist.sh script + +```bash +#!/bin/bash +if [ $( docker ps -a | grep $1 | wc -l ) -gt 0 ]; then + echo "1" +else + echo "0" +fi +``` + +This Bash script checks if a Docker container with a specific name or ID (passed as an argument to the script) exists. Here's a breakdown of what each part does: + + **`#!/bin/bash`**: + - This is the shebang line that tells the system to run the script using the Bash shell. + + **`if [ $( docker ps -a | grep $1 | wc -l ) -gt 0 ]; then`**: + - This checks if there is any Docker container matching the argument (`$1`) provided when running the script. + - **`docker ps -a`**: Lists all containers, including both running and stopped ones. + - **`grep $1`**: Searches for the container name or ID specified by `$1` in the list of containers. + - **`wc -l`**: Counts the number of lines output by the `grep` command, i.e., the number of matching containers. + - **`-gt 0`**: Checks if the count is greater than zero, meaning there is at least one match. + + **`echo "1"`**: + - If a container with the given name or ID is found, it prints `1`, indicating the container exists. + + **`else`**: + - This handles the case where no matching container is found. + + **`echo "0"`**: + - If no container matches, it prints `0`, indicating the container does not exist. + This step ensures that users cannot attempt to write to a non-existent container, which prevents potential errors and ensures smooth operation. ### Capturing User Input with a Modal