I use a lot of Bash scripts in Linux. These are a few examples.
checksize.sh
checksize.sh a script that checks whether an image file is certain width & height, then takes action (in this case, removes the file). Can be used together with find. Remove is commented out, because you may want to use the script for something else. The script uses identify
, part of ImageMagick.
Bash command to be run from any folder that contains subfolders with images that need to be batch processed:
find . -type f -exec bash -c ~/checksize.sh ;
checksize.sh itself:
#!/bin/bash echo ${@} if [ -z "$1" ] then echo "\$1 empty" >&2 exit fi size=($(identify -format "%w %h" "$1" | tr -d "()")) if [ ${size[0]} -eq ${size[1]} ] then # rm -v "$1" fi
sshlogin.sh
This script logs into a SSH server and creates a reverse SSH port, so this port can in turn be used to log in to the original computer that ran the script. Using sshpass
might be insecure, in that case enable public key login in the server and the line that starts with sshpass can start where ssh -l is written.
#!/bin/bash # Loop forever: while [ 1 ] ; do sshpass -p PlainTextPassword ssh -l username_in_server -p port_number -R19222:localhost:22222 server.host.name.com sleep 3600 done
Logging in from server to original computer:
ssh -l pc_username -p 19222 localhost # Then enter the password of the original PC.
I usually start this script on a tty
(tty2/tty3 for example) in the background, automatically, with systemd. I enable auto-login on that specific tty
and then I check from the .profile
or similar file whether the login was done on that tty or somewhere else.