From ddf779a49926a690588eef909d8a87e94d86e563 Mon Sep 17 00:00:00 2001 From: Brandon Rozek Date: Mon, 7 Sep 2020 21:47:59 -0400 Subject: [PATCH] New Posts --- content/blog/bashpartialargparse.md | 58 +++++++++++++++++++++++++++++ content/blog/splittingfiles.md | 37 ++++++++++++++++++ content/blog/xvfb.md | 22 +++++++++++ 3 files changed, 117 insertions(+) create mode 100644 content/blog/bashpartialargparse.md create mode 100644 content/blog/splittingfiles.md create mode 100644 content/blog/xvfb.md diff --git a/content/blog/bashpartialargparse.md b/content/blog/bashpartialargparse.md new file mode 100644 index 0000000..79cfc9c --- /dev/null +++ b/content/blog/bashpartialargparse.md @@ -0,0 +1,58 @@ +--- +title: "Partial Argument Parse and Passing in Bash" +date: 2020-09-07T21:33:26-04:00 +draft: false +tags: [] +--- + +Let's say we want to augment an existing terminal command (like for example `wget`). We then want to be able to add or edit command line options. The rest of this post provides an example that hopefully you can use in your bash script. + +```bash +#!/bin/bash + +# Custom help function +show_help() { + echo "Usage: custom_command [arguments]" + echo " --name " + echo " --flag_example" + echo " " + exit 0 +} + +# Defaults for our custom flags or parameters. +name="" +flag_example=0 + +# Loop through and take out our custom parameters +# from the parameter list. +i=0 +numargs=$# +while test $i -lt "$numargs" +do + case "$1" in + "--help") + show_help + ;; + "--name") + shift + name=$1 + ;; + "--flag_example") + flag_example=1 + ;; + *) + set -- "$@" "$1" + ;; + esac + shift + i=$((i+1)) +done + +# Do something here using our custom parameters + +# Pass our non-custom parameters to the application +wget "$@" +``` + + + diff --git a/content/blog/splittingfiles.md b/content/blog/splittingfiles.md new file mode 100644 index 0000000..013bbcf --- /dev/null +++ b/content/blog/splittingfiles.md @@ -0,0 +1,37 @@ +--- +title: "Splitting Files to Circumvent Size Limits" +date: 2020-09-07T20:41:25-04:00 +draft: false +tags: [] +--- + +Let's say you want to transfer file(s) over to someone and there is a limit the size you can transfer over. Maybe because of the physical medium or the online service you're using. You can make use of the terminal tool `split` in order to get the chunks over there and then use `cat ` to combine it back to one file. + +## Create a Single File + +Skip to the next section if you only want to transfer a single file. + +Otherwise, let's say you have a folder of files named `Documents`. First, let's create a gzipped compressed archive that contains everything. + +```bash +tar -czf documents.tar.gz Documents +``` + +## Splitting the File + +Next let's split the file into 1 GB parts. + +```bash +split -b 1GB -d documents.tar.gz PART +``` + +Then transfer the files labeled PARTX where X is the part number over.... + +## Re-combining + +Once the files are transfered, we use `cat` to bring the files back together. + +```bash +cat PART* > documents.tar.gz +``` + diff --git a/content/blog/xvfb.md b/content/blog/xvfb.md new file mode 100644 index 0000000..ab3157d --- /dev/null +++ b/content/blog/xvfb.md @@ -0,0 +1,22 @@ +--- +title: "Xvfb" +date: 2020-09-07T20:49:54-04:00 +draft: false +tags: [] +--- + +X Virtual Framebuffer (Xvfb) is a great quick application to run applications that expect a `X11` server, but you don't care to see the visual output. + +To install: + +```bash +sudo apt install xvfb +``` + +To run: + +```bash +xvfb-run application +``` + +For more customization, I hear that it's better to use [xpra with Xdummy](https://xpra.org/trac/wiki/Xdummy). I haven't tried this myself yet, but if you experience issues with the application expecting `randr` or `glx` extensions, give it a shot. \ No newline at end of file