From 6f69ec66a4044e895e34724a0cfcb30cbccab1bd Mon Sep 17 00:00:00 2001 From: Raven Scott Date: Wed, 18 Sep 2024 19:33:34 -0400 Subject: [PATCH] Update article --- .DS_Store | Bin 0 -> 6148 bytes ...cord-Linux Automated Container Platform.md | 32 ++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..20f3d976656172b17c70feff413bf68c817d7274 GIT binary patch literal 6148 zcmeHK&2G~`5S~rb)TTvBB`U!I$r9HzB&8}sTuew09Jn+H4uFCkN5$0jMsZRfqDa2O zGw=$Wc@f@)6MQ?nmF$Fy8;a15HT%u(&g{?U^{$tQL~kB-iJC;@Ko!<+A^C%-dZlYp zGbJuia2uZ}dy&Xdn8`ECZXyfckbD6wm}uo2uWh+7zBa+rLM^c|Z6l^T8~b&9h!GeXDY> zq)ftVI|yIL<9yh>^IWF0AWp|q4v3>MT;9Ej(@5q$IZvaEV+XpzaUFNqyth~!ADy(k z!*2KSvgIwF9CcdW@uQRF(sd3VJbZdKyhtun`I)Cm0-GAkZG+eF1;!qwARwYK4MB;r z=9C~;-T*;}xDVelf%_mjpb-cR=p6osh?1OV`eCn7D%5DoE$pqda8umRmAD4t<`km8 zm`2stRy$wub?J;w@$&oh64=HJqiO^%jIX7Iu}xQKcZ?;m!T>LcvM0K-vIz{B&^K6UL=8mfP@oPK=87S7 zILbZa=Nl|E>TnX~@*zym!rV{<_m1{Gb|>L$w5eslGEik;OJ|$v{6D?<{$CBUIm>`$ z;J;!()cb>e4^uK{>)PbhS?fVRK$R%JLL-MDF~>0*>L|VoWkH>%44`kY(1;R<{Sjaq LY+@PsrwsfC+`P1h literal 0 HcmV?d00001 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