IT notes

parallel xargs

To run a script in parallel using xargs: printf %d\\n {0..9} | xargs -n 1 -P8 sleep In this case sleep is going to be call 8 times (-P8) using has the input an int from 0 to 9. From the man: -P maxprocs Parallel mode: run at most maxprocs invocations of utility at once.

tmp

Ways to create a temp file: Using mktemp: $ mktemp /tmp/file.XXX The trailing Xs will be replaced with the process number and/or a unique letter combination Creating a temp dir: $ mktemp -d /tmp/dir.XXX Output could be saved into a variable: TMPDIR=$(mktemp -d /tmp/dir.XXXX) $$ Using $$: OUT=/tmp/file.out.$$ Here $$ will be replaced with the current process PID. $RANDOM OUT=/tmp/file.out.${RANDOM} $RANDOM is an internal bash/zsh function (not a constant) that returns a pseudorandom [1] integer in the range 0 - 32767

pkg -o OSVERSION

When updating if get something like this: pkg: Newer FreeBSD version for package jsoncpp: - package: 1101503 - running kernel: 1100506 Try uname -KU to get the version, and then: pkg -o OSVERSION=1100506 update -f pkg -o OSVERSION=1100506 upgrade

Ansible Patterns

To match hosts only starting with certain string a regex could be used for example to match hosts starting with the word fabrik: --- - hosts: ~fabrik.* become: True tasks: - name: uname shell: uname -a register: uname - debug: var: uname.stdout notice the ~

MTU 1453

If after upgrading macOS to 10.13.4 wifi stop working give a try to change the MTU:

radtest

To test a radius server: $ brew install freeradius-server Then: $ radtest {username} {password} {hostname} 10 {radius_secret} The 10 is the nas-port-number. Is an integer between 0 and 2^31, and it really doesn’t matter what you put here.

git basics

git branch -a This will print all branches, local or remote, to see only local branches: $ git branch To only see remote branches: $ git branch -r When you clone a repo after typing git branch -a the output will look something like this: $ git branch -a * master remotes/origin/HEAD -> origin/master remotes/origin/master master is a branch in the local repository, remotes/origin/master is a branch named master on the remote named origin:

Git Web Deployment Workflow

The idea behind is to push to a remote repository on the same web/service server and a post-receive hook will checkout the files to the public directory. Configuring the server Create the repository: $ cd $HOME $ mkdir my-site.git $ cd my-site.git $ git init --bare The idea of using .git as a suffix is just to distinguish between other directories. Crate the directory where you would like to deploy, for example:

OBJC_DISABLE_INITIALIZE_FORK_SAFETY

In macOS High Sierra if getting this: objc[55492]: +[__NSPlaceholderDate initialize] may have been in progress in another thread when fork() was called. objc[55492]: +[__NSPlaceholderDate initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug. Define: export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES This will fix temporally fix the problem and allow program to continue executing, more about this issue here: http://sealiesoftware.

bash git prompt

To display the current branch in the terminal prompt using bash, add the following lines to ~/.bash_profile: parse_git_branch() { git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' } export PS1="\[email protected]\h \[\033[32m\]\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\] $ "