Name | Modified | Size | Downloads / Week |
---|---|---|---|
jwscripts_20240531.tar.xz | 2024-05-31 | 1.2 MB | |
jwscripts_20240513.tar.xz | 2024-05-13 | 1.2 MB | |
jwscripts_20240510.tar.xz | 2024-05-10 | 1.2 MB | |
jwscripts_20240424.tar.xz | 2024-04-24 | 22.6 kB | |
jwscripts_20240415.tar.xz | 2024-04-15 | 22.6 kB | |
jwscripts_20240414.tar.xz | 2024-04-15 | 23.7 kB | |
README.md | 2024-02-13 | 29.5 kB | |
jwscripts_20240208.tar.xz | 2024-02-08 | 23.7 kB | |
jwscripts_20240207.tar.xz | 2024-02-07 | 23.6 kB | |
jwscripts_20240130.tar.xz | 2024-01-31 | 23.4 kB | |
jwscripts_20240129.tar.xz | 2024-01-30 | 23.5 kB | |
jwscripts_20240125.tar.xz | 2024-01-25 | 23.4 kB | |
Totals: 12 Items | 3.8 MB | 1 |
jwscripts
jwscripts is a collection of bash scripts that I maintain primarily for personal use. The latest release available here. The changelog is here.
apod
This script downloads the NASA Astronomy Picture of the Day. It is based on a script by Josh Schreuder. The script downloads the webpage where the daily NASA picture is posted, scrapes it for the name of the picture, and stores the picture locally.
The script can optionally store the description locally and set the wallpaper using feh.
Usage: apod [options] [dir]
download current NASA pic of the day to dir (default ~/Pictures)
Options:
-d save image description
-h, --help display this help and exit
-n don't save picture
-w set wallpaper using feh
Examples:
apod save pic of the day to ~/Pictures
apod -w /tmp save pic of the day to /tmp and set wallpaper
bell
This script rings the terminal bell. Whether this actually produces a sound depends on your terminal, system, and volume settings.
btwn
This script returns a random number between two numbers. By default, the two numbers are 1 and 100.
Usage: btwn [number] [number]
Return a random number between two numbers
Examples:
btwn between 1 and 100
btwn 1 10 between 1 and 10
btwn 100 10 between 10 and 100
btwn 10 between 1 and 10
btwn -4 between -4 and 0
convert2pdf
This script converts multiple images into a single PDF document. The script expects a list of images as arguments. If a PDF file name is not specified, the script names the PDF by replacing the extension of the first image file with pdf.
Usage: convert2pdf [options] <image> <image>
Combine images into a PDF
Options:
-h, --help display this help and exit
-n dry run, no conversion performed
-f <filename> output PDF to filename
Examples:
convert2pdf -nf output.pdf *.jpg dry run on all jpg images in current dir
convert2pdf slideshow_001.jpg slideshow_002.png combine listed images; guess PDF filename
cutc
This script uses tput
to determine the width of the terminal, then cuts all input lines so that they fit in the terminal width.
ddiso
This script writes an ISO file to a USB drive using dd
. Using dd
directly can be dangerous because you can target an internal drive and frag your system. ddiso
uses udevadm
to look for a USB device to write to. If it finds multiple USB devices or no USB devices, it refuses to write.
Usage: ddiso [options] <ISO>
Identify USB drive and dd ISO to it
Options:
-d dry run, don't write
-h, --help display this help and exit
-f force; write even if file does not appear to be an ISO
Examples:
ddiso alpine_latest.iso write alpine_latest.iso to the identified USB drive
dify
This script uses tput
to determine the width of the terminal, then shows a side-by-side diff that is fitted to that terminal width.
$ dify --help
Usage: dify <file> <file>
diff side-by-side and match terminal width
$ dify lorem*
Lorem ipsum dolor sit amet | Lorem ipsum dolor sit amet I took some Latin, so I think I could translate this
consectetur adipiscing elit | consectetur adipiscing elit it wouldn't be a very good translation
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua sed do eiusmod tempor incididunt ut labore et dolore magna aliqua
Ut enim ad minim veniam Ut enim ad minim veniam
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugi Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugi
Excepteur sint occaecat cupidatat non proident Excepteur sint occaecat cupidatat non proident
sunt in culpa qui officia deserunt mollit anim id est laborum <
eauto
This script executes a command, then watches the file to see if it changes. If a change is detected, eauto
executes the command again.
Usage: eauto <executable file>
Execute file whenever it changes
Options:
-h, --help display this help and exit
-n do not execute
-q be quiet
extract
This script uses file extensions to determine what tool(s) to use to extract the files. It can use 7zip, bunipz2, gunzipz, tar, unxz, and unzip. Multiple files may be given as arguments, even if they require the use of different tools.
Usage: extract [options] <file>
Extract file
Options:
-h, --help display this help and exit
-q be quiet
-v be verbose
File types:
7zip .7z, .7zip
bz2 .bz2
gz .gz
tar .tar, .tar.bz2, .tar.gz, tar.xz, .tgz, .txz
xz .xz
zip .zip
Examples:
extract test.tar use tar to extract
extract -v text.gz use gunzip to extract, be verbose
extract -q files.zip use unzip to extract, be quiet
extract files.zip morefiles.tgz use unzip and tar to extract
fehslideshow
This script uses feh to show a slideshow of all images in a directory. By default, it loads images in ~/Pictures
.
Usage: fehslideshow [dir]
Show slideshow of images in a directory (default ~/Pictures)
Options:
-h, --help display this help and exit
-r random order
Examples:
fehslideshow -r show in random order
fehslideshow Downloads use ./Downloads
headl
This script uses tput
to determine the number of lines in the terminal, then displays that number of lines of input using head. The goal is to automatically display as many lines as possible without scrolling.
hr
This script creates a horizontal rule using the characters given as argument number 1. By default, it uses #
.
Usage: hr [options] [word]
Output a horizontal rule
Options:
-h, --help display this help and exit
-e, wait for enter to be pressed to exit
Examples:
hr -e wait for enter
hr "hello " make rule with text "hello"
i3resize
Designed for use with i3-wm
The script uses i3-msg
to send window resize messages to the main i3 process. It is intended to be mapped to keys in an i3 configuration file.
i3 config file excerpt:
bindsym $mod+Shift+y exec --no-startup-id /usr/local/bin/i3resize left
bindsym $mod+Shift+u exec --no-startup-id /usr/local/bin/i3resize down
bindsym $mod+Shift+i exec --no-startup-id /usr/local/bin/i3resize up
bindsym $mod+Shift+o exec --no-startup-id /usr/local/bin/i3resize right
idleslideshow
This script uses feh to show a slideshow of all images in a directory. It only activates the slideshow after the keyboard and mouse have been idle for a number of seconds (default 10).
Usage: idleslideshow [options] [dir]
slideshow images in dir (default ~/Pictures)
Options:
-h, --help display this help and exit
-q be quiet
-t <time> time to wait in seconds (default 10)
-v be verbose
Examples:
idleslideshow show images in ~/Pictures after 10 seconds
idleslideshow -t 5 ./Downloads show images in ./Downloads after 5 seconds
ifup
This script checks if a remote host is up, then connects if it is. By default, it connects using ssh and checks port 22 using netcat. It can also connect using telnet, checking port 23 using netcat. An alternate port can be provided.
Usage: ifup [options] <remote host>
Connect to a remote host if it is up
Options:
-b bell when connecting
-h, --help display this help and exit
-p <port> use alternate port
-r ssh as root user
-t use telnet instead of ssh
-v be verbose
-w wait 10 seconds before connecting
Examples:
ifup -brw 192.168.0.1 use bell and wait, ssh root@192.168.0.1
ifup -tp 10023 192.168.0.1 telnet to 192.168.0.1 on port 10023
keepalive
This script loops continuously, sleeping for a random time between two numbers. By default, the low limit for the random time is 10 seconds and the high limit for the random time is 60 seconds.
Usage: keepalive [options] [number] [number]
Loop to show terminal activty
Defaults:
low limit 10 seconds
high limit 60 seconds
Options:
-d show date
-h, --help display this help and exit
-q be quieter
-v be verbose (output a dot every second)
Examples:
keepalive -q 10 300 quieter output, between 10 and 300 seconds
keepalive -d 60 600 date output, between 60 and 600 seconds
keepalive 1 10 between 1 and 10 seconds
keepalive -dv date, dot, and number of seconds
keepalive -dqv date and dot, no number of seconds
l
This script makes an educated guess about the type of file. If a directory is given as an argument, l
will list files in the dir as per ls
. If a file is given as an argument, l
will show the file using less
.
$ l
Documents Downloads Pictures
$ l Documents
final_project.txt really_final.txt really_final_02.txt
something_else.txt zzz.log
$ l Documents/final_project.txt
______________________________________________________________________________
| Blah blah blah final project I'm really gonna turn this in
|
| Have you ever just written crap until you come up with somehting worth
| keeping? that's how some people overcome writer's block. Not me, though,
| I keep writing crap and turn it in :)
|
_|____________________________________________________________________________
launcher
This script opens a terminal window with an alternate .bashrc. This is useful if the normal .bashrc includes starting a terminal multiplexer or other extra features that are not needed when you just want a new terminal to run mupdf Downloads/new_file.pdf & exit
.
lcase
This script converts any uppercase characters to their lowercase equivalent. It will operate on standard input or on a file.
$ echo "Hello, how are YOU today?" | lcase
hello, how are you today?
lesc
This script uses tput
to determine the width of the terminal, cuts all input lines so that they fit in the terminal width, and pipes to less.
Usage: lesc <file>
or: cat <file> | lesc
Cut input lines to match terminal width and pipe to less
linkimages
This script creates an HTML file for each image file provided as an argument. Each HTML page links to the next page, with the last page linking to the first page.
Usage: linkimages <image> ...
Create an HTML page for each image. Each page links to the next page.
Options:
-h, --help display this help and exit
-n dry run; don't create files
-v be verbose
Examples:
linkimages -n *.jpg dry run on all jpg files
linkimages -v * all files in dir, be verbose
link_jwscripts
This script creates links in /usr/local/bin to the install location /usr/local/share/jwscripts/bin. It is run during installation and typically doesn't need to be run again.
lookup
This script looks up an IP address in /etc/hosts and using DNS. The -l option uses /etc/hosts only. The -r option searches /etc/hosts for a hostname using an IP address.
locker
Designed for use with i3-wm
This script selects a random image from a given directory and calls i3lock with that image.
Usage: locker [dir]
call i3lock with a random image in dir (default ~/Pictures)
Options:
-h, --help display this help and exit
-n dry run; don't lock
-v be verbose
mdauto
This script compiles a markdown file using mkd2html
and opens the resulting HTML file in a viewer (Firefox, by default).
Whenever the markdown file changes, the script recompiles and attempts to refresh the viewer.
Usage: mdauto [options] <file>
Compile file using mkd2html
Options:
-h, --help display this help and exit
-n don't display resulting HTML file
-q be quiet
-v <viewer> use viewer (default firefox)
Examples:
mdauto test.md compile test.md and display resulting HTML file
mdauto -v evince test.md compile test.md and display with evince
mdauto -n test.md compile test.md but do not display result
mdedit
This script runs the user's preferred editor on the markdown file, using the $EDITOR variable. When the editor exits, the script compiles the markdown file using mkd2html
and opens the resulting HTML file in a viewer (Firefox, by default).
Usage: mdedit [options] <file>
edit file, then compile using mkd2html
Options:
-e <editor> use viewer (default $EDITOR)
-h, --help display this help and exit
-n don't display resulting HTML file
-q be quiet
-v <viewer> use viewer (default firefox)
Examples:
mdedit test.md edit test.md, compile, and display resulting HTML file
mdedit -e emacs test.md edit with emacs
mdedit -e micro -v xreader test.md edit with micro, view with xreader
mdedit -n test.md edit, compile, but do not display result
montyhall
This script plays the Monty Hall door game.
netcheck
This script uses mtr to periodically check connectivity. It is intended to help diagnose intermittent WiFi issues by provding insight into failure modes.
Usage: netcheck [options] [remote host]
Use mtr to test connection to a remote host
Options:
-h, --help display this help and exit
-v be verbose
-p [pings] pings per cycle (default 20)
-t [time] time in seconds to wait between cycles (default 60)
Examples:
netcheck test to 8.8.8.8
netcheck -t 100 192.168.0.1 test to 192.168.0.1, 100 pings per cycle
pause
This script simply pauses for a short time. By default, it sleeps for 10 seconds and then exits. It can be set to pause for a different time or for a random time.
Usage: pause [options] [num]
Pause for [num] seconds (default 10)
-h, --help display this help and exit
-q be quiet
-r choose a random number of seconds up to [num]
Examples:
pause 10 pause 10 seconds
pause -r 5 pause for 5 to 15 seconds
pause -qr 60 pause for 5 to 60 seconds, quietly
pause -r 10 20 pause for 10 to 20 seconds
pb
This script uses curl to post text to an online pastebin service. It uses https://paste.rs by default. The script will read from a file or from standard input. It can also get and delete posts using the ID of a post.
Usage: pb <file>
or: cat <file> | pb
or: pb -g <ID>
or: pb -d <ID>
or: pb -dg <ID>
Paste to
Options:
-d delete post with ID
-g get post with ID
-h, --help display this help and exit
-u <URL> URL of pastebin (default https://paste.rs)
Examples:
pb file.txt post contents of file.txt to https://paste.rs
uname -a | pb post output of uname -a to https://paste.rs
pb -g AAAAA get post with ID AAAAA from https://paste.rs
pb -dg AAAAA get and delete post with ID AAAAA from https://paste.rs
pingmtu
This script uses ping to check the MTU to a specific remote host. It accomplishes the task by setting the "do not fragment" option and increasing the packet size until responses are no longer received.
Usage: pingmtu [options] <remote host>
check MTU to a host
-s [size] MTU size to start with
Examples:
pingmtu 192.168.0.1 check MTU to 192.168.0.1
pingmtu -s 1000 10.0.100.1 check MTU to 10.0.100.1 starting with 1000
portalassistant
This script connects to a website (http://neverssl.com by default) and scrapes the page to determine if the connection has been redirected to a captive portal page. If redirection has occurred, the script opens a web browser (Firefox by default) so that the user can do whatever is required to get unfettered access.
Usage: portalassistant [options] [remote host]
Check if the internet connection is behind a captive portal
Options:
-b [browser] use browser (default firefox)
-c [content] scrape site for content (default not missing much)
-f force open browser (don't scrape)
-h, --help display this help and exit
-q be quiet
-s [site] use site (default http://neverssl.com/online)
-v be verbose
Examples:
portalassistant check for unfiltered connection to http://neverssl.com/online
portalassistant -b chromium use chromium instead of firefox
portalassistant -vf be verbose and force open firefox
pping
This script "pings" a TCP port. This is to allow a user to check if a remote host is up in an environment that does not allow normal ICMP pings.
Usage: pping [options] <remote host>
Check if remote host is listening on port 22
-h, --help display this help and exit
-l loop
-p [port] check port (default 22)
Examples:
pping -p 10000 192.168.0.1 check port 10000
pping -lp 23 192.168.0.1 check port 23 on a loop
prq
This script checks if commands are available on the system. It has similar functionality to the standard Unix which
command, with the addition of a more useful error message in the case that a command is not available.
Script that calls prq
:
#!/bin/bash
/usr/local/bin/prq mysql vim || exit 1
Script output on a system that has vim but not mysql installed:
mysql not found
prq
can also be used on the command line, though error messages are not as helpful when used interactively.
Usage: prq [options] <program> [program]
check for program availability
-h, --help display this help and exit
-p display path to program
-q be quiet
-v be verbose
Examples:
prq wget sed check for wget and sed
prq -p vim emacs display path for vim and emacs
prq -q firefox check for firefox quietly
roku
This script attempts to locate a Roku device on the local network. If one is found, the script acts as a HTTP remote.
Usage: roku
Remotely control a Roku device
-h, --help display this help and exit
roll
This script rolls dice. There are two different methods available: sum of rolled dice and number of successes in rolled dice.
- Sums: roll some number dice of some size. Currently, all dice rolled must be the same size.
- If one argument is given, the script returns the sum of all dice. Example: 2d6, roll 2 six-sided dice.
- If two arguments are given, the script returns the two sums and whichever has the higher total. Example: 2d6 2d8, roll 2 six-sided dice versus 2 eight-sided dice.
- Successes: roll some number of six-sided dice, where successes are dice which roll greater than or equal to the "success" value. Black dice must roll greater than or equal to 4 to be a success. Gray dice must roll greater than or equal to 3 to be a success. White dice must roll greater than or equal to 2 to be a success.
- If one argument is given, the script returns the number of successes. Examples: 3b, roll 3 black dice. 3g, roll 3 gray dice. 2w, roll 2 white dice.
- If two arguments are given, the script returns the two numbers of successes and whichever has the higher total. Example: 4b 3g, roll 4 black dice versus 3 gray dice.
Usage: roll [options] <dice>
or: roll [options] <dice> <dice>
Roll dice and return result
Options:
-h, --help display this help and exit
-q be quiet
-v be verbose
Dice:
sum of N dice with S sides
2d6 2 6-sided dice, min 2, max 12
1d12 1 12-sided die, min 1, max 12
number of successful rolls
5b 5 6-sided black dice, 4 or better is success
5g 5 6-sided gray dice, 3 or better is success
5w 5 6-sided white dice, 2 or better is success
Examples:
roll 2d6
roll d6 1 6-sided die
roll -l 5d20 sum 5 20-sided dice, loop
roll 1d1000 1 1000-sided die
roll d4 d12 4-sided die vs 12-sided die
roll 3b 3 black dice (number of successes)
roll 4b 3g 3 black dice vs 3 gray dice
run*
Most of these scripts loop over the following actions:
- Display "Press Enter to Activate" and wait for the user to press enter
- Run a command
The scripts are most useful if run within a terminal multiplexer such as GNU Screen. This allows the window to be ready for use but not actually running the command.
since
This script stores the exact time it was run in a temporary file. Then, the next time it is run, it outputs how much time has passed since the last time it was run. Alternatively, the script can output how much time has passed since a given date and time.
If no temporary file is found and no date is given, the script outputs the time since the beginning of the Unix epoch.
Usage: since [options]
Show time since last run or since a given date
-h, --help display this help and exit
-s display time in seconds
Examples:
since time since last run (or the beginning of the UNIX epoch)
since "January 1, 2001" time since the start of the millennium
since -s "January 1, 2001" number of seconds since the start of the millennium
since 1700000000 time since UNIX second 1700000000
sums
This script calculates checksums for files. By default, it calculates with sha256sum and saves the results to sha256.txt.
Usage: sums [options] [file]
display and save checksums for files
-c [prog] use prog to calculate checksums (default /bin/sha256sum)
-f [file] save to file (default sha256.txt)
-n don't save to file
-h, --help display this help and exit
Examples:
sums save checksum of all files in current dir to sha256.txt
sums image.iso save checksum of image.iso to sha256.txt
sums -c md5sum -f sums.txt save checksum (calculated with md5sum) to sums.txt
sums -nc md5sum calculate checksum with md5sum, do not save to file
sysinfo
This script gathers system information. It uses the following commands:
hostname
shows the system hostname.uname -or
shows the operating system and kernel release.lscpu
shows some CPU info.free -h
shows information about RAM.df -h
shows information about internal storage drives.lsb_release
shows information about the distribution.date
shows the date that the information was gathered.- Distro specific package information is gathered by
pacman
on Arch Linux.apt-mark
on Debian, Ubuntu, or Mint.- Other distributions are not currently supported.
taill
This script uses tput
to determine the number of lines in the terminal, then displays that number of lines of input using tail. The goal is to automatically display as many lines as possible without scrolling.
template
This is a script that serves as a template for building scripts. For that purpose, it handles arguments as an example.
Usage: template [options] [argument]
Show how script options and arguments are handled
Options:
-b ring bell
-h, --help display this help and exit
-o <option> option
-q be quiet
-v be verbose
-w wait 10 seconds
Examples:
template -bvw use bell and wait, be verbose
texauto
This script compiles a tex file using pdflatex
and opens the resulting PDF file in a viewer (mupdf, by default).
Whenever the tex file changes, the script recompiles and attempts to refresh the viewer.
Usage: texauto [options] <file>
Compile file using pdflatex
-h, --help display this help and exit
-n don't display resulting pdf
-q be quiet
-v <viewer> use viewer (default mupdf)
Examples:
texauto test.tex compile test.tex and display resulting test.pdf
texauto -v xreader test.tex compile test.tex and display result with xreader
texauto -n file.tex compile file.tex but do not display result
texedit
This script runs the user's preferred editor on the tex file, using the $EDITOR variable. When the editor exits, the script compiles the tex file using pdflatex
and opens the resulting PDF file in a viewer (mupdf, by default).
Usage: texedit [options] <file>
Edit file, then compile using pdflatex
Options:
-e <editor> use editor (default nvim)
-h, --help display this help and exit
-n don't display resulting pdf
-q be quiet
-v <viewer> use viewer (default mupdf)
Examples:
texedit test.tex edit test.tex, compile, and display resulting test.pdf
texedit -e emacs test.tex edit with emacs
texedit -e micro -v xreader test.tex edit with micro, view with xreader
texedit -n file.tex edit, compile, but do not display result
tildone
This script runs a command until it exits successfully. For example, if you run umount /dev/sda1
and get an error because a process is still writing to the USB drive, you could run tildone umount /dev/sda1
to rerun the command until the process is done writing and the device can be umounted.
Usage: tildone [option] <command>
Run a command until it exits successfully
-h, --help display this help and exit
-n [num] try [num] times (default 99)
-w [num] wait [num] seconds between attempts (default 1)
-v be verbose
Examples:
tildone umount /dev/sda1 run command 99 times, 1 second between tries
tildone -n 5 -w 10 umount /dev/sda1 run command 5 times, 10 seconds between tries
tilup
This script checks connectivity to a remote host until it gets a good response, then it exits. By default, it uses neverssl.com as the remote host and port 80.
Usage: tilup [options] <remote host>
Check a remote host until it is up
-b bell when connecting
-h, --help display this help and exit
-p [port] check TCP port (default 80)
-v be verbose
-w wait 10 seconds between ping and exit
Examples:
tilup check neverssl.com, port 80
tilup 192.168.0.1 check 192.168.0.1, port 80
tilup -p 22 192.168.0.1 check 192.168.0.1, port 22
tilup -p 0 192.168.0.1 check 192.168.0.1, ping
ucase
This script converts any lowercase characters to their uppercase equivalent. It will operate on standard input or on a file.
$ echo "Hello, how are YOU today?" | ucase
HELLO, HOW ARE YOU TODAY?
usblist
Derived from the ddiso
script, this script lists all connected USB drives it can detect.
whenup
This script checks a remote host until it gets a good response, then it connects. By default, it connects using ssh and checks port 22 using netcat. It can also connect using telnet, checking port 23 using netcat. An alternate port can be provided.
Usage: whenup [options] <remote host>
Connect to a remote host when it is up
Options:
-b bell when connecting
-d wait for host to be down first
-h, --help display this help and exit
-o only try 3 times
-p <port> use alternate port
-r ssh as root user
-t use telnet instead of ssh
-v be verbose
-w wait 10 seconds before connecting
Examples:
whenup -d 192.168.0.1 wait for host to be down, then up, then connect
whenup -brw 192.168.0.1 use bell and wait, ssh root@192.168.0.1
whenup -tp 10023 192.168.0.1 telnet to 192.168.0.1 on port 10023