draft0 - a shared blog by just some people

Menu

Entries tagged 'cat:Linux' (Page 3)

Beep Wars

This is one of these things that gets copied around without crediting the author or mentioning any source. Yea, I'm doing it too. I don't know where I got it from anymore.

If you still have a physical pcspeaker, execute this in your Linux shell for some beep music:

beep -l 350 -f 392 -D 100 -n -l 350 -f 392 -D 100 -n -l 350 -f 392 -D 100 -n -l 250 -f 311.1 -D 100 -n -l 25 -f 466.2 -D 100 -n -l 350 -f 392 -D 100 -n -l 250 -f 311.1 -D 100 -n -l 25 -f 466.2 -D 100 -n -l 700 -f 392 -D 100 -n -l 350 -f 587.32 -D 100 -n -l 350 -f 587.32 -D 100 -n -l 350 -f 587.32 -D 100 -n -l 250 -f 622.26 -D 100 -n -l 25 -f 466.2 -D 100 -n -l 350 -f 369.99 -D 100 -n -l 250 -f 311.1 -D 100 -n -l 25 -f 466.2 -D 100 -n -l 700 -f 392 -D 100 -n -l 350 -f 784 -D 100 -n -l 250 -f 392 -D 100 -n -l 25 -f 392 -D 100 -n -l 350 -f 784 -D 100 -n -l 250 -f 739.98 -D 100 -n -l 25 -f 698.46 -D 100 -n -l 25 -f 659.26 -D 100 -n -l 25 -f 622.26 -D 100 -n -l 50 -f 659.26 -D 400 -n -l 25 -f 415.3 -D 200 -n -l 350 -f 554.36 -D 100 -n -l 250 -f 523.25 -D 100 -n -l 25 -f 493.88 -D 100 -n -l 25 -f 466.16 -D 100 -n -l 25 -f 440 -D 100 -n -l 50 -f 466.16 -D 400 -n -l 25 -f 311.13 -D 200 -n -l 350 -f 369.99 -D 100 -n -l 250 -f 311.13 -D 100 -n -l 25 -f 392 -D 100 -n -l 350 -f 466.16 -D 100 -n -l 250 -f 392 -D 100 -n -l 25 -f 466.16 -D 100 -n -l 700 -f 587.32 -D 100 -n -l 350 -f 784 -D 100 -n -l 250 -f 392 -D 100 -n -l 25 -f 392 -D 100 -n -l 350 -f 784 -D 100 -n -l 250 -f 739.98 -D 100 -n -l 25 -f 698.46 -D 100 -n -l 25 -f 659.26 -D 100 -n -l 25 -f 622.26 -D 100 -n -l 50 -f 659.26 -D 400 -n -l 25 -f 415.3 -D 200 -n -l 350 -f 554.36 -D 100 -n -l 250 -f 523.25 -D 100 -n -l 25 -f 493.88 -D 100 -n -l 25 -f 466.16 -D 100 -n -l 25 -f 440 -D 100 -n -l 50 -f 466.16 -D 400 -n -l 25 -f 311.13 -D 200 -n -l 350 -f 392 -D 100 -n -l 250 -f 311.13 -D 100 -n -l 25 -f 466.16 -D 100 -n -l 300 -f 392.00 -D 150 -n -l 250 -f 311.13 -D 100 -n -l 25 -f 466.16 -D 100 -n -l 700 -f 392

I've converted it for FreeBSD:

echo "L15T120MSO4G...G...G...D#..A#G...D#..A#G.....>D...D...D...D#..<A#F#...D#..A#G.....>G...<G..G>G...F#..FED#E.~~~~<G#~>C#...C..<BA#AA#.~~~~D#~F#...D#..GA#...G..A#>D.....G...<G..G>G...F#..FED#E.~~~~<G#~>C#...C..<BA#AA#.~~~~D#~G...D#..A#G.._~D#...A#G....." > /dev/speaker

I'm no musician. I know it's not quite right. But if you ask me, for what it is it's almost good enough. (I think you can tell that I'm not a Star Wars fan.)

Comment via email

Theres no feeling like the feeling you get when you finally tidied up your .bashrc, added every alias and function you ever wanted there and then accidently overwrite it with something silly before you made a backup.

Comment via email

Bash One-liners

Great collection of Bash one-liners at https://linuxcommandlibrary.com/basic/oneliners.html

Another, more structured collection at https://github.com/onceupon/Bash-Oneliner

Comment via email

Generate Random Passwords in Linux

Two ways to generate random passwords on the command line:


#!/bin/bash
if [ $# -eq 0 ]
then
  echo "I'll not generate anything for you if you won't give me at least one argument."
  echo "1st argument: password length"
  echo "2nd argument: number of passwords (optional)"
  exit
fi
i=0
if [ $# -gt 1 ]
then
  num=$2
else
  num=1
fi
while [ $i -lt $num ]; do
  let i=i+1 
  </dev/urandom tr -dc '12345!@#$%qwertQWERTasdfgASDFGzxcvbZXCVB' | head -c$1
  echo ""
done

Pass the length of the password as the first argument and the number of passwords as the second argument, if you want more than one.

Or you can use just this line to generate a single 16 character long password with the same rules.


</dev/urandom tr -dc '12345!@#$%qwertQWERTasdfgASDFGzxcvbZXCVB' | head -c16; echo ""

Or just use pwgen (man page) to have more options. It's probably in your distro's repos.

Comment via email

moviefy.sh - Make Bash Output like It's The 80s And We're In Hollywood

Source this script in Bash to make unformatted output of commands appear on screen slowly, accompanied by beeping galore.

source moviefy.sh or . moviefy.sh. Every command executed after that will be moviefied. There is no way to turn it off again. (Just exit.) Please note that formatted output may be mangled or it may crash the script. Curses stuff won't work.

#!/bin/bash

export LC_ALL=C
exec > >\
(while IFS= read -d '' -r line; do
  if [[ -n $line ]]; then
    echo
    for (( i=0; i<${#line}; i++ )); do
      char="${line:$i:1}"
      printf '%c' "$char"
      case $char in
        [" "]) sleep 0.04
               ;;
        [$'\t']) sleep 0.08
                 ;;
        [$'\v']) sleep 0.7
                 ;;
        [$'\n'$'\r'$'\f']) sleep 0.25
                           ;;
        *) beep -f $(shuf -i 3000-3200 -n 1) -l 5
           sleep 0.015
           ;;
      esac
    done
    printf "${PS1@P}"
    printf ""
  fi
done)
PROMPT_COMMAND='printf "\0"'
Comment via email

Backup Shell Script

This entry is an update of the entry 'Automatic backups with rsync under Linux'.
There is a newer version of this entry: 'backup.sh'.

This is an outdated version of my backup script. I've posted a newer version here.


Here is an updated, more versatile version of the simple backup script I posted before. It takes arguments now (wow)! So now you need only one backup.sh and in your cron tab or similar you can pass it the directory you would like to back up.

For example backup.sh /home/user UsersHomeDir will back up the home directory of user to the predefined location.

In preperation you only need to mount the drive you would like to back up to and enter the mount point (or a path inside it) at the top of the script (variable $BUDIR). In this destination folder (which can be an external drive or a NAS) backups are organised in directories named by the host name of the machine the script was executed on and the name of the backup job (the second argument). By default it will keep 8 incremental backups per backup name. This can be changed with the variable $NUM.

If you give the script only one argument it will interpret it as a name of a file that contains the directories that you want to back up.

If you pass no argument to the script it will look for such a file in the location that is pre-defined at the top of the script (variable $LIST).

You can download the script here if you want to.

Comment via email

Automatic backups with rsync under Linux

There is a newer version of this entry: 'Backup Shell Script'.

This is a very primitive and bad script. I've posted a new version here.

"No backup no pity!"

I don't agree. But I like the saying for reasons that I shall not analyse here right now.

I don't always have proper backups of my data, let alone off-site backups. I have no backup at all of a large portion of my hoarded data. But I did at some point take the time to create scripts that back up important stuff automatically. Here is a simple one using rsync and a mounted share as a target.


#!/bin/bash

NAME="usershomedir"
SRCDIR="/home/user"
BUDIR="/mnt/backup/"

rm -rf $BUDIR$NAME.8
mv $BUDIR$NAME.7 $BUDIR$NAME.8
mv $BUDIR$NAME.6 $BUDIR$NAME.7
mv $BUDIR$NAME.5 $BUDIR$NAME.6
mv $BUDIR$NAME.4 $BUDIR$NAME.5
mv $BUDIR$NAME.3 $BUDIR$NAME.4
mv $BUDIR$NAME.2 $BUDIR$NAME.3
mv $BUDIR$NAME.1 $BUDIR$NAME.2
cp -al $BUDIR$NAME.0 $BUDIR$NAME.1
NOW=$(date)
echo >> $BUDIR$NAME.log
echo >> $BUDIR$NAME.log
echo >> $BUDIR$NAME.log
echo "##### STARTING INCREMENTAL BACKUP AT $NOW" >> $BUDIR$NAME.log
echo >> $BUDIR$NAME.log
rsync --archive -L --delete $SRCDIR  $BUDIR$NAME.0/ 2>&1 | tee -a $BUDIR$NAME.log

You would create one of these scripts per directory you want to backup. BUDIR is the directory where you want to backup to be stored. This will probably be the same for every script if you have only one backup drive/server. SRCDIR is the directory you want to backup. NAME is the name you want the backup to be stored under. It can be a sub-directory if you want, so you can sort the backups into directories on the target.

Comment via email
Mastodon