Tag Archives: Linux

It’s SysAdmin Day: Your Top 10 Linux Hacks for SpiderOak

Photo credit ovsage.org.

Be sure to thank and lavish gifts upon your SysAdmin today.

Last week, we asked the Linux community to submit their favorite Linux tips and tricks to share with their fellow SpiderOak users.

In honor of sysadmin everywhere, this is the Top 10 list of hacks (in no particular order):

  1.  SpiderOak here’s a hack. I wrote SysV init and systemd scripts for you: https://t.co/eg7G4Z9XRy
  2. Long time ago I created a post in my blog about howto backup my cpanel accout first locally and then to SpiderOak. Here you are: http://www.elsotanillo.net/2011/09/backing-up-a-cpanel-hosting-account/
  3. I made the SpiderOak sync with my home bin dir and point the PATH to the bin. Since I have many self made Bash and Ruby codes, I know that if I write one and save it, all my servers will have latest copies of code and immediately accessible. I also sync git repository this way(and the normal commit method), I can restore via git or from the SpiderOak when I need to do a rollback, knowing that I still have copies of code on other machines not just on the clouds gives me peace of mind.
  4. Stop spideroak eating all my 3G data when I’m on the road: In crontab:
    $ cat /home/joel/Dropbox/bin/stop_spideroak_when_on_3g.sh
    if (nm-tool | grep -A 4 Bigpond | grep connected 2>1 >/dev/null) ||
    (nm-tool | grep -A 4 Ultimate | grep connected 2>1 >/dev/null); then
    SPIDEROAK_PID=`ps aux | grep ‘SpiderOak$’ | sed ‘s/\s\+/ /g’ | cut -d’ ‘ -f2`
    kill -QUIT $SPIDEROAK_PID
    fi
  5. # SpiderOak completion
    # This should be placed in the /etc/bash_completion.d/ directory_SpiderOak()
    {
      local cur prev opts
      COMPREPLY=()
      cur=”${COMP_WORDS[COMP_CWORD]}”
      prev=”${COMP_WORDS[COMP_CWORD-1]}”
      opts=”–help –version –verbose –redirect –device –output –enable-schedule –disable-schedule –scan –scan-only –build –scan-and-build-only –sync –backup –restore –batchmode –headless –merge –purge –userinfo –user-info –shelved-x –print-shelved-x –space –tree –fulllist –tree-changelog –journal-changelog –force –selection –print-selection –reset-selection –exclude-file –exclude-dir –include-dir –rebuild-reference-database –billing –destroy-shelved-x –repair –purge-historical-versions –purge-deleted-items –vacuum –list-orphan-external-files –convert-to-hybrid-db –generate-previews –bootstrap –setup –list-shares –create-share –delete-share”
      case “${prev}” in
      –output | –exclude-dir | –include-dir | –purge-deleted-items | –journal-changelog)
        COMPREPLY=( $(compgen -d ${cur}) )
        return
        ;;
      –redirect | –exclude-file | –bootstrap | –setup | –backup | –restore | –purge)
        COMPREPLY=( $(compgen -f ${cur}) )
        return
        ;;
      *)
        ;;
      esac
      COMPREPLY=( $(compgen -W “${opts}” — ${cur}) )
    }
    complete -F _SpiderOak SpiderOak
  6. I have a desktop in the office, at the house, and a laptop that floats around, all running Gentoo Linux; naturally I want access to them all at anytime and anyplace. So my problem was: how do I figure out my ip address, both on the LAN and to the external world, and then update all my computers to have that information? Keep in mind that at the office I have no control over the network, router, and so on.I suppose a traditional answer would be something like purchase a domain name with a dynamic update to the ip address (e.g., dyndns.com), point it to the home desktop, and then have reverse ssh tunnels running all the time. The downside is the cost of the domain name and making sure that the desktop and tunnels are always up and running. Plus, the big disadvantage is the network overhead. If I happen to have the laptop in the office, going from it to the office desktop would involve a round trip through the internet instead of just staying on the LAN.So I thought, “I could skip the domain name with an updated ~/.ssh/config, plus I could add entries for the LAN ip and have the best solution. But how am I going to keep them updated without an ssh connection? Updated… in sync… sync… SPIDEROAK!” So I whipped up something quick in Python that runs at login and periodically through cron, and set spideroak to sync my ssh config file on all machine (yes, it could probably be done better in bash, but multi-line sed replacements are hard!).I know, the script could use some tiding up (e.g., wireless interfaces have different names on different machines, so for the time being I wrote that in by hand)… but it works, damnit!
    -- ~/.ssh/config --
    # Snipping some global options
    Host                 zeal_palace
    Hostname             internet-ip-address
    
    Host                 zeal_palace-local
    Hostname             192.168.1.100
    
    Host                 kajar
    Hostname             internet-ip-address
    
    Host                 kajar-local
    Hostname             192.168.0.110
    
    # You get the picture...
    
    -- update-ssh.py -- 
    
    #! /bin/env python3
    
    import os
    import re
    import subprocess
    
    def execute(cmd, capture=False):
        """
        Execute a command line process.  Includes the option of capturing output,
        and checks for successful execution.
        """
        #print(cmd)
    
        with open(os.devnull, 'w') as void:
            if capture:
                sub = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=void)
            else:
                sub = subprocess.Popen(cmd, shell=True, stdout=void, stderr=void)
        status = sub.wait()
    
        # Exit if the command fails for any reason.
        if status != 0:
            sys.exit(1)
    
        if capture:
            text = sub.stdout.read().decode("utf-8")
            text = text.replace('\n', '')
            return text
        else:
            return None
    
    host = execute('hostname', True)
    addr = execute('curl --max-time="60" --silent ifconfig.me', True)
    
    with open('/home/strider1551/.ssh/config', 'r') as handle:
        haystack = handle.read()
        needle = 'Host\s+{0}\nHostname\s+[a-zA-Z0-9.]+'.format(host)
        replacement = 'Host                 {0}\nHostname             {1}'.format(host, addr)
        haystack = re.sub(needle, replacement, haystack)
    
        if host == "enhasa":
            addr = execute("ifconfig wlp8s0", True)
            addr = re.findall('inet\s[a-zA-Z0-9.]+', addr)[0]
            addr = addr[5:]
            needle = 'Host\s+{0}-local\nHostname\s+[a-zA-Z0-9.]+'.format(host)
            replacement = 'Host                 {0}-local\nHostname             {1}'.format(host, addr)
            haystack = re.sub(needle, replacement, haystack)
        if host == "kajar":
            addr = execute("ifconfig wlp11s0", True)
            addr = re.findall('inet\s[a-zA-Z0-9.]+', addr)[0]
            addr = addr[5:]
            needle = 'Host\s+{0}-local\nHostname\s+[a-zA-Z0-9.]+'.format(host)
            replacement = 'Host                 {0}-local\nHostname             {1}'.format(host, addr)
            haystack = re.sub(needle, replacement, haystack)
    
    with open('/home/strider1551/.ssh/config', 'w') as handle:
        handle.write(haystack)
  7. It’s not super fancy, but a quick little script to batch process dvd/blu-ray rips and move them into my Plex movie library.
    cd /media/raid5/rips/ondeck/
    for f in *
    do
    HandBrakeCLI -Z “High Profile” -i “$f” -o “../processed/$f.mp4″
    rm -rf “$f”
    chown plex:plex “../processed/$f.mp4″
    mv -f “../processed/$f.mp4″ ../../plexLibrary/movies/
    date
    done
  8. Just a little command for those curious about their top 10 commands. Too bad it wont work for the selecting the top 10 linux hacks. Would make spideroaks job easier selected the top 10. Ihttp://www.omgubuntu.co.uk/2010/09/reveal-your-top-ten-most-used-terminal-commands
  9. I’m no Uber, but I have pet peaves I want taken care of. I don’t like dealing with updates, like at all, don’t want to deal with any maintanence notifications. Those make me feel like a slave to my machine. So on startup I have a script to do a robust and clean update on ubuntu and keep a good log of things incase anything happens. Recently I took off the automatic dist-upgrade because of a hardware issue with my lappy. But I’ll probably uncomment that again, maybe. I don’t only use this script everyday but literally everytime my computer is turned on. It’s very refreshing not to care about updates but know you’re completely updated. I also made a cron version for servers. (just took of the sleep and added to crontab)http://pastebin.com/RjCqBrmQ(The log file is written last entry first so you don’t have to scroll to see what the last action was)

    I have this other semi-uncompleted script that searches for rootkits, everytime my computer turns on. But I haven’t expanded it to any good kind of notification. I haven’t settled on a notification I’d be comfortable with. So I guess in that sense it’s kind of useless, but it’s good to have it so I can run it when I want and check the log files manually, periodically.

    http://pastebin.com/3Af5afWn

    These last two scripts some other spideroak users might like more.

    I like to use truecrypt but I don’t like using passwords for them, but keyfiles. I like lots of complicated keyfiles that can easily be hidden as anything, but I don’t like the work involved in making them. This keyfile generator originally used randomsound for lots of entropy but I stopped using that for haveged because of compatibility issues. I know software entropy generation isn’t the best but it’s good enough for my uses.

    http://pastebin.com/DBWQ5q6a

    (I had to research how to get a mid range number to make file sizes more randomly and found a super complicated function in a bash book. Many years later on commandlinefu.com I found an easy one liner. But I worked so dam hard on that freaking thing I decided to leave it in all it’s mess)

    There’s been so much debate, i.e legitimate scientific debate, on password length and type and how long and what’s exactly the safest. So I took the infamous inspiriration from https://xkcd.com/936, commandlinefu oneliners, and my own practice on what makes a strong – yet memorable – password. I’m very indecisive and run this thing like 10 times before I find one I like and even then I don’t go with exactly what comes out of it. Only used when I want to remember a good password but otherwise I just use a regular random one.

    http://pastebin.com/jzU1Grrw

    (I think some advanced password cracker could come up with a plausible amount of password hashes knowing your password attributes, according to some reasearch by Arstechnica, but I’m not sure that’s been proven in this case (the script way). Anyone know?)

    Sorry I have more than one script but these ones I use ALL the time. They are synced on every debian machine I have, with SpiderOak ofcourse ;)

  10. alias please=sudo :)Also my cp with progressbar (not finally tested and not prepared for the public release so please be gentle):
    https://gist.github.com/b3niup/6075240

Thanks to everyone who submitted and congrats to all who were chosen – you won 100GB/year!

Please email campaigns[at]spideroak.com if your hack was listed in the top 10.