Authentication Bearer Token
Is it possible to obtain the auth bearer token of a login session through noscript? I want to POST something on my website via curl POST but can't as it required bearer token to be passed. Can I use my creds to GET token in command line or through bash noscript?
https://redd.it/x05q6v
@r_bash
Is it possible to obtain the auth bearer token of a login session through noscript? I want to POST something on my website via curl POST but can't as it required bearer token to be passed. Can I use my creds to GET token in command line or through bash noscript?
https://redd.it/x05q6v
@r_bash
reddit
Authentication Bearer Token
Is it possible to obtain the auth bearer token of a login session through noscript? I want to POST something on my website via curl POST but can't...
Brash Cli Trash Manager in Pure Bash
Why Brash
Well, why not. As you see its similar to Trash\_cli. Unlike Trash_cli, Brash don't Depends on any Python libs just pure bash.
So why not ?
https://redd.it/x0m7y4
@r_bash
Why Brash
Well, why not. As you see its similar to Trash\_cli. Unlike Trash_cli, Brash don't Depends on any Python libs just pure bash.
So why not ?
https://redd.it/x0m7y4
@r_bash
GitHub
GitHub - andreafrancia/trash-cli: Command line interface to the freedesktop.org trashcan.
Command line interface to the freedesktop.org trashcan. - andreafrancia/trash-cli
is there a way to get a command history list view like this in bash ?
​
https://preview.redd.it/m9duxw3cnuk91.png?width=1205&format=png&auto=webp&s=d5708c47a840039b0d59215f65ec4cae9436bab6
https://redd.it/x1ime0
@r_bash
​
https://preview.redd.it/m9duxw3cnuk91.png?width=1205&format=png&auto=webp&s=d5708c47a840039b0d59215f65ec4cae9436bab6
https://redd.it/x1ime0
@r_bash
Is there a Bash equivalent to Zsh Named Directories feature?
Hi, I read that Zsh has the Named Directories feature, where you can create an 'alias' to a path.
The neat part is that you can use this alias as part of a command.
So, instead of using something like:
cp .bashrc /very/long/path/name
I could use:
cp .bashrc vlpn
Does Bash has something like that?
https://redd.it/x1nik6
@r_bash
Hi, I read that Zsh has the Named Directories feature, where you can create an 'alias' to a path.
The neat part is that you can use this alias as part of a command.
So, instead of using something like:
cp .bashrc /very/long/path/name
I could use:
cp .bashrc vlpn
Does Bash has something like that?
https://redd.it/x1nik6
@r_bash
reddit
Is there a Bash equivalent to Zsh Named Directories feature?
Hi, I read that Zsh has the Named Directories feature, where you can create an 'alias' to a path. The neat part is that you can use this alias as...
Is it possible to stop a bash a bash noscript during execution and then return back to where you left off the next time you run the noscript
Hopefully the noscript makes sense, for context let's say this is the situation:
- I'm running a bash noscript that runs random commands one by one and in order to proceed to each next command the user has to press the spacebar. there are about 80 items
- Let's say the user presses CTRL+C to stop the noscript from executing halfway through those 80 items
Is there a way to return back to where they were in noscript execution when they cancelled the noscript? Or do they have to re-run the noscript and then start at the very beginning again?
https://redd.it/x225ew
@r_bash
Hopefully the noscript makes sense, for context let's say this is the situation:
- I'm running a bash noscript that runs random commands one by one and in order to proceed to each next command the user has to press the spacebar. there are about 80 items
- Let's say the user presses CTRL+C to stop the noscript from executing halfway through those 80 items
Is there a way to return back to where they were in noscript execution when they cancelled the noscript? Or do they have to re-run the noscript and then start at the very beginning again?
https://redd.it/x225ew
@r_bash
reddit
Is it possible to stop a bash a bash noscript during execution and...
Hopefully the noscript makes sense, for context let's say this is the situation: - I'm running a bash noscript that runs random commands one by one...
Re-directing outputs from a noscript that uses FFmpeg to recursively transcode video files
Hi all. I have very little experience so far with bash noscripting, so please forgive my rudimentary question... but I've been given a noscript that uses FFmpeg to recursively transcode mkv video files to mp4 derivatives:
#!/bin/bash
VIDEOS=/Users/ExampleUser/Desktop/1
cd /Users/ExampleUser/Desktop/1
find "$VIDEOS" -name '*.mkv' -exec sh -c 'ffmpeg -analyzeduration 15M -guess_layout_max 0 -i "$0" -y -pix_fmt yuv420p -codec:v libx264 -fps_mode cfr -r 29.97 -filter:v "yadif,scale=640:480" -aspect 4:3 -preset medium -g 60 -sc_threshold 0 -profile:v main -b:v 1000k -minrate 900k -maxrate 1200k -bufsize 2000k -tune film -pass 1 -an -f mp4 /dev/null ; ffmpeg -i "$0" -y -pass 2 -pix_fmt yuv420p -codec:v libx264 -fps_mode cfr -r 29.97 -filter:v "yadif,scale=640:480" -preset medium -g 60 -sc_threshold 0 -profile:v main -b:v 1000k -minrate 900k -maxrate 1200k -bufsize 2000k -tune film -map 0:0 -map 0:1 -codec:a aac_at -ac 2 -ar 48000 -b:a 128k -filter:a "aresample=async=1:min_hard_comp=0.100000:first_pts=0" -f mp4 -movflags faststart "${0%%.mkv}_sl.mp4"' {} \;
rm *.log.mbtree *.log
exit;
Right now, it outputs the derivative mp4s into the same directory as the source mkv files (specified by the variable VIDEOS). How can I change the output destination for the mp4 files? Ideally, I'd like to re-direct the mp4 outputs to a different disk attached to our workstation. Many thanks for any suggestions!
https://redd.it/x2knt0
@r_bash
Hi all. I have very little experience so far with bash noscripting, so please forgive my rudimentary question... but I've been given a noscript that uses FFmpeg to recursively transcode mkv video files to mp4 derivatives:
#!/bin/bash
VIDEOS=/Users/ExampleUser/Desktop/1
cd /Users/ExampleUser/Desktop/1
find "$VIDEOS" -name '*.mkv' -exec sh -c 'ffmpeg -analyzeduration 15M -guess_layout_max 0 -i "$0" -y -pix_fmt yuv420p -codec:v libx264 -fps_mode cfr -r 29.97 -filter:v "yadif,scale=640:480" -aspect 4:3 -preset medium -g 60 -sc_threshold 0 -profile:v main -b:v 1000k -minrate 900k -maxrate 1200k -bufsize 2000k -tune film -pass 1 -an -f mp4 /dev/null ; ffmpeg -i "$0" -y -pass 2 -pix_fmt yuv420p -codec:v libx264 -fps_mode cfr -r 29.97 -filter:v "yadif,scale=640:480" -preset medium -g 60 -sc_threshold 0 -profile:v main -b:v 1000k -minrate 900k -maxrate 1200k -bufsize 2000k -tune film -map 0:0 -map 0:1 -codec:a aac_at -ac 2 -ar 48000 -b:a 128k -filter:a "aresample=async=1:min_hard_comp=0.100000:first_pts=0" -f mp4 -movflags faststart "${0%%.mkv}_sl.mp4"' {} \;
rm *.log.mbtree *.log
exit;
Right now, it outputs the derivative mp4s into the same directory as the source mkv files (specified by the variable VIDEOS). How can I change the output destination for the mp4 files? Ideally, I'd like to re-direct the mp4 outputs to a different disk attached to our workstation. Many thanks for any suggestions!
https://redd.it/x2knt0
@r_bash
reddit
Re-directing outputs from a noscript that uses FFmpeg to recursively...
Hi all. I have very little experience so far with bash noscripting, so please forgive my rudimentary question... but I've been given a noscript that...
How can I write this if condition more efficiently?
if $a -eq 0 && $b -eq 0 && $c -eq 0 ; then
I want to do something like:
if $a && $b && $c -eq 0
i just don't know how to format it correctly
https://redd.it/x37adx
@r_bash
if $a -eq 0 && $b -eq 0 && $c -eq 0 ; then
I want to do something like:
if $a && $b && $c -eq 0
i just don't know how to format it correctly
https://redd.it/x37adx
@r_bash
reddit
How can I write this if condition more efficiently?
if [ $a -eq 0 ] && [ $b -eq 0 ] && [ $c -eq 0 ]; then I want to do something like: if $a && $b && $c -eq 0 i just don't know how to format...
Any tip on optimizing this?
Hi!
I have a
Since it runs so frequently I want it to be as performant as possible.
This is what I came so far:
#!/bin/sh
player="playerctl -p 'spotify'"
metadata="$player metadata"
playerstatus=$(eval $player status 2> /dev/null)
([ "$playerstatus" = "Playing" ] || "$player_status" = "Paused" ) && \
printf "$(eval $metadata artist) - $(eval $metadata noscript)"
It works, but I figured this is a nice opportunity to learn something new about shell-noscripts.
Does anybody have any tip or idea on how to improve this for runtime footprint?
Thanks in advance :D
EDIT: result thanks to @rustyflavor and @oh5nxo:
player=$(playerctl -p 'spotify' metadata -f "{{ artist }} - {{ noscript }}")
"$player" != "No players found" && printf "$player"
https://redd.it/x3ez5w
@r_bash
Hi!
I have a
waybar module to track Spotify that runs every two seconds.Since it runs so frequently I want it to be as performant as possible.
This is what I came so far:
#!/bin/sh
player="playerctl -p 'spotify'"
metadata="$player metadata"
playerstatus=$(eval $player status 2> /dev/null)
([ "$playerstatus" = "Playing" ] || "$player_status" = "Paused" ) && \
printf "$(eval $metadata artist) - $(eval $metadata noscript)"
It works, but I figured this is a nice opportunity to learn something new about shell-noscripts.
Does anybody have any tip or idea on how to improve this for runtime footprint?
Thanks in advance :D
EDIT: result thanks to @rustyflavor and @oh5nxo:
player=$(playerctl -p 'spotify' metadata -f "{{ artist }} - {{ noscript }}")
"$player" != "No players found" && printf "$player"
https://redd.it/x3ez5w
@r_bash
reddit
Any tip on optimizing this?
Hi! I have a `waybar` module to track **Spotify** that runs every two seconds. Since it runs so frequently I want it to be as performant as...
Are parentheses wrapped around the primary case statement variable required?
Parentheses:
case "$1" in
esac
Without parentheses:
case $1 in
esac
Would I have to worry about whitespace, and or weird ass symbols in the $1 variable? Or does the case statement simply not care? If parentheses are not required in any stretch of the imagination, then I will write all my dash noscript case statements without parentheses.
https://redd.it/x3vnes
@r_bash
Parentheses:
case "$1" in
esac
Without parentheses:
case $1 in
esac
Would I have to worry about whitespace, and or weird ass symbols in the $1 variable? Or does the case statement simply not care? If parentheses are not required in any stretch of the imagination, then I will write all my dash noscript case statements without parentheses.
https://redd.it/x3vnes
@r_bash
reddit
Are parentheses wrapped around the primary case statement variable...
Parentheses: case "$1" in esac Without parentheses: case $1 in esac Would I have to worry about whitespace, and or weird ass...
How can I replace this grep command? I'm getting the Argument list too long error.
Hello, I'm very new to bash so this can probably be easily solved.
I'm writing a bash noscript that stores a list of files in a variable, and then I need to grep those files from a much larger list that contains the files from the first list. Don't know if that makes sense. Here's how I did it:
finalList=$(cat <(echo "$completeList") | grep "$partialList")
It works fine most of the time, however, in some cases the "$partialList" has a lot of files, and the "grep: Argument list too long" error pops up. Any workaround I can use? I read I could use the find command but I'm not really sure how to apply it here.
Thanks in advance!
https://redd.it/x42cnc
@r_bash
Hello, I'm very new to bash so this can probably be easily solved.
I'm writing a bash noscript that stores a list of files in a variable, and then I need to grep those files from a much larger list that contains the files from the first list. Don't know if that makes sense. Here's how I did it:
finalList=$(cat <(echo "$completeList") | grep "$partialList")
It works fine most of the time, however, in some cases the "$partialList" has a lot of files, and the "grep: Argument list too long" error pops up. Any workaround I can use? I read I could use the find command but I'm not really sure how to apply it here.
Thanks in advance!
https://redd.it/x42cnc
@r_bash
reddit
How can I replace this grep command? I'm getting the Argument list...
Hello, I'm very new to bash so this can probably be easily solved. I'm writing a bash noscript that stores a list of files in a variable, and then...
I've been trying to make a noscript to simplify my very common find command usage, but it's not working in three ways
First, I can't figure out how to use
Second, the
Third, it can't actually find the directory I pass to it. So if I do
Here is the noscript:
#!/bin/bash
# File Find
FILENAME="$1"
shift
SEARCHDIR="$PWD"
EXCLUDEDDIRS=
-z "$FILENAME" && echo "No filename pattern supplied."
while "$#" -gt 0 ; do
echo "$#"
case "$1" in
-x | --exclude ) EXCLUDEDDIRS="${EXCLUDEDDIRS} ! -path '${2}'"; shift 2 ;;
-s | --search-dir ) SEARCHDIR="$2"; shift 2 ;;
* ) shift ;;
esac
done
case "$SEARCHDIR" in
"WebModules") EXCLUDEDDIRS="${EXCLUDEDDIRS} ! -path '${PWD}/obj/'" ;;
) ;;
esac
COMMAND="find ${SEARCHDIR} ${EXCLUDEDDIRS} -name ${FILENAME} -print"
echo "$COMMAND"
"$COMMAND"
https://redd.it/x45d70
@r_bash
First, I can't figure out how to use
. in a variable. I want to use . so that output from find is like ./dir1/dir2/file, instead of /home/user/project/date/dir1/dir2/file. In line 7 below at the point SEARCH_DIR="$PWD" is what I need help with for using . please, as I've resorted to $PWD.Second, the
find command when executed from my bash noscript is not doing wildcard expansion on the *. I echo the command I'm running and copy and paste it into bash and it works as intended, but when run from my noscript file it says No such file or directory.Third, it can't actually find the directory I pass to it. So if I do
ff *test* -s /, it says No such file or directory.Here is the noscript:
#!/bin/bash
# File Find
FILENAME="$1"
shift
SEARCHDIR="$PWD"
EXCLUDEDDIRS=
-z "$FILENAME" && echo "No filename pattern supplied."
while "$#" -gt 0 ; do
echo "$#"
case "$1" in
-x | --exclude ) EXCLUDEDDIRS="${EXCLUDEDDIRS} ! -path '${2}'"; shift 2 ;;
-s | --search-dir ) SEARCHDIR="$2"; shift 2 ;;
* ) shift ;;
esac
done
case "$SEARCHDIR" in
"WebModules") EXCLUDEDDIRS="${EXCLUDEDDIRS} ! -path '${PWD}/obj/'" ;;
) ;;
esac
COMMAND="find ${SEARCHDIR} ${EXCLUDEDDIRS} -name ${FILENAME} -print"
echo "$COMMAND"
"$COMMAND"
https://redd.it/x45d70
@r_bash
reddit
I've been trying to make a noscript to simplify my very common find...
First, I can't figure out how to use `.` in a variable. I want to use `.` so that output from find is like `./dir1/dir2/file`, instead of...
can someone what did I overlook
what is the purpose of the noscript: unlocking the dataset using the curl command
the code that works:
now this one works flawlessly, but the moment i try to replace the "
my next try is to create the part as a string that i can echo out for debugging so i create:
and run it like this:
but what i get for this is:
​
but when I echo the created env variable i get the correct string that if i copy and run in terminal it does what is supposed to do
​
now what did I miss
​
​
edit:
the curl command is now fixed and it looks like this:
​
https://redd.it/x5v910
@r_bash
what is the purpose of the noscript: unlocking the dataset using the curl command
the code that works:
curl "`https://$host/api/v2.0/pool/dataset/unlock`" -k -X POST -H "accept: */*" -H "Content-Type: application/json" -H "Authorization: Bearer 1-$API_TOKEN" -d '{"id": "the_dataset_hardcoded","unlock_options": {"key_file": false,"recursive": false,"toggle_attachments": true,"datasets": [{"name" : "the_dataset_hardcoded" , "passphrase" : "the_password_hardcoded"}]}}'now this one works flawlessly, but the moment i try to replace the "
the_dataset_hardcoded" and/or the "the_password_hardcoded" as an environmental variable the noscript stops workingmy next try is to create the part as a string that i can echo out for debugging so i create:
curl_builder3="'{\"id\": \"$pool\",\"unlock_options\": {\"key_file\": false,\"recursive\": false,\"toggle_attachments\": true,\"datasets\": [{\"name\" : \"$pool\" , \"passphrase\" : \"$pass\"}]}}'"and run it like this:
curl "`https://$host/api/v2.0/pool/dataset/unlock`" -k -X POST -H "accept: */*" -H "Content-Type: application/json" -H "Authorization: Bearer 1-$API_TOKEN" -d $curl_builder3but what i get for this is:
curl: (3) unmatched brace in URL position 1:{"key_file":^bash: line 3: Server: command not found​
but when I echo the created env variable i get the correct string that if i copy and run in terminal it does what is supposed to do
​
now what did I miss
​
​
edit:
the curl command is now fixed and it looks like this:
curl "`https://$host/api/v2.0/pool/dataset/unlock`" -k -X POST -H "accept: */*" -H "Content-Type: application/json" -H "Authorization: Bearer 1-$API_TOKEN" -d "{\"id\": \"$pool\",\"unlock_options\": {\"key_file\": false,\"recursive\": false,\"toggle_attachments\": true,\"datasets\": [{\"name\" : \"$pool\" , \"passphrase\" : \"$pass\"}]}}"​
https://redd.it/x5v910
@r_bash
reddit
can someone what did I overlook
what is the purpose of the noscript: unlocking the dataset using the curl command the code that works: `curl...
I am once again asking for your noscripting support
How are you doing
I learned a lot about noscripting in my last post here, and I want to see if there is some other hidden improvement that can be done on a little noscript I created, and hopefully learn something new on the way.
I use
wpctl set-volume @DEFAULTAUDIOSINK@ 1%+
but as a downside, this command allows to increase volume well over
I figured I could check the volume with this command
sicro@sicro ~ $ wpctl get-volume @DEFAULTAUDIOSINK@
Volume: 1.00
so if I were to pipe the output to
wpctl set-volume @DEFAULTAUDIOSINK@ $(wpctl get-volume @DEFAULTAUDIOSINK@ | awk '{ print ($2 >= 1) ? "100%" : "1%+"}')
Now, this needs two calls to
Does anybody can come up with a better version that can reduce the processes spawned?
Thank you for your time :D
https://redd.it/x7ab4y
@r_bash
How are you doing
bash ninjas?I learned a lot about noscripting in my last post here, and I want to see if there is some other hidden improvement that can be done on a little noscript I created, and hopefully learn something new on the way.
I use
wireplumber to control volume, the command I use to increase volume iswpctl set-volume @DEFAULTAUDIOSINK@ 1%+
but as a downside, this command allows to increase volume well over
100%, which I don't like.I figured I could check the volume with this command
sicro@sicro ~ $ wpctl get-volume @DEFAULTAUDIOSINK@
Volume: 1.00
so if I were to pipe the output to
awk I could: remove the Volume: part, compare the numbers, and pass the corresponding argument to the original command like thiswpctl set-volume @DEFAULTAUDIOSINK@ $(wpctl get-volume @DEFAULTAUDIOSINK@ | awk '{ print ($2 >= 1) ? "100%" : "1%+"}')
Now, this needs two calls to
wpctl and awk to do the math.Does anybody can come up with a better version that can reduce the processes spawned?
Thank you for your time :D
https://redd.it/x7ab4y
@r_bash
reddit
I am once again asking for your noscripting support
How are you doing `bash` ninjas? I learned a lot about noscripting in my last post here, and I want to see if there is some other hidden...
How do you create empty collection if $col.json is empty?
ls -1 *.json | sed 's/.json$//' | while read col;
do
mongoimport --host $host --port $port -d $db --collection $col --file $col.json
echo $cmd
done
I have this bash noscript, but the issue is that it doesn't create an empty collection if the file is empty. How do you remedy this situation?
https://redd.it/x7ig30
@r_bash
ls -1 *.json | sed 's/.json$//' | while read col;
do
mongoimport --host $host --port $port -d $db --collection $col --file $col.json
echo $cmd
done
I have this bash noscript, but the issue is that it doesn't create an empty collection if the file is empty. How do you remedy this situation?
https://redd.it/x7ig30
@r_bash
reddit
How do you create empty collection if $col.json is empty?
ls -1 *.json | sed 's/.json$//' | while read col; do mongoimport --host $host --port $port -d $db --collection $col --file $col.json ...
Using expect to give inputs to bash noscript
Suppose I have a noscript which takes two inputs
`
\#!/bin/bash
echo "enter username: "
read $UNAME
echo "enter port: "
read $PORT
echo $UNAME
echo $PORT
`
I want to use a expect noscript to give input directly for PORT, but allow user to enter username manually and then print both username and port.
https://redd.it/x91ujm
@r_bash
Suppose I have a noscript which takes two inputs
`
\#!/bin/bash
echo "enter username: "
read $UNAME
echo "enter port: "
read $PORT
echo $UNAME
echo $PORT
`
I want to use a expect noscript to give input directly for PORT, but allow user to enter username manually and then print both username and port.
https://redd.it/x91ujm
@r_bash
reddit
Using expect to give inputs to bash noscript
Suppose I have a noscript which takes two inputs \` \#!/bin/bash echo "enter username: " read $UNAME echo "enter port: " read $PORT echo...
Trigger another noscript when a bin file executed?
Without modifying the executable.. is it possible to add a hook or some type of event on my system (bashrc?) that allows me to trigger a side-effect/another shell noscript when a bin executable has finished being executed
https://redd.it/xatgw3
@r_bash
Without modifying the executable.. is it possible to add a hook or some type of event on my system (bashrc?) that allows me to trigger a side-effect/another shell noscript when a bin executable has finished being executed
https://redd.it/xatgw3
@r_bash
reddit
Trigger another noscript when a bin file executed?
Without modifying the executable.. is it possible to add a hook or some type of event on my system (bashrc?) that allows me to trigger a...
I Just Want To Show Off Some Scripts I've Been Using
So a couple years ago I finally sat down and decided to get better at bash noscripting. I had a number of things I wanted to automate and was often needing "oddball" utilities no one else had done/I could find.
# CSV2CUE
Probably the most niche of problems. I had exported a very long audio project from a DAW that had embedded CUE points. It was 4 entire CDs in one project. I could split the entire thing out by CUE points. The problem is that the DAW I edited everything on did not follow proper Redbook timecode format of
Now it's not a full cue sheet; but all my editor wanted was TRACK and INDEX fields.
# VPS Backup
I back all my critical VPS stuff up with a bash noscript:
I used to do a full MYSQL dump as well; but I ditched wordrpess for (semi)static site generation.
# Jekyll Lazy-Compose
Speaking of static site generators; I'm using Jekyll. The way I got it configured I became stupid reliant on front-matter for making everything work. So I decided to hack together a noscript so I can write posts from bash without having to do anything but write, save, and commit to my git so githooks render it.
This one was fun because I had no idea how to make it blindly accept multiple words as arguments. The only issue is if you don't escape characters that require it. This is probably my second most used noscript.
# Asterisk MusicOnHold
Did you know you can do musiconhold from a streaming source with Asterisk? It can call an application and suck input in from stdin. This is fine till you want to use OGG sources since ogg123 doesn't resample and mplayer doesn't support stdout. Good thing noscripts count as executables.
I have made ogg123 work with a direct pipe to sox; but holy cow the CPU usage.
# Hacky Auto-Update Page
I've been following this stuff with a particular provider's /16 block relentlessly attacking SIP
So a couple years ago I finally sat down and decided to get better at bash noscripting. I had a number of things I wanted to automate and was often needing "oddball" utilities no one else had done/I could find.
# CSV2CUE
Probably the most niche of problems. I had exported a very long audio project from a DAW that had embedded CUE points. It was 4 entire CDs in one project. I could split the entire thing out by CUE points. The problem is that the DAW I edited everything on did not follow proper Redbook timecode format of
MM:SS:FF (minutes:seconds:frames) and instead used HH:MM:SS:FF. This made the editor I use for splitting completely crash. So I had to make the DAW output a CSV file of CUE points...then process them in to something my other editor liked.#!/bin/bash
tail -n +2 Markers.csv | tac | awk '{print $3}' | sed -e "s/:/ /g" >> cue.tmp
t=1
cat cue.tmp | while read line;
do
p=($(echo $line))
if [ ${p[0]} -gt 0 ]; then
p[1]=$(echo "(${p[0]} * 60) + ${p[1]}" | bc)
fi
cue=($(echo "${p[1]}:${p[2]}:${p[3]}"))
printf "\nTRACK %02d AUDIO\n" $t >> output.cue
printf "INDEX 01 %s\n" $cue >> output.cue
t=$((t + 1))
done
rm cue.tmp
Now it's not a full cue sheet; but all my editor wanted was TRACK and INDEX fields.
# VPS Backup
I back all my critical VPS stuff up with a bash noscript:
#!/bin/bash
rsync -a /etc/nginx/ /var/www/backups/etc-nginx
rsync -a /etc/asterisk/ /var/www/backups/etc-asterisk
rsync -a /home/dewdude/.znc/ /var/www/backups/znc-conf
rsync -a /home/dewdude/qspbot/ /var/www/backups/qspbot
rsync -a /home/git/ /var/www/backups/home-git-gogs
rsync -arvz -e 'ssh -p [SECRETPORT]' /var/www [HOME PC]:/media/remote/vpsbackup
I used to do a full MYSQL dump as well; but I ditched wordrpess for (semi)static site generation.
# Jekyll Lazy-Compose
Speaking of static site generators; I'm using Jekyll. The way I got it configured I became stupid reliant on front-matter for making everything work. So I decided to hack together a noscript so I can write posts from bash without having to do anything but write, save, and commit to my git so githooks render it.
#!/bin/bash
# usage: ./compose.sh [category] [noscript]
# example: /compose.sh blog MY AWESOME POST TITLE NO YOU DON'T NEED TO ENCLOSE IT!
# run in the root of your site files/repository
# assumes categories are directories in root
# Variables and category argument
category=$1
pd=$(date +'%Y-%m-%d')
pt=$(date +'%T')
file=blog$$.md
# Ditch the category argument
shift 1
# Read everything else as noscript.
noscript=$@
t=${noscript,,}
t=${t// /-}
fd=$(date +'%Y/%^b/%d')
# Let's write the front matter to our temp file.
printf -- "---\nnoscript: $noscript\nlayout: post\ndate: $pd $pt\npermalink: /$category/$fd-$t.php\nexcerpt_separator: <!--more-->\n---\n\n" >> $file
# Write the post in whatever editor you want.
nano + $file
# Move the file to category/_posts replacing spaces with hyphen
mv $file $category/_posts/$pd-${t// /-}.md
# Display some output to verify it's done.
printf "\nPost $noscript created in $category: $category/_posts/$pd-$t.md\n\n"
This one was fun because I had no idea how to make it blindly accept multiple words as arguments. The only issue is if you don't escape characters that require it. This is probably my second most used noscript.
# Asterisk MusicOnHold
Did you know you can do musiconhold from a streaming source with Asterisk? It can call an application and suck input in from stdin. This is fine till you want to use OGG sources since ogg123 doesn't resample and mplayer doesn't support stdout. Good thing noscripts count as executables.
#!/bin/bash
PIPE="/tmp/asterisk-pipe.$$"
mknod $PIPE p
mplayer -playlist http://host:port/playlist.m3u -really-quiet -quiet -ao pcm:file=$PIPE -af resample=8000,pan=1:0.5:0.5,channels=1,format=mulaw 2>/dev/null | cat $PIPE 2>/dev/null
rm $PIPE
I have made ogg123 work with a direct pipe to sox; but holy cow the CPU usage.
# Hacky Auto-Update Page
I've been following this stuff with a particular provider's /16 block relentlessly attacking SIP
accounts. They seem to be doing nothing and the numbers have increased. We're almost to 5% of the /16 being blacklisted.
Anyway...this noscript just plops my iptables output between some pre-rendered HTML/PHP code; along with stuff to count the IPs and keep a list of prior counts.
I have filtered the full IP range and clues just to avoid breaking rules.
Since the blacklist only updates every 4 hours; the noscript only has to run every 4 hours. It does so 5 minutes after the blacklist updates.
That's all for now.
https://redd.it/xaxkn1
@r_bash
Anyway...this noscript just plops my iptables output between some pre-rendered HTML/PHP code; along with stuff to count the IPs and keep a list of prior counts.
I have filtered the full IP range and clues just to avoid breaking rules.
#!/bin/bash
date=$(date)
count=$(iptables -S | grep '###\.##\.[0-9]\{1,3\}\.[0-9]\{1,3\}' | wc -l)
count=$(($count - 1))
cp /root/head /root/tmp.tmp
printf "Last updated: $date - Last Count: $count\n<br><pre><code>\n" >> /root/tmp.tmp
iptables -S | grep '###\.##\.[0-9]\{1,3\}\.[0-9]\{1,3\}' >> /root/vypr.tmp
printf "$date : $count\n" >> /root/count
printf "<br>\n" >> /root/tmp.tmp
cat /root/count >> /root/tmp.tmp
printf "</code></pre><br>\n" >> /root/tmp.tmp
cat /root/vfoot >> /root/tmp.tmp
rm [path-to-www-root]/tmp.php
# the file is stored in a different directory because Jekyll wipes root every build
rm [path-to-www-stuff]/tmp.php
mv /root/tmp.tmp /var/www/tmp.php
chmod 777 /var/www/tmp.php
ln -s /var/www/tmp.php /var/www/pickmy/pbx/tmp.php
Since the blacklist only updates every 4 hours; the noscript only has to run every 4 hours. It does so 5 minutes after the blacklist updates.
That's all for now.
https://redd.it/xaxkn1
@r_bash
reddit
I Just Want To Show Off Some Scripts I've Been Using
So a couple years ago I finally sat down and decided to get better at bash noscripting. I had a number of things I wanted to automate and was often...
Syntax highlighting for command line tool options
Hello!
As in the noscript; I don't know where to ask, so I'm sorry if this is not the place to do so, but what syntax highlighting should I use for command line tool options? Basically to highlight the output of
Thank you kindly for the help!
https://redd.it/xb3f23
@r_bash
Hello!
As in the noscript; I don't know where to ask, so I'm sorry if this is not the place to do so, but what syntax highlighting should I use for command line tool options? Basically to highlight the output of
tool --help, or similar.Thank you kindly for the help!
https://redd.it/xb3f23
@r_bash
reddit
Syntax highlighting for command line tool options
Hello! As in the noscript; I don't know where to ask, so I'm sorry if this is not the place to do so, but what syntax highlighting should I use for...
Having issues with if-elif processing
I'm a little befuddled with a noscript I've been writing - and would appreciate some help!
This is one of those cases where each command seems to work fine on their own, but not so when put together into a noscript.
Here's a gist of what I'm trying to do:
​
input=$1
singlefunc () {
command "$input"
}
multifunc () {
xargs < $input -n 1 singlefunc
}
if [[ "$input" == name1* || name2* ]];
then
singlefunc
elif [ -f "$input" ];
then
multifunc
else
echo "exiting"
exit
fi
​
The idea here is - if the noscript is invoked with ./noscript.sh input, if will run if the input starts with name1 or name2, using single\func. If the input provided doesn't start with name1 or name2, and is a file containing a list of items, elif will run (reason for -f) using multi_fuc, which is just single_func running with xarg on the provided file.
The 'single_func' component runs on the command line fine on its own (command "input"), and the 'multi_func' component runs fine with a test file (xargs < testfile.txt -n 1 ./single_func.sh). But when I put them together as above and try to run them together, only the first 'if' part works correctly. When provided with a file or some nonsense line not containing name1 or name2, the noscript simply exits without returning anything.
For the curious, I'm running entrez direct commands within the single_func block.
What am I doing wrong?
https://redd.it/xb51hr
@r_bash
I'm a little befuddled with a noscript I've been writing - and would appreciate some help!
This is one of those cases where each command seems to work fine on their own, but not so when put together into a noscript.
Here's a gist of what I'm trying to do:
​
input=$1
singlefunc () {
command "$input"
}
multifunc () {
xargs < $input -n 1 singlefunc
}
if [[ "$input" == name1* || name2* ]];
then
singlefunc
elif [ -f "$input" ];
then
multifunc
else
echo "exiting"
exit
fi
​
The idea here is - if the noscript is invoked with ./noscript.sh input, if will run if the input starts with name1 or name2, using single\func. If the input provided doesn't start with name1 or name2, and is a file containing a list of items, elif will run (reason for -f) using multi_fuc, which is just single_func running with xarg on the provided file.
The 'single_func' component runs on the command line fine on its own (command "input"), and the 'multi_func' component runs fine with a test file (xargs < testfile.txt -n 1 ./single_func.sh). But when I put them together as above and try to run them together, only the first 'if' part works correctly. When provided with a file or some nonsense line not containing name1 or name2, the noscript simply exits without returning anything.
For the curious, I'm running entrez direct commands within the single_func block.
What am I doing wrong?
https://redd.it/xb51hr
@r_bash
reddit
Having issues with if-elif processing
I'm a little befuddled with a noscript I've been writing - and would appreciate some help! This is one of those cases where each command seems to...
Should videos be allowed in r/bash?
Hi,
My recent post was removed by a mod because it was a video, however, I believe videos do provide value. It wasn't removed in r/zsh and people seemed to like it.
Looking at the history of the sub, I see many videos, one less than a month ago, but presumably these escaped the watch of this particular mod.
In fact, this post specifically requested YouYube channels: [youtube channels](https://www.reddit.com/r/bash/comments/szg3hr/youtube_channels/).
Here's a quick list of past videos in this sub:
* [BASH programming video: user input, looping and text splitting with IFS/read](https://www.reddit.com/r/bash/comments/wq284v/bash_programming_video_user_input_looping_and/)
* [Writing bash noscript and not yet using shellcheck. I have just published a 5 minute intro video](https://www.reddit.com/r/bash/comments/r1s1up/writing_bash_noscript_and_not_yet_using_shellcheck/)
* [I made a video about how I applies all my bash, linux and terminal knowledge to finish a very important task in a real life situation under 30 min.](https://www.reddit.com/r/bash/comments/ldmyp8/i_made_a_video_about_how_i_applies_all_my_bash/)
* [In this video, you will learn how to pass arguments shell file and how to receive them inside the file. Also, will learn about asking user to certain input like username and password.](https://www.reddit.com/r/bash/comments/k42lva/in_this_video_you_will_learn_how_to_pass/)
* [In this video, you will learn how to write more complex bash commands using concepts like redirecting, pipelines, chaining and also how to write nested commands.](https://www.reddit.com/r/bash/comments/jxo56u/in_this_video_you_will_learn_how_to_write_more/)
* [Nice introduction video on regular expressions for anyone curious into learning more about regex. Thought some might appreciate it here:)](https://www.reddit.com/r/bash/comments/cjwu1c/nice_introduction_video_on_regular_expressions/)
* [Using one terminal command to create my own way to search from google sheet.](https://www.reddit.com/r/bash/comments/lh57ju/using_one_terminal_command_to_create_my_own_way/)
* [A simple bash program to Search and Play youtube videos with Terminal](https://www.reddit.com/r/bash/comments/lpb2y2/a_simple_bash_program_to_search_and_play_youtube/)
* [Bash noscript to do some common clipboard related operations quickly.](https://www.reddit.com/r/bash/comments/mb2pfw/bash_noscript_to_do_some_common_clipboard_related/)
These are just some of the ones posted straight up as a video, there's many more which are included in some text post.
What do you guys think? Do videos have a place in r/bash?
https://redd.it/xb6dji
@r_bash
Hi,
My recent post was removed by a mod because it was a video, however, I believe videos do provide value. It wasn't removed in r/zsh and people seemed to like it.
Looking at the history of the sub, I see many videos, one less than a month ago, but presumably these escaped the watch of this particular mod.
In fact, this post specifically requested YouYube channels: [youtube channels](https://www.reddit.com/r/bash/comments/szg3hr/youtube_channels/).
Here's a quick list of past videos in this sub:
* [BASH programming video: user input, looping and text splitting with IFS/read](https://www.reddit.com/r/bash/comments/wq284v/bash_programming_video_user_input_looping_and/)
* [Writing bash noscript and not yet using shellcheck. I have just published a 5 minute intro video](https://www.reddit.com/r/bash/comments/r1s1up/writing_bash_noscript_and_not_yet_using_shellcheck/)
* [I made a video about how I applies all my bash, linux and terminal knowledge to finish a very important task in a real life situation under 30 min.](https://www.reddit.com/r/bash/comments/ldmyp8/i_made_a_video_about_how_i_applies_all_my_bash/)
* [In this video, you will learn how to pass arguments shell file and how to receive them inside the file. Also, will learn about asking user to certain input like username and password.](https://www.reddit.com/r/bash/comments/k42lva/in_this_video_you_will_learn_how_to_pass/)
* [In this video, you will learn how to write more complex bash commands using concepts like redirecting, pipelines, chaining and also how to write nested commands.](https://www.reddit.com/r/bash/comments/jxo56u/in_this_video_you_will_learn_how_to_write_more/)
* [Nice introduction video on regular expressions for anyone curious into learning more about regex. Thought some might appreciate it here:)](https://www.reddit.com/r/bash/comments/cjwu1c/nice_introduction_video_on_regular_expressions/)
* [Using one terminal command to create my own way to search from google sheet.](https://www.reddit.com/r/bash/comments/lh57ju/using_one_terminal_command_to_create_my_own_way/)
* [A simple bash program to Search and Play youtube videos with Terminal](https://www.reddit.com/r/bash/comments/lpb2y2/a_simple_bash_program_to_search_and_play_youtube/)
* [Bash noscript to do some common clipboard related operations quickly.](https://www.reddit.com/r/bash/comments/mb2pfw/bash_noscript_to_do_some_common_clipboard_related/)
These are just some of the ones posted straight up as a video, there's many more which are included in some text post.
What do you guys think? Do videos have a place in r/bash?
https://redd.it/xb6dji
@r_bash
reddit
youtube channels
Hi All, me again learning bash noscripting, anyone have a favorite youtube channel I can sink my teeth into Thanks