Home Page

Category: shell scripting

Batch create new users on Linux

A while ago I had to create many new users on a Linux machine. Since I'm lazy, I opted to automate this process. The newusers command combined with pwgen (to generate new passwords) was the solution. First I installed pwgen, a utility to automatically generate passwords: $ sudo apt-get install pwgen I created a file […]

I've released cfgtrack v1.0: Get notified of changes on your server

I needed a simple way of being notified when configuration files had been changed on some servers. Nothing fancy. No configuration management, no intrusion detection, no centralised versioning control repositories. Just a simple email saying what's been changed. I couldn't find a tool that did just that, and didn't require massive amounts of configuration, so I […]

Script to start a Chrome browser with an SSH Socks5 proxy

Socks5 proxies are great. They allow you to tunnel all traffic for applications that support Socks proxies through the proxy. One example I frequently use is starting a Chrome window that will do everthing as if it was an a remote machine. This is especially useful to bypass firewalls so you can test websites that […]

Read the POSIX standard

Stop reading your local manual pages when programming/scripting stuff, and use the POSIX standard instead: Online POSIX 2008 (EEE Std 1003.1-2008) standard There are four main parts: The Base Definitions (XBD): The basics of a POSIX-compliant system. The System Interfaces (XSH): What POSIX-compliant systems offer to programs. I.e. programming in C (stdlib) The Shell & […]

Excluding results of a 'find' command (inverting tests)

In kind of a follow up to my previous post on using find and sed to search and replace multiple files, I found out something else. I needed to find and replace something in every file, except for any files which had ".svn" in them. After struggling for a few fruitless minutes with -regex, I […]

Linux search and replace

I always kept a small Python script around for searching and replacing in Linux. Turns out that GNU sed has an inline edit mode which I didn't know about: -i[SUFFIX], –in-place[=SUFFIX] edit files in place (makes backup if extension supplied) This makes searching and replacing in files as simple as: find . -name "*.txt" -print0 […]

chkrootkit false positives filtering

Chkrootkit is a tool that searches for rootkits, trojans and other signs of break-ins on your system. Like most security scanners, it sometimes generates false positives. Chkrootkit doesn't have a native way to filter those out. From the FAQ: [Q:] chkrootkit is reporting some files and dirs as suspicious: `.packlist', `.cvsignore', etc. These are clearly […]

Floating point stuff in Bash

Shell scripting is powerful, but unfortunatelly it gets less easy if you want to perform floating point calculations in it. There's expr, but it only handles integers: [todsah@jib]~$ echo `expr 0.1 + 0.1` expr: non-numeric argument If you wish to perform floating point calculations in shell scripts, you can use the bc tool: "bc – […]

More XML Commandline unix tools

A little while ago I reported on a little XML toolset called XMLStarlet. XMLStartlet provided a bunch of commandline tools for reading and converting XML files from the commandline. Usefull in scripts. However, it uses a pretty complex interfacing. For instance, you'll have to know XPath to easily select a particular piece of XML to […]

XML commandline toolset

Those who are familiar with Unix commandline tools like grep, sed and cut will know about the enormous power they provide. They make it a breeze to mangle, transform and retrieve information in and from text files. Unfortunately, they're mostly dependant on row and column based information. That is, they expect each line in a […]