I use several small though nifty bash scripts daily.
pass.sh
Generates random 10 char A-Za-z0-9_ password. Simple but Extremely convenient to generate annoying but moderately safe passwords.
#!/bin/bash </dev/urandom tr -dc A-Za-z0-9_ | head -c10 echo
Oberon.sh
Connects to gateway home server over ssh. Checks if I am at home or outside by checking a webpage on that server, if it loads, it connects to the internal IP; if not it gets the IP adress from a webpage (I made Jopin for exactly this purpose) and connects to that with some extra tunnels in place.
#!/bin/bash # Global user="gert" command="ssh" # Internal IIp="192.168.0.1" #The internal IP IMagicWord="works!" #The string for which to test to see if the server is available # External EIp_Source="http://your.server.org/homeIP" #A file on the internet containing your home IP ETunnel="-L 84:localhost:80 -L 85:192.168.1.2:80" #Tunnel some stuff EPort="-p 22" # Port to use to connect to your home setup if [[ $( curl -s --connect-timeout 1 $IIp | grep -o $IMagicWord ) = $IMagicWord ]]; then command="$command $user@$IIp" else command="sudo $command $user@$( curl -s $EIp_Source ) $EPort $ETunnel" # The sudo allows you to tunnel more freely fi echo $command $command
remote_tar.sh
I use this as a crude way to set up a dated backup. The script connects over ssh, tars the content you request and saves the resulting archive to your harddisk. You will need to input your password manually or use public key auth.
#!/bin/bash # Tar remote location # Remote data user="username" serv="remote server" map="/map/you/want" tar="tar cvz" # The tar command with necessary parameters files="* .emacs*" # The files you want tarred extra_options="--exclude=backup*" # The files you Dont want tarred and more options # Local data destination="/home/you/backup" #where you want to store the backups filename="backup.$serv.$( date +%y%m%d ).tgz" # Format of the backup tar; this one ll be something like "backup.remote server.100427.tgz" # magicks ssh $user@$serv "cd $map && $tar $files $extra_options" > $destination/$filename
For those it may help ;)
This work is licensed under a
Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
Use this code at your own peril; I am not responsible for anything that happens to you or your devices. You re a big boy or girl, please do some research before using it if you have any concerns!