Help with a noscript
Hi all, I've decided to write a noscript for a lengthy process at work. I have a main box which I store driver packs for multiple devices, I'd like to copy the content of this directory into other servers.
My plan is to add the new driver files when we get a new model, then run this noscript to copy to the other servers. I'd also like for this to work for when I update existing driver packs. I do not want to copy content that already exists. How can I do this with the following noscript I have started? Hope this makes sense.
​
#!/bin/bash
#source directory
sourcedirectory="/images/drivers"
#remote username
remoteuser="username"
#array of remote server IPs
remoteservers=("10.xx.xx.xxx" "10.xx.xx.xxx")
#Destination directory on remote servers
destinationdirectory="/images/drivers"
#specify the user and group ownership for the copied directories
ownership="name:name
#Loop through each remote server and copy the contents
for server in "${remoteservers[@]}"; do
rsync -avs --ignore-existing --chown="$ownership" "$sourcedirectory/" "$remoteuser@$server:$destinationdirectory/"
done
​
​
https://redd.it/16rw9kl
@r_bash
Hi all, I've decided to write a noscript for a lengthy process at work. I have a main box which I store driver packs for multiple devices, I'd like to copy the content of this directory into other servers.
My plan is to add the new driver files when we get a new model, then run this noscript to copy to the other servers. I'd also like for this to work for when I update existing driver packs. I do not want to copy content that already exists. How can I do this with the following noscript I have started? Hope this makes sense.
​
#!/bin/bash
#source directory
sourcedirectory="/images/drivers"
#remote username
remoteuser="username"
#array of remote server IPs
remoteservers=("10.xx.xx.xxx" "10.xx.xx.xxx")
#Destination directory on remote servers
destinationdirectory="/images/drivers"
#specify the user and group ownership for the copied directories
ownership="name:name
#Loop through each remote server and copy the contents
for server in "${remoteservers[@]}"; do
rsync -avs --ignore-existing --chown="$ownership" "$sourcedirectory/" "$remoteuser@$server:$destinationdirectory/"
done
​
​
https://redd.it/16rw9kl
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Video Stripe Preview Generator
# Hello Everyone,
I just finished making a noscript to generate a striped preview image of a video (mp4, mkv, etc.) or image-sequence (gif, etc.) (with the help of FFmpeg), I'll definitely make it better going forward. For now, I'm just trying to debug and hunt down exceptions states and anomalies.
So here's the **REPO** for my Script, have at it and let me know how it performed, and if you find any odd behavior do let me know so that I can patch it up. And I'm also up for a good suggestion.(I know the Script looks bad and a bit UnOptimized and has a lot of sanity checks, but right now my priority is to find all exception/error states and handle it)
​
# Some Preview:
Command :
​
Default parameters
Command :
​
Row = 2 | Column = 4 | Width = 960
Command :
​
Row = 5 | Column = 2
​
# Credits :
**WING IT !!** — An Open Film from *blender Studio* was used to generate previews.
# Note:
I'm kinda new to the whole Linux, git, CLI, FFmpeg, etc. so feel free to be informal with the discussion, we'll probably need to have many back and forth before I come to a conclusion.
https://redd.it/16rz17d
@r_bash
# Hello Everyone,
I just finished making a noscript to generate a striped preview image of a video (mp4, mkv, etc.) or image-sequence (gif, etc.) (with the help of FFmpeg), I'll definitely make it better going forward. For now, I'm just trying to debug and hunt down exceptions states and anomalies.
So here's the **REPO** for my Script, have at it and let me know how it performed, and if you find any odd behavior do let me know so that I can patch it up. And I'm also up for a good suggestion.(I know the Script looks bad and a bit UnOptimized and has a lot of sanity checks, but right now my priority is to find all exception/error states and handle it)
​
# Some Preview:
Command :
video-stripe-preview -vf "WING IT - Blender Open Movie.mp4"​
Default parameters
Command :
video-stripe-preview -r 2 -c 4 -l 960 -vf "WING IT - Blender Open Movie.mp4"​
Row = 2 | Column = 4 | Width = 960
Command :
video-stripe-preview -r 5 -c 2 -vf "WING IT - Blender Open Movie.mp4"​
Row = 5 | Column = 2
​
# Credits :
**WING IT !!** — An Open Film from *blender Studio* was used to generate previews.
# Note:
I'm kinda new to the whole Linux, git, CLI, FFmpeg, etc. so feel free to be informal with the discussion, we'll probably need to have many back and forth before I come to a conclusion.
https://redd.it/16rz17d
@r_bash
GitLab
Scripts / Video Stripe Generator · GitLab
Need help with a noscript - Finding out when my car is in the driveway
My car has a Dashcam that will let me download files. There is already a way to synchronize my BlackVue dashcam with a local directory over a LAN. What I want to do is place a laptop in my living room and every 5 minutes see if it can see the Wi-Fi network that my Blackvue camera creates. If it does I want it to connect to that network then call the noscript to start transferring files.
I am not very knowledgeable when it comes to noscripting.
This is what I have written so far. I would appreciate help in cleaning it up.
​
​
https://redd.it/16scc1q
@r_bash
My car has a Dashcam that will let me download files. There is already a way to synchronize my BlackVue dashcam with a local directory over a LAN. What I want to do is place a laptop in my living room and every 5 minutes see if it can see the Wi-Fi network that my Blackvue camera creates. If it does I want it to connect to that network then call the noscript to start transferring files.
I am not very knowledgeable when it comes to noscripting.
This is what I have written so far. I would appreciate help in cleaning it up.
#!/bin/bashDashcamAP="" # Name of the wireless network I am looking forDashcamPA="" # Password of the wireless network I am looking for# <<Code to drop all wireless networks>>echo "Looking for network called " $DashcamAPif test -e "wifiscan.lock" thenecho "Wifi Scan done Less than 5 minutes ago"rm -f wifiscan.lock # to delete the lock filerm -f wifi.list # to delete the list of found networksrm -f AmIHome # to delete the flag file if the car was homesleep 5mtouch wifiscan.lock # To show the noscript was recently runecho "Preparing to scan wif"sh ./wifitest.shelse echo "Wifi Scan not done. Scanning now"touch wifiscan.locknmcli dev wifi rescannmcli -t -g SSID dev wifi > wifi.listgrep -i $DashcamAP wifi.list > AmIHomeif [ -s AmIHome ]; then touch IAmHome firm -f wifiscan.lockif test -e "IAmHome"thenecho "Network is found"# << Code to connect to the wireless network >># sh ./BlackVueSyncScript -- Will call the SyncScriptelseecho "Network not found"fifi​
​
https://redd.it/16scc1q
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
How to filter files with glob patterns?
Lets say i have these files in
file1.jar
file2.jar
file3suffix.jar
file4.txt
...
fileX.someotherextension
I need all `*.jar` files execpt those ended with `suffix.jar
Preferably i would somehow merge these 2 together.
​
https://redd.it/16srr4t
@r_bash
Lets say i have these files in
dir directory.file1.jar
file2.jar
file3suffix.jar
file4.txt
...
fileX.someotherextension
I need all `*.jar` files execpt those ended with `suffix.jar
. I've read this [https://www.gnu.org/software/bash/manual/html\_node/Pattern-Matching.html#Pattern-Matching](https://www.gnu.org/software/bash/manual/html_node/Pattern-Matching.html#Pattern-Matching)
... and:
* ls dir/.jar` gives me all jarsls dir/!(_suffix.jar) gives me good jars but also files with other extensionsPreferably i would somehow merge these 2 together.
​
https://redd.it/16srr4t
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
rm function does not work
I am trying to delete some text files but I am getting this error :
rm: /path/to/files/* No such file or directory
This is the actual command :
rm -r $PATHTOFILES”*”
Used * wildcard because my usecase requires to all files deleted regardless of file extension.
I am running an airflow DAG to call a shell noscript that delete all files from a local directory, then pull files from an SFTP server and place them within the same directory. Therefore it is the same airflow user creating the directory and placing the files.
Would appreciate any advice, thank you!
https://redd.it/16thf8z
@r_bash
I am trying to delete some text files but I am getting this error :
rm: /path/to/files/* No such file or directory
This is the actual command :
rm -r $PATHTOFILES”*”
Used * wildcard because my usecase requires to all files deleted regardless of file extension.
I am running an airflow DAG to call a shell noscript that delete all files from a local directory, then pull files from an SFTP server and place them within the same directory. Therefore it is the same airflow user creating the directory and placing the files.
Would appreciate any advice, thank you!
https://redd.it/16thf8z
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
How to run 2x readarray ... < <(...) in parallel ?
Hi folks,
Is it possible to run the above simultaneously?
Thank you.
https://redd.it/16ti9pr
@r_bash
Hi folks,
readarray -d '' a < <(my_function)
readarray -d '' b < <(my_function)
Is it possible to run the above simultaneously?
my_function runs complicated find ... -print0.Thank you.
https://redd.it/16ti9pr
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Hi, I'm sharing The dotfiles manager+ written in pure bash
https://github.com/yunielrc/ydf
https://redd.it/16tr45b
@r_bash
https://github.com/yunielrc/ydf
https://redd.it/16tr45b
@r_bash
GitHub
GitHub - yunielrc/ydf: A dotfiles manager+. Be ready to work in just a few minutes on your Fresh OS
A dotfiles manager+. Be ready to work in just a few minutes on your Fresh OS - yunielrc/ydf
Combined output of commands into variable
I know I can do
value=$(echo "FOO"; echo "BAR")
to get the combined output of the command group and set it to the variable. AFAIU, the commands will be run in a separate shell. Now, I was wondering whether it would be possible to achieve the same thing without starting a new shell, but I couldn't find the right syntax. The closest I got was
value=$({ echo "FOO"; echo "BAR"; })
but I suppose this is not what I wanted. This will run the command group locally in a new shell. The goal was to prevent the creation a new shell in the first place.
Any ideas?
Thanks.
https://redd.it/16tuegx
@r_bash
I know I can do
value=$(echo "FOO"; echo "BAR")
to get the combined output of the command group and set it to the variable. AFAIU, the commands will be run in a separate shell. Now, I was wondering whether it would be possible to achieve the same thing without starting a new shell, but I couldn't find the right syntax. The closest I got was
value=$({ echo "FOO"; echo "BAR"; })
but I suppose this is not what I wanted. This will run the command group locally in a new shell. The goal was to prevent the creation a new shell in the first place.
Any ideas?
Thanks.
https://redd.it/16tuegx
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
ndarray: tools for setting up and using N-dimensional / nested arrays in bash
A recent post here inspired me to pick up an old personal project for getting bash to work with N-dimensional/nested arrays. I got it working, so I figured id share it.
The [CODE](https://github.com/jkool702/bashndarray/blob/main/ndarray.bash) is on github. There are 5 functions:
`nd_usage` gives a brief usage example
`nd_set` writes data into the arrays at the end on the namerefs (the `A_0` and `A_1` arrays in the simple example above)
nd_clear unsets all the array and nameref variables
METHODOLOGY
It involves creating a framework of nameref arrays to handle all the dimensions except the last one (which is saved in the arrays themselves. The idea is to do something like
declare -n a_0='A_0'
declare -n a_1='A_1'
A=(a_0 a_1)
A_0=(1 2 3)
A_1=(4 5 6)
So to get the data at (1,2), you do `${A[1]}` which gives `a_1` which namerefs to A_1 then `${A_1[2]}` which gives the actual data. The use of the `a_1` and `a_0` are because bash doesnt directly support doing, say, `declare -n A[0]=A_0`...you have to nameref a dummy variable and then store that in an array.
USAGE EXAMPLE
this is the example that running `nd_usage` prints
# # # # # generate nameref framework.
# note: dont include the last dimension
source <(nd_create -a A 2 3 4)
# # # # # set array values
# pass data to be set on STDIN, and use function inputs to define basename + index ranges
source <(seq 1 $(( 2 3 4 5 )) | ndset A 0:1 0:2 0:3 0:4)
# # # # # extract various slices from the array
ndget A 0 \@ \@ \@
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
ndget A \@ 0 \@ \@
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
61 62 63 64 65
66 67 68 69 70
71 72 73 74 75
76 77 78 79 80
ndget A \@ \@ 0 \@
1 2 3 4 5
21 22 23 24 25
41 42 43 44 45
61 62 63 64 65
81 82 83 84 85
101 102 103 104 105
ndget A \@ \@ \@ 0
1
6
11
16
21
26
31
36
41
46
51
56
61
66
71
76
81
86
91
96
101
106
111
116
# # # # # cleanup
ndclear A
https://redd.it/16tvadk
@r_bash
A recent post here inspired me to pick up an old personal project for getting bash to work with N-dimensional/nested arrays. I got it working, so I figured id share it.
The [CODE](https://github.com/jkool702/bashndarray/blob/main/ndarray.bash) is on github. There are 5 functions:
`nd_usage` gives a brief usage example
nd_create sets up the nameref framework and declares the arrays`nd_set` writes data into the arrays at the end on the namerefs (the `A_0` and `A_1` arrays in the simple example above)
nd_get reads data out of the arrays. You can define lists/ranges on indices for any dimension and it will output all the data that falls into the n-dimensional slice of the array.nd_clear unsets all the array and nameref variables
METHODOLOGY
It involves creating a framework of nameref arrays to handle all the dimensions except the last one (which is saved in the arrays themselves. The idea is to do something like
declare -n a_0='A_0'
declare -n a_1='A_1'
A=(a_0 a_1)
A_0=(1 2 3)
A_1=(4 5 6)
So to get the data at (1,2), you do `${A[1]}` which gives `a_1` which namerefs to A_1 then `${A_1[2]}` which gives the actual data. The use of the `a_1` and `a_0` are because bash doesnt directly support doing, say, `declare -n A[0]=A_0`...you have to nameref a dummy variable and then store that in an array.
USAGE EXAMPLE
this is the example that running `nd_usage` prints
# # # # # generate nameref framework.
# note: dont include the last dimension
source <(nd_create -a A 2 3 4)
# # # # # set array values
# pass data to be set on STDIN, and use function inputs to define basename + index ranges
source <(seq 1 $(( 2 3 4 5 )) | ndset A 0:1 0:2 0:3 0:4)
# # # # # extract various slices from the array
ndget A 0 \@ \@ \@
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
ndget A \@ 0 \@ \@
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
61 62 63 64 65
66 67 68 69 70
71 72 73 74 75
76 77 78 79 80
ndget A \@ \@ 0 \@
1 2 3 4 5
21 22 23 24 25
41 42 43 44 45
61 62 63 64 65
81 82 83 84 85
101 102 103 104 105
ndget A \@ \@ \@ 0
1
6
11
16
21
26
31
36
41
46
51
56
61
66
71
76
81
86
91
96
101
106
111
116
# # # # # cleanup
ndclear A
https://redd.it/16tvadk
@r_bash
String substitution
I am new to Bash and am having a difficult time employing string substitution. In my code below, I am attempting to replace file paths that contain
#!/bin/bash
for f in /path/to/inputfiles/*.csv /path/to/inputfiles/.xlsx
do
if [[ $f == ".csv" ]]; then
$output={$f//.csv/.json}
fi
if [ $f == *".xlsx" ]; then
$output={$f//.xlsx/.json}
fi
echo $output
python3 API.py "$f" "$output" args
done
​
https://redd.it/16u2eoz
@r_bash
I am new to Bash and am having a difficult time employing string substitution. In my code below, I am attempting to replace file paths that contain
.csv or .xlsx extensions with the .json extension and the output for $output is always /path/to/input_files/file.csv//.csv/.json or /path/to/input_files/file.xlsx//.xlsx/.json. Could anyone help me to understand how I am using string substitution incorrectly here?#!/bin/bash
for f in /path/to/inputfiles/*.csv /path/to/inputfiles/.xlsx
do
if [[ $f == ".csv" ]]; then
$output={$f//.csv/.json}
fi
if [ $f == *".xlsx" ]; then
$output={$f//.xlsx/.json}
fi
echo $output
python3 API.py "$f" "$output" args
done
​
https://redd.it/16u2eoz
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
I want to add a crontab for ec2-user but it keeps adding it under root, how do I fix this?
* I am running some user data inside my EC2 instance which will always run as the root user as per AWS documentation
* I supply the EC2 instance a bunch of bash commands on launch and one of them is to invoke this file run-cron.sh
In terms of code it looks like this
cd "${ROOT_PATH}" || exit
git clone -b test/cron "${UTILS_REPO_URL}"
chown -R ec2-user:ec2-user ./utils
# https://askubuntu.com/a/889348/968824
find "${ROOT_PATH}/utils" -type f -iname "*.sh" -exec chmod +x {} \;
# shellcheck source=/dev/null
bash "${ROOT_PATH}/utils/src/ec2/run-cron.sh"
My run-cron.sh file looks like this
set -o pipefail
set -u
set -x
IFS=$'\n\t'
# https://stackoverflow.com/a/52879454/5371505
crontab <<EOF
0 0,4,8,12,16,20 * * * ec2-user /home/ec2-user/utils/src/elasticache/backup-elasticache-to-s3.sh > /tmp/backup-elasticache-to-s3.log 2>&1
0 0,4,8,12,16,20 * * * ec2-user /home/ec2-user/utils/src/rds/backup-rds-to-s3.sh > /tmp/backup-rds-to-s3.log 2>&1
EOF
My problem is that after my user data noscript runs, I logout of EC2 instance and log in again as ec2-user. When I run crontab -l it says no crontabs found for ec2-user. When I run sudo crontab -u root -l it shows the above jobs.
How do I add the crontab for ec2-user when running as root from user data noscript?
https://redd.it/16uh7jz
@r_bash
* I am running some user data inside my EC2 instance which will always run as the root user as per AWS documentation
* I supply the EC2 instance a bunch of bash commands on launch and one of them is to invoke this file run-cron.sh
In terms of code it looks like this
cd "${ROOT_PATH}" || exit
git clone -b test/cron "${UTILS_REPO_URL}"
chown -R ec2-user:ec2-user ./utils
# https://askubuntu.com/a/889348/968824
find "${ROOT_PATH}/utils" -type f -iname "*.sh" -exec chmod +x {} \;
# shellcheck source=/dev/null
bash "${ROOT_PATH}/utils/src/ec2/run-cron.sh"
My run-cron.sh file looks like this
set -o pipefail
set -u
set -x
IFS=$'\n\t'
# https://stackoverflow.com/a/52879454/5371505
crontab <<EOF
0 0,4,8,12,16,20 * * * ec2-user /home/ec2-user/utils/src/elasticache/backup-elasticache-to-s3.sh > /tmp/backup-elasticache-to-s3.log 2>&1
0 0,4,8,12,16,20 * * * ec2-user /home/ec2-user/utils/src/rds/backup-rds-to-s3.sh > /tmp/backup-rds-to-s3.log 2>&1
EOF
My problem is that after my user data noscript runs, I logout of EC2 instance and log in again as ec2-user. When I run crontab -l it says no crontabs found for ec2-user. When I run sudo crontab -u root -l it shows the above jobs.
How do I add the crontab for ec2-user when running as root from user data noscript?
https://redd.it/16uh7jz
@r_bash
Ask Ubuntu
Command to perform a recursive chmod to make all .sh files within a directory executable?
Trying to perform a recursive chmod on all the .sh files in a directory to make them executable
Can you guess the output of these tr(1) commands?
echo abcdefghijklmnopqrstuvwxyz
echo abcdefghijklmnopqrstuvwxyz | tr -d [:blank:\]
echo abcdefghijklmnopqrstuvwxyz | tr -d '[:blank:\]'
Now that you've tried it, and assuming you got what I did, how do you explain >!the missing letter l in the 2nd command!<?
https://redd.it/16ums5y
@r_bash
echo abcdefghijklmnopqrstuvwxyz
echo abcdefghijklmnopqrstuvwxyz | tr -d [:blank:\]
echo abcdefghijklmnopqrstuvwxyz | tr -d '[:blank:\]'
Now that you've tried it, and assuming you got what I did, how do you explain >!the missing letter l in the 2nd command!<?
https://redd.it/16ums5y
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Variable with double quotes in cURL header
Hello all,
I've been trying to figure something out here for a bit. I am pulling an Etag from a request header and then attempting to use that in the "If-Match" to patch.
export ETag=$(curl -I -X GET https://{uri} -H "Authorization: Bearer ${BEARER}" 2>/dev/null | grep Etag | head -1 | cut -d":" -f2)
The tag gets stored as expected but contains double quotes: W/"12345678910"
When passing in a patch, I am struggling with how to format it.
curl --location --request PATCH https://{uri} \
-H "Authorization: Bearer ${BEARER}" \
-H "Content-Type: application/json" \
-H "If-Match: ${ETag}" \
--data '{}'
Since the tag itself contains double quotes, I am finding it difficult in how to pass it to the header for the match. Does anyone have any ideas on how I can get around this? TIA.
https://redd.it/16vcmvh
@r_bash
Hello all,
I've been trying to figure something out here for a bit. I am pulling an Etag from a request header and then attempting to use that in the "If-Match" to patch.
export ETag=$(curl -I -X GET https://{uri} -H "Authorization: Bearer ${BEARER}" 2>/dev/null | grep Etag | head -1 | cut -d":" -f2)
The tag gets stored as expected but contains double quotes: W/"12345678910"
When passing in a patch, I am struggling with how to format it.
curl --location --request PATCH https://{uri} \
-H "Authorization: Bearer ${BEARER}" \
-H "Content-Type: application/json" \
-H "If-Match: ${ETag}" \
--data '{}'
Since the tag itself contains double quotes, I am finding it difficult in how to pass it to the header for the match. Does anyone have any ideas on how I can get around this? TIA.
https://redd.it/16vcmvh
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Provide password securely to shell noscript
Is there a built in command that can provide a password to a shell noscript? Thought I could use
Any options using a command that is part of bash or available on most distros?
https://redd.it/16voh9d
@r_bash
Is there a built in command that can provide a password to a shell noscript? Thought I could use
read but it can be sniffed. https://unix.stackexchange.com/questions/563718/sniff-password-entered-with-read-and-passed-as-a-command-line-argumentsystemd-ask-password looks like it is about system passwords not for noscripts?Any options using a command that is part of bash or available on most distros?
https://redd.it/16voh9d
@r_bash
Unix & Linux Stack Exchange
Sniff password entered with read and passed as a command line argument
I'd like to show that entering passwords via read is insecure.
To embed this into a half-way realistic scenario, let's say I use the following command to prompt the user for a password and have 7z¹
To embed this into a half-way realistic scenario, let's say I use the following command to prompt the user for a password and have 7z¹
A simple bash noscript if all you need is a simple (really, really simple) website, Zite!
Hello y'all, just thought I'd share a cool little project I've been working on called Zite. It is a simple static website generator using bash and pandoc. The main reason I created was because of the frustration of trying to use tools like Hugo and Zola for creating my personal website. While I do think they're great, I've always felt like all I needed for the website I wanted was a few lines of noscripting, so that's what I did!
The github link is https://github.com/rodrigueslazaro/zite if anyone wants to check it out. I'm no bash, or programming, expert, so I'd be glad if anyone wants to contribute to the project! I know there are some improvement that can be done, but the functionality is pretty much how I want to.
​
https://preview.redd.it/et1rg77flhrb1.png?width=963&format=png&auto=webp&s=81a9b2bbb63a9c73b0a741f4413502483b5cae62
​
https://redd.it/16wmw1z
@r_bash
Hello y'all, just thought I'd share a cool little project I've been working on called Zite. It is a simple static website generator using bash and pandoc. The main reason I created was because of the frustration of trying to use tools like Hugo and Zola for creating my personal website. While I do think they're great, I've always felt like all I needed for the website I wanted was a few lines of noscripting, so that's what I did!
The github link is https://github.com/rodrigueslazaro/zite if anyone wants to check it out. I'm no bash, or programming, expert, so I'd be glad if anyone wants to contribute to the project! I know there are some improvement that can be done, but the functionality is pretty much how I want to.
​
https://preview.redd.it/et1rg77flhrb1.png?width=963&format=png&auto=webp&s=81a9b2bbb63a9c73b0a741f4413502483b5cae62
​
https://redd.it/16wmw1z
@r_bash
GitHub
GitHub - rodrigueslazaro/zite: Simple static website generator in a single bash noscript.
Simple static website generator in a single bash noscript. - GitHub - rodrigueslazaro/zite: Simple static website generator in a single bash noscript.
Bash menu to execute different functions
I have a small tool to help install stuff without running all the commands.
What I'm trying to do is now that I have all the functions, I am creating a menu so that each item can be selected, and then that particular function is executed, then the menu appears again.
Here is some code to get a feel
At the top of the noscript I have booleans to turn certain things on and off (it's more complex than this, but this is an example), it depends on the distro I'm using.
Then I've got the function that performs the action
And before the menu at the bottom, I have a statement checking if the bool for the item is true or false, and if it's true, add that item to the array which will show in the selection menu.
Now for the selection menu at the bottom of the bash noscript, I have
The issue with this is that the list of options can change, depending on what those booleans are. So with the array I'm creating that displays all the options, I can't just hardcode the function name that needs to be executed. Because on one of my machines, Option 1 may be something different than another.
So the question is, in the array, how do I store both the menu item name and the name of the function I need to call, so that in the case statement, I can reference the option name and the function name that matches it.
https://redd.it/16wp3s9
@r_bash
I have a small tool to help install stuff without running all the commands.
What I'm trying to do is now that I have all the functions, I am creating a menu so that each item can be selected, and then that particular function is executed, then the menu appears again.
Here is some code to get a feel
bInstall_program_A=false
bInstall_program_B=true
function run_program_A() {
# execute command
echo -e "Finished"
}
function run_program_B() {
# execute command
echo -e "Finished"
}
if [ "$bInstall_program_A" = true ] ; then
items+=('Program A')
fi
if [ "$bInstall_program_B" = true ] ; then
items+=('Program B')
fi
At the top of the noscript I have booleans to turn certain things on and off (it's more complex than this, but this is an example), it depends on the distro I'm using.
Then I've got the function that performs the action
And before the menu at the bottom, I have a statement checking if the bool for the item is true or false, and if it's true, add that item to the array which will show in the selection menu.
Now for the selection menu at the bottom of the bash noscript, I have
noscript="Selection Menu"
prompt="Select an option\n\n"
while item=$(zenity --list \
--width="430" \
--height="335" \
--noscript="$noscript" \
--text="$prompt" \
--column="Installable Packages" "${items[@]}")
do
case "$item" in
"${items[0]}") echo "Selected $items[0], item #1";;
"${items[1]}") echo "Selected $item, item #2";;
"${items[2]}") echo "Selected $item, item #3";;
*) echo "Invalid option.";;
esac
done
The issue with this is that the list of options can change, depending on what those booleans are. So with the array I'm creating that displays all the options, I can't just hardcode the function name that needs to be executed. Because on one of my machines, Option 1 may be something different than another.
So the question is, in the array, how do I store both the menu item name and the name of the function I need to call, so that in the case statement, I can reference the option name and the function name that matches it.
https://redd.it/16wp3s9
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
UI in Next Generation Shell
https://blog.ngs-lang.org/2023/09/30/ui-in-ngs/
https://redd.it/16wthsm
@r_bash
https://blog.ngs-lang.org/2023/09/30/ui-in-ngs/
https://redd.it/16wthsm
@r_bash
Next Generation Shell
UI in NGS
Before describing UI design in Next Generation Shell, let’s clarify which problems we are trying to solve. Problems Warming exercise: CLI is an interface that focuses on a single line, the Co…
How to delete data from 2 files and output the result
How do I tell it to remove IP in these 2 file wl.txt and bots.txt from the output file it only reads the first file also need to clean up a file find ips in ipban.txt and remove them from ipattack.txt also want to add if an IP ends with .0 to add /24 i.e: 10.10.10.0 make it 10.10.10.0/24 please add your code to the code below. Thanks
curl -sk $GLOBAL $GLOB $IDP $ATTACK $SRX |\\grep -P -o '((25[0-5\]|(2[0-4\]|1\\d|[1-9\]|)\\d)\\.?\\b){4}(/(3[0-2\]|[12\]?\\d))?\\b' |\\#awk 'NR > 0 {print $0}' > spamhaus_transformed.txtawk 'NR > 0 {print $1}' | sort -u | grep -F -v -f ipban/wl.txt | grep -F -v -f ipban/bots.txt > ipban/ipattack.txt
https://redd.it/16x15yh
@r_bash
How do I tell it to remove IP in these 2 file wl.txt and bots.txt from the output file it only reads the first file also need to clean up a file find ips in ipban.txt and remove them from ipattack.txt also want to add if an IP ends with .0 to add /24 i.e: 10.10.10.0 make it 10.10.10.0/24 please add your code to the code below. Thanks
curl -sk $GLOBAL $GLOB $IDP $ATTACK $SRX |\\grep -P -o '((25[0-5\]|(2[0-4\]|1\\d|[1-9\]|)\\d)\\.?\\b){4}(/(3[0-2\]|[12\]?\\d))?\\b' |\\#awk 'NR > 0 {print $0}' > spamhaus_transformed.txtawk 'NR > 0 {print $1}' | sort -u | grep -F -v -f ipban/wl.txt | grep -F -v -f ipban/bots.txt > ipban/ipattack.txt
https://redd.it/16x15yh
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
/sbin/brltty launching randomly
Hey guys,
I’m trying to start writing some noscripts for school in my ubuntu 18.04 VM and while executing it, suddenly while doing ./noscript1.sh i get the following error:
/sbin/brltty: failed to execute /sbin/brltty
I don’t use it nor did i know of its existence up until today. Any help?
https://redd.it/16x3www
@r_bash
Hey guys,
I’m trying to start writing some noscripts for school in my ubuntu 18.04 VM and while executing it, suddenly while doing ./noscript1.sh i get the following error:
/sbin/brltty: failed to execute /sbin/brltty
I don’t use it nor did i know of its existence up until today. Any help?
https://redd.it/16x3www
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Bash / sed on Mac adds ^M when appending to a line
I'm writing a bash noscript to append additional tab-delimited fields to (initially) the end of the first/header line of a text file on Mac. It works, but sed adds a \^M and then the added fields to the end of each line, which I can only see when I open the file with Vim. It also adds the \^M to the end of all the other lines, even though they don't match.
How do I tell sed NOT to add the \^M?
Here's my sed command:
sed '1s/$/\\tField1\\tField2$/' TESTDATA.txt
https://redd.it/16x8cez
@r_bash
I'm writing a bash noscript to append additional tab-delimited fields to (initially) the end of the first/header line of a text file on Mac. It works, but sed adds a \^M and then the added fields to the end of each line, which I can only see when I open the file with Vim. It also adds the \^M to the end of all the other lines, even though they don't match.
How do I tell sed NOT to add the \^M?
Here's my sed command:
sed '1s/$/\\tField1\\tField2$/' TESTDATA.txt
https://redd.it/16x8cez
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Some tricky regex and graphviz docs later, we have a decent noscript
A vimwiki graph generator using the dot language and graphviz, written in BASH.
Supports two layouts and more can be added.
Instead of a plain white elongated chart that all other such noscripts generate, this one uses the SFDP or NetworkMap layouts along with some custom coloring. Something along the lines of obsidian's graph.
link
Cheers.
https://redd.it/16xkrzf
@r_bash
A vimwiki graph generator using the dot language and graphviz, written in BASH.
Supports two layouts and more can be added.
Instead of a plain white elongated chart that all other such noscripts generate, this one uses the SFDP or NetworkMap layouts along with some custom coloring. Something along the lines of obsidian's graph.
link
Cheers.
https://redd.it/16xkrzf
@r_bash
GitHub
GitHub - wolandark/Vimwiki-Graphviz: A VimWiki Graph Generator
A VimWiki Graph Generator . Contribute to wolandark/Vimwiki-Graphviz development by creating an account on GitHub.