Skip to main content

Posts

Programatically named variables in bash.

Suppose you wanted to do the following in bash: for label in a b c d e f do variable_${label}=${label} done This has the intended result of setting a series of variables: variable_a variable_b variable_c variable_d variable_e variable_f But if what if you want to dereference them programatically? for label in a b c d e f do echo ${variable_${label}} done is not acceptable bash syntax. But there is a way... We can abuse export and env . We set them with: for label in a b c d e f do export variable_${label}=${label} done We can then programmatically dereference the variables by searching for them in the output of env and using awk to get their value. for label in a b c d e f do echo "`env | grep variable_${label} | awk -F= '{print $2}'`" done How's that for bash abuse?

Fixing SSH connection problems in EGit in Eclipse

Note: I posted a version of this on Stack Overflow. Errors can occur when there is an underlying SSH authentication issue, like having the wrong public key on the git remote server or if the git remote server changed its SSH host key. Often the an SSH error will appear as: " Invalid remote: origin: Invalid remote: origin" Eclipse will use the .ssh directory you specify in Preferences -> General -> Network Connections -> SSH2 for its ssh configuration. Set it "{your default user directory}.ssh\" . To fix things, first you need to determine which ssh client you are using for Git. This is stored in the GIT_SSH environmental variable. Right-click on "Computer" (Windows 7), then choose Properties -> Advanced System Settings -> Environment Variables. If GIT_SSH contains a path to plink.exe, you are using the PuTTY stack. To get your public key, open PuTTYgen.exe and then load your private key file (*.ppk). The listed public key sho...

Straight to Voicemail, If Unknown - A simple free method for blocking scam calls and robocalls

Problem: How do I block scam calls and robo calls? Premise:  If the call is important, the caller will leave a voicemail. Solution: We put every number we know into our caller ID systems. If a number we do not recognize, or a number that blocks caller ID calls, we always let the call go to voicemail. Callers that really want or need to talk with us will leave a voicemail. If we are not interested, we delete the message. This process initially upset some of our parents, but we have not had to deal with a robo or scam call in some time, since the calling computers almost never leave a voicemail. Our parents are now used it and leave messages. Sometimes, we pick up as soon as they start talking. Our friends mostly communicate via Facebook, internet chat tools, and email these days, so they are used to asynchronous communication and don't mind leaving a message. The political parties and charities we support do leave messages. We call them back to donate or express our s...

A script to split a file tree into separate trees - one per file extension present in the original tree

Purpose Have you ever had a tree of files from which you only needed certain types of file? For example, I had an iTunes library with some Apple files from another iTunes account combined with a large number of MP3s. I wanted to pull out the tree of MP3s only. You can make such a tree by passing a combination of flags to rsync that make it do an exclusive include. How? Pass the following flags to rsync to make it do an exclusive include for files fitting a certain globbing pattern. Fill in for the variables of course, if you want to use this line alone. In particular, this rsync line: rsync -av --include '*/' --include "*.${extension}" --exclude '*' ${source_directory}/ ${top_directory_of_results}/${extension}/ The script: ========================================================== This tool reads a directory of files that have extensions and then copies each type of file to its own tree. The location of each file in the subtree matches that file...

How do I clean up old large files on Linux?

Many people who have run Linux file servers and ftp servers have at some point wanted to free up some space. One good algorithm to do this efficiently is to remove old data starting with the largest files first. So how to generate such a list? One method is to use a " find -exec du " command: find /path/to/full/file/system -type f -mtime +10 -exec du -sk {} \; | sort -n > /var/tmp/list_of_files_older_than_10_days_sorted_by_size Once you have that list, you can selectively delete files from the bottom of it. Note that the list will likely be exponentially sorted. That is, the bottom 10% of the list will take up a huge chunk of the used storage space.

How the find the Active Directory Domain Controllers listed in DNS on Linux...

Assumptions: You have the "host" utility from BIND. You can do a zone transfer from the local DNS server Your Active Directory admins have properly configured DNS for Active Directory If you have the above, use the following command: host -t srv -l your.active.directory.dns.domain | grep _kerberos._tcp.*._sites.dc._msdcs.your.active.directory.dns.domain Replace your.active.directory.dns.domain with your actual AD DNS domain.