Not sure how it was possible that I have not done this before but I recently realized I needed to forcibly remove a user from a login session on a remote Linux system and didn’t have a better idea than simply killing off all their individual system processes one at a time. Thankfully, Linux provides a much more useful way of dealing with kicking users from terminal sessions (and thereby shutting down their entire process tree as well.)
Will give you a list of user sessions based on which terminal they are logged into. This includes X sessions, virtual terminals, remote sessions, and any text mode logins. The output should looks something like this:
bobby :0 2011-04-21 20:01 ? 12122
bobby pts/0 2011-04-21 20:01 . 12405 (:0)
bobby pts/1 2011-04-21 20:01 02:10 12322 (:0)
root pts/2 2011-04-21 22:19 . 13887 (10.0.0.101)
You can then kill the session login by looking at the last column and killing that process ID. In the example above you can see there are two virtual terminals (i.e. the pts/X sessions), a remote session (the ssh session I am remotely accessing the machine on from host 10.0.0.101), and a single local login on terminal session :0. Because the terminal session must be responsible for starting the virtual terminals, you can simply kill the process 12122 force a logout of all three sessions.
Entirely too easy. If you would like to be kind (I am NOT) and actually warn your users that you are bout to kick them off, you can send them a system message using the standard Unix wall command. If you type wall you will get an open text area to type your message (end the message by clicking Ctrl+d) or you can pipe a message to standard input like so:
$echo “My name is Inigo Montoya. You killed my father. Prepare to die.” |wall
Wall will send a system message to every terminal session that allows messages (if you are root, that means everybody.)
What most people are objecting to is that the market gives people what the people want instead of what the person talking thinks the people aught to want.
Milton Friedman is easily the most influential economist since John Maynard Keynes. What makes him such a powerful voice for the free market is his ability to distill complex macro economic theory into chunks non-economists can easily understand. He is so influential, and understandable, that PBS actually produced a series with him explaining economic ideas and debating these thoughts with other prominent scholars, politicians, and businessmen. The series was called “Free To Choose.”
Unfortunately most of us don’t have hours worth of time to watch all the episodes (although you should.) To get a quick overview of each of his core concepts Trent Liberty has produced a series of 7 videos called The Friedman Series. The background audio ranges from amazing to annoying, but the topic selection is outstanding. If you get nothing else from the video, always remember that the biggest danger to liberty isn’t inequality, but the sincerity of the well intentioned.
One of the best parts of Unix systems is that fundamentally they are built as development platforms. The most common text command interface for Unix is call Bash (the Bourne Again Shell)and it is a full blown script-able interface allowing direct interaction with command line programs and giving the user the ability to string together these programs into really powerful applications. Because of the power of this interface, developers have over many years improved the ability to use it directly as well. Things like <tab> completion are well known, but how about reverse command searches, built-in text editor mode, and shortcuts galore. I have been trying to use more and more of this “built-in” bash functionality and so below are some of my favorite shortcuts and functionality.
|Ctrl + A
||Go to the beginning of the line you are currently typing on
|Ctrl + E
||Go to the end of the line you are currently typing on
|Ctrl + L
||Clears the Screen, similar to the clear command
|Ctrl + U
||Clears the line before the cursor position. If you are at the end of the line, clears the entire line. Especially useful when you know you’ve mis-typed a password and want to start again.
|Ctrl + K
||Cut the line after the cursor, inverse of the Ctrl + U
|Ctrl + Y
||Pastes the content from a previous Ctrl + K or Ctrl + U cut.
|Ctrl + H
||Same as backspace
|Ctrl + R
||Search through previously used commands
|Ctrl + C
||Sends SIGINT to whatever you are running (effectively terminating the program.)
|Ctrl + D
||Exit the current shell
|Ctrl + Z
||Puts whatever you are running into a suspended background process. fg restores it.
|Ctrl + W
||Delete the word before the cursor
|Ctrl + T
||Swap the last two characters before the cursor
|Alt + T
||Swap the last two words before the cursor
|Alt + F
||Move cursor forward one word on the current line
|Alt + B
||Move cursor backward one word on the current line
||Auto-complete files and folder names (f there is a multiple option match hitting Tab twice will list all possible values.)
|Alt + .
||Paste the previous commands final argument (great for running different commands on the same file path.)
To see a complete list of all bound bash shortcuts you can type
bind -P |less
but you may need to look-up some bash hex character values to understand all of them. What is more you can actually set bound shortcuts to almost anything you can think of, including actual applications, for example:
$ bind -x ‘”\C-e”‘:firefox.
will launch the Firefox web browser from the command line when you hit Ctrl + e.
Another one of my favorite commands is fc (fix command.) If you simply type
FC will copy your most recent bash history into your preferred editor (vi by default on most systems) and allow you to edit it within the editor. If you save and exit the editor it will automatically copy it the contents into the bash session and hit enter. Additionally if you are interested in editing some other history item you can type
to get a full history with numbers beside them. Then type
where<num> is the history number you want to edit. In a former life my bash terminal and fc was all I needed for most SQL testing.
Package building under RPM hasn’t actually changed a whole lot in the last decade. While I have notes scattered around the website on building and maintaining package repositories; the one part that has changed significantly is the use of git for version control. Thankfully tagging, archiving, and building packages is pretty simple under git basically consisting of the following three steps:
- git tag -a 1.1 -m “Version 1.1″
- git archive –prefix=projectname-1.1/ 1.1 |bzip2 > ~/Temp/projectname-1.1.tar.bz2
- rpmbuild -tb ~/Temp/projectname-1.1.tar.bz2
The -a option will create a “true” package tag although it will not be signed with a digital key. Of course the rpmbuild command depends on correctly formatted spec file in the base of your project directory. Make sure the spec file version and changelog have the same version number as your tag. FYI for scripting purposes it is good to remember that changelog dates use the following date command format:
date +’%a %b %d %Y’
The reason I mention scripting is because I am working at extending my automated build script for software packages I manage. Way back in my days at DPS I had developed a bash configuration that would allow me to download, package, and build a piece of software directly from the CVS repository.
When I moved to Cobb Engineering I also changes version control software and started using SVN. Extending my previous script to supportboth CVS and SVN wasn’t too hard. Now I have a number of personal projects at home as well as software examples I keep for my students at ITT-Tech; all of which is stored/managed in Git. The new software package script is almost done but I would really like to be able to update a spec file, changelog, tag, package, and build with one command.
The most useful part of my build script is that is doesn’t require me to spend any time remembering how to use it. By default is has both auto-complete as well as logical default behaviors. I just run buildpackage and it will list the available projects that I have ready to build. If I run buildpackage project it will present me with a list of versions that have already been tagged. One of these days I will post it publicly but I seriously doubt there is much interest in the broader community as almost everyone who develops at this level seems to already have their own custom build scripts.