Almost forgot before going to bed but I feel bi-weekly is a good rhythm for this.

Let us know what you set up lately, what kind of problems you currently think about or are running into, what new device you added to your homelab or what interesting service or article you found.

  • harsh3466@lemmy.ml
    link
    fedilink
    English
    arrow-up
    5
    ·
    1 day ago

    I’ve been working on some bash scripts to help manage my media files. I’ve been slowly working on learning more bash and I’m pretty pleased with my progress. After I finish this bash book I’m reading (can’t remember the title atm), I think I’m gonna jump into awk.

    • Xanza@lemm.ee
      link
      fedilink
      English
      arrow-up
      4
      ·
      edit-2
      1 day ago

      Bash is a really great shell, but consider trying out a functional shell scripting language like Elvish (which is also a shell). Syntatically it’s pretty similar and not hard to pickup, but it’s stupid powerful. A cool example is updating different servers via ssh in parallel using a servers.json file;

      [
        {"name": "server.com", "user": "root", "identity": "~/.ssh/private_key0", "cmd": "apt update; apt upgrade -y"},
        {"name": "serverb.com", "user": "root", "identity": "~/.ssh/private_key1", "cmd": "pacman -Syu"},
        {"name": "serverc.com", "user": "root", "identity": "~/.ssh/private_key2", "cmd": "apk update; apk upgrade"}
      ]
      

      and a little elvish magic;

      var hosts = (from-json < servers.json)
      peach {|h|
        ssh $h[user]@$h[name] -i $h[identity] $h[cmd] > ssh-$h[name].log
      } $hosts
      

      Just run the script and boom, done. You can even swap out peach which is parallel each for each if you want to do each command procedurally–but I really love using peach, especially with file operations over many different files. Linux is fast, but peach is fuckin’ crazy fast. Especially for deleting files (fd -e conf -t file | peach {|x| rm $x }, or one thing that I do is extract internal subs (so they play on my chromecast) in my Jellyfin server, using elvish makes it really fast;

      fd -e mkv | peach {|x| ffmpeg -i $x -map 0:s:0 $x.srt }
      

      Find all *.mkv files, pass the filenames through ffmpeg (using peach) and extract the first subtitle as filename.mkv.srt. Takes only about a few seconds to do thousands and thousands of video files. I highly recommend it for home-labbers.


      Pretty dumb example, but peach is like 6x faster;

      ❯ time { range 0 1000 | each {|x| touch $x.txt }}
      5.2591751s
      ❯ time { range 0 1000 | peach {|x| touch $x.txt }}
      776.2411ms