

pathway mtu discovery bash script
I wrote pmtud.sh this weekend to get the MTU of a link (or tunnel) quickly, reliably, and without sending a ton of pings. It can do so in about 11 pings per target.
I had fun writing the entire thing in sh
, tried making it "POSIX-compliant," but probably failed somewhere since POSIX isn't worded well. The script only needs dig
and ping
and uses shell built-ins for everything else. It performs a recursive binary search on the MTU search domain and asynchronously queues pings for later.
read user input problem
why I can't pass my input in foo function
undefined
foo() { read -r -p "delete $name (default is no) [y/n]? " choice choice="${choice:-n}" echo "\$choice: $choice" } printf "%s\n" "foo" "bar" "baz" "eggs" "spam" | while read -r name; do foo
Expected result:
undefined
delete foo (default is no) [y/n]? USER_INPUT $choice: USER_INPUT delete bar (default is no) [y/n]? USER_INPUT $choice: USER_INPUT # truncated
Actual output:
undefined
$choice: bar $choice: eggs $choice: n
[!NOTE] Actual output produced without user interaction
Tutorial about using the bind builtin
This article describes bind and shows the ways you can use it to make binding to write faster and more comfortably use bash.
255 return code from command substitution of wait builtin but why?
In the code below we wait
for a background process three times. In the first paragraph we get the expected 0 return code from the wait. In the second paragraph the only change is wrapping the wait in a command substitution which instead gives a 255 return code. In the third paragraph the only change is wrapping the wait in a subshell which gives a 127 return code. Why is this?
bash
sleep 1 & wait $! echo $? # prints "0" sleep 1 & a=$(wait $!) # <---- only difference is cmd substitution echo $? # prints "255" sleep 1 & (wait $! &>/dev/null) # <---- only difference is subshell echo $? # prints "127"
Thanks in advance for your thoughts!
EDIT: updated to include the subshell final example also, which gives a clue
How does this code work?
I'm studying bash, and I came across this Stackoverflow thread which contains this bit of code:
undefined
var="abcde" echo ${var%d*}
The output is abc
, but I can't figure out why. I understand that %d
is used to indicate an integer number and *
represents anything, but I can't figure out why those together would truncate var
to only 3 characters.
Mystified by stdin, stdout and stderr? Learn to use them in your Linux scripts.
A question regarding this script I wrote not working
I made grebuntu to merge all of the separate scripts into one script for all distros, but it doesn't work. The individual scripts do, I tested in VMs. What could have caused the issue? the script in question is tsubuntu.sh btw, can be found in the repo The original scripts are available at https://github.com/Tsu-gu/tsubuntu
Pipe wget output into bzip2 for decompression
Hi all,
I'm trying to put a command together to download a bz2 archive containing an img file and decompress it immediately, basically without saving it to the filesystem. Can this be done?
This is what I've come up with so far, but it's incomplete: wget -qO- "https://opnsense.com/.../img.bz2" | bzip2 -dv
Background: Trying to install OPNsense on Linode. Their hacky official guide says the best way to install FreeBSD is via the rescue mode. But FreeBSD posts their images as .img, so the filesystem size limitation of 1GB for the rescue image isn't an issue. But with OPNsense I need to decompress it.
I have a few different options on how to install this but I see it as a good reason to learn more about stdin/out, piping commands, etc.
Thanks in advance.
Exiftool bash script to process image in a specific time range recursively.
After a long process of roaming the web, re-runs and troubleshoot the script with this wonderful community, the script is functional and does what it's intended to do. The script itself is probably even further improvable in terms of efficiency/logic, but I lack the necessary skills/knowledge to do so, feel free to copy, edit or even propose a more efficient way of doing the same thing.
I'm greatly thankful to @AernaLingus@hexbear.net, @GenderNeutralBro@lemmy.sdf.org, @hydroptic@sopuli.xyz and Phil Harvey (exiftool) for their help, time and all the great idea's (and spoon-feeding me with simple and comprehensive examples ! )
Prerequisites:
parallel
package installed on your distribution Copy/past the below script in a file and make it executable. Change the start_range/end_range
to your needs and install the parallel
package depending
Is it possible to debug a bash script using a debugger in attached mode? For debugging scripts on the host machine and scripts inside a docker container?
I was able to setup a debugger using a launch mode using Visual Studio Code with the Bash Debug extension. Is it possible to setup the debugger in VSCode to be able to debug a bash script using a attach debug mode?
For debugging scripts on the host machine and scripts inside a docker container?
fuzzysh: minimalist selector in shell, inspired by fzf
minimalist selector in shell, inspired by fzf. Contribute to yazgoo/fuzzysh development by creating an account on GitHub.
A choice selector in pure bash (and compatible with zsh), inspired by fzf which I'm working on
Bash script to download and search youtube subtitles and output clickable timestamped urls
cross-posted from: https://lemm.ee/post/23155648
Here is the script.
undefined#!/usr/bin/env bash # Download and search youtube subs # deps yt-dlp ,awk, perl, any one or more of either ugrep, ripgrep, grep # usage "script youtube_url" main() { url="$@" check_if_url get_video_id search_for_downloaded_matching_files set_download_boolean_flag download_subs read_and_format_transcript_file echo_description_file user_search } # Iterate over the array and add items to the new array if they match the regex check_if_url() { local regex='^https://[^[:space:]]+$' if ! [[ $url =~ $regex ]]; then echo "Invalid input. Valid input is a url matching regex ${regex}" exit 1 fi } get_video_id() { video_id=$(echo "$url" | sed -n 's/.*v=\([^&]*\).*/\1/p') } search_for_downloaded_matching_files() { # Find newest created files matching the
Fast youtube download bash script using custom build of aria2
I made a script that downloads from youtube super fast using a custom aria2 build.
Aria2 https://github.com/P3TERX/Aria2-Pro-Core/releases
ffmpeg build https://github.com/yt-dlp/FFmpeg-Builds/releases
I choose ffmpeg-master-latest-linux64-gpl.tar.xz
undefined
#!/usr/bin/env bash #set -x if [[ -z $@ ]]; then echo "specify download url" exit fi dir_dl="$PWD" url="$@" ffmpeg_dir="$HOME/.local/bin.notpath/" download_archive_dir="$HOME/Videos/yt-dlp/" download_archive_filename=".yt-dlp-archived-done.txt" mkdir -p "$download_archive_dir" youtube_match_regex='^.*(youtube[.]com|youtu[.]be|youtube-nocookie[.]com).*$' if [[ "$1" =~ $youtube_match_regex ]]; then url="$(echo "$@" | perl -pe 's/((?:http:|https:)*?\/\/(?:www\.|)(?:youtube\.com|m\.youtube\.com|youtu\.|#youtube-nocookie\.com).*(?:c(?:hannel)?\/|u(?:ser)?\/|v=|v%3D|v\/|(?:a|p)\/(?:a|u)\/\d.*\/|watch\?|vi(?:=|\/)|\/#embed\/|oembed\?|be\/|e\/)([^&?%#\/\n]+)).*/$1/gm')" yt-dlp \ --check-formats \ --clean-
Need help downloading spotify playlists efficiently using SpotDL
[SOLVED] Solution: https://lemmy.ml/comment/4317564
I am doing all of this using ChatGPT, I know enough bash to understand the script partially, but not enough to write the script myself.
I recently posted bash script(click) to download songs on spotify
using Spotdl
Updated Post
This is all good, but I am not trying to download whole playlists and I want to make sure to
URL
to the Archieve_file
so it doesn't download it again. i.e., compare and if present, exit loop, if not present in file, download and add link to the file. This was easier when I was dealing with only song
links and not playlist
links. But now, playlists complicates the equation, but if I can achieve this, I can basically add this script to `c
Created a bash script to download Spotify songs and keep track of your download i.e., not download them again and again
I would rather prefer that you would buy spotify premium
if you can. But, till you can, there's always spotdl
which can allow you to download your songs
Installation of spotdl (github page click here): https://i.imgur.com/5g6uUgD.png
https://paste.debian.net/plain/1293528 a very simple script, you don't actually need the script, but it makes it easier to download songs.
btw, I am using file manager nemo here, if you want something else, change it to your default file manager, if you don't want to open folder, well remove last but one line.
execute this command first and when nano text edit appears, paste the debian pastebin in there. ::: spoiler spoiler
:::
I created a bash script to download videos from Youtube using yt-dlp
This will remove all sponsors, download subtitles and view it when you are watching a video. Modify and Share this all over if you like!
Edit: Give credits to this community or Lemmy in general if you are posting this or a modified form (please do share) of this elsewhere. Some popularity would do Lemmy good.
Few requirements:
yt-dlp
in Videos folder or else change the location in the script below. yt-dlp
not youtube-dl
on your system.
You can do this by sudo apt install yt-dlp
or use your distro's package installer. name
in your home folder (or whichever folder you are you most comfortable with and give it execution permissions by chmod +x name
Debian Pastebin Thanks to folds at debian for making a tor network friendly pastebin. I have noticed that sometimes scripts get corrupted here, so best copy this from pastebi
Script to export a SVG to PNG with a certain width. IDK why the exported picture has not this size.
The issue is that if my script is correctly done, a SVG is supposed to be exported to PNG with a fixed width, the script seems to work fine, but when I check it out again on Inkscape*, it shows me the original SVG size, not the resized PNG exported picture.
Here's a folder with the script and a random SVG I'm using for testing.
*To check the size of the picture in Inkscape, we need to change the units in the top bar, and then see the numbers that shows. The screenshot shows a 14,79 cm x 9,85 cm, instead of 10,5 cm x 6,9 cm.
How to remove previous lines on bash?
I want to have a selector in a "case" menu, so I show the options:
undefined
1) option A 2) option B 3) option C
Then read the choice (let's say it's B), remove the previous menu and show this instead:
undefined
1) option A » 2) option B 3) option C
How can I do this? I know we can remove the current line with echo -ne "\r"
, but I have no idea of how to do it with several