Currently Browsing: Linux

Cheatsheet: dynamic date value in shell scripts

using a variable – easier to read in scripts:
NOW=$(date +"%Y%m%d%H%M%S")
echo "bar" > "$NOW"foobar.txt

one-line, equivalent to above:
echo "bar" > $(date +"%Y%m%d%H%M%S")foobar.txt

alternate single-line format:
echo "bar" >> $(date "+myfile%Y%m%d.txt")

man strftime to see formatting values

install VirtualBox Guest Additions & mount shared folders

To use Guest Additions on a VirtualBox VM you need to install Guest Additions from the VBoxGuestAdditions.iso.

On Ubuntu/Debian, you should install additional system tools first if you don’t already have then:

apt-get update
apt-get install dkms build-essential linux-headers-$(uname -r)

First use the VB app to set up the share and then “insert” the virtual CD via the VB storage settings menu drop-down, then:

mount /dev/cdrom /mnt
cd /mnt
./VBoxLinuxAdditions.run --nox11

run

mount | grep vbox

to verify the share path, etc.

Alpine Linux with Docker – node build tool updates

Smaller distros like Alpine for containers just seems to make sense.

Some build tools for node.js include:

apk --update add bash nano wget python make gcc g++

You can install on a “build” container and create an artifact to transfer to a sparse box without the build tools. See base images like:
mhart/alpine-node.

Basic HTTP Auth on Nginx

Quick set-up for basic authentication on Nginx.

Create htpasswd file on local or install tools via apt or yum, e.g.,

apt-get install apache2-utils
sudo htpasswd -c /etc/nginx/.htpasswd exampleuser

Will be presented with password prompts

Update your Nginx site config with:

auth_basic "Restricted";
auth_basic_user_file /etc/nginx/.htpasswd;

Reload or restart Nginx

/etc/init.d/nginx reload

RAR on CentOS 7

sudo rpm -ivh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm
sudo yum -y install rar unrar

« Previous Entries