COTD: Screen

Overview

Ever wanted to run a long-running command but you can’t seem to get it to complete because you have a shaky connection? Can’t run your command in the background? Want to leave your IRC session open so you can SSH from work and catch the chat room action? Enter screen. Screen allows you to

 

Installation

Well, installation depends on your flavor of Linux. Here are the installation methods for a few common flavors of Linux:

 

up2date

To install screen with up2date issue this command:

# up2date -i screen

 

yum

To install screen with yum issue this command:

# yum -y install screen

 

apt

To install screen with apt issue this command:

# apt-get install screen

 

Usage

Using screen is extremely easy. Here are a few commands to help you understand how it operates.

 

Creating a new screen

Type "screen" to start a new screen. Note that the title of putty (if you’re using putty) tells you which screen you are currently attached to by inserting "[screen 0: bash]  before your normal [email protected]:/path text.
image

You should now run any commands you want to save inside your "screen".

 

Detaching a screen

To detach your current screen simply press "CTRL + AD" (Control plus A then D). You are now presented with a message saying "[detached]". You are now returned to your normal shell outside of your virtual screen.

 

Attaching to an existing screen

Chances are if you are using screen you’ll need to reattach to your detached screen. Type "screen -r" to reattach to your current screen. If multiple screen sessions are active, you’ll see a list of current screens to choose from. Type "screen -r PID" to reattach to that screen.
image
Multiple screens to choose from

Video Overview

Here’s a quick demonstration of screen.

10 Substantial Events in Linux History

Here are a few substantial events in Linux history:

1991 – Linus Torvalds posts his first message about his free operating system resembling MINIX. He mentions that the operating system will probably never support anything other than AT-hard drives.

1992 – Andrew Tanenbaum, a computer scientist and author of the MINIX kernel, wrote a post in response to Linus’ post in 1991. He said "Linux is Obselete" which sparked the debate about the structure of Linux. Hundreds of people were on-board with Linux at Linus’ campus; then thousands were developing and perfecting the code … soon to become hundreds of thousands.

image 1993 – The compressed kernel source was no around 800K and Linux had passed multiple revisions (15+)

1994 – Linus opened Linux version 1.1; beginning the stable development of the Linux we know today.

1994 – Caldera was formed in October 1994. I won’t go much into detail about Caldera – about all they contributed was a dual-processor Pentium machine for the development of the SMP-based kernel.

1996 – The 2.0 kernel was released and included many enhancements. The list looks like this: Multi-Architecture support (x86 and Alpha). This kernel also had support for SMP. The kernel is now around 5MByte compressed.

1996 – KDE was founded. The choice to go with the Qt toolkit was a sketchy one. Qt, at the time, did not use a free software license. The GNU team was concerned about this.

1997 – In August 1997, two projects were started to help KDE. The Harmony Toolkit was the replacement for the previously pay-only Qt libraries. GNOME was also founded but build without Qt and only built upon free software)

1999 – The kernel has doubled in size. The new kernel 2.2 release included a number of features. Finer-grained locking for improved multi-processor support. IBM announced an large project in support of the Linux operating system.

2004 – Microsoft published documents evaluating the use of Windows Vs. Linux with the name "Get the Facts" on their website. RedHat, Novell and IBM published articles in response to Microsoft’s "bent" version of the truth.

Netgear Releases Open Source Wireless Router

image It’s about time a company releases a router based on open-source ideologies. I personally run an old Dell Optiplex at home with pfSense… I may now be changing my router. Enter the WGR614L. This new 54G, fully-capable router is available to the retail masses. The router includes an entire open-source community site which includes blogs, forums, articles and projects. The site is called "MyOpenRouter.com".

 

The Features

This router has many robust features that makes this a great choice for only $69.00 (even cheaper at NewEgg.com).

  * 240 MHz CPU

  * 4 MB flash

  * 16 MB RAM

  * Works with Windows Vista (I believe this is a feature)

 

This router is reasonably priced and it makes me very happy to know that a larger company supports the open source community. This kind of support will open many options for users of this router.

This router is compatible with well-known 3rd party firmware’s like Tomato and DD-WRT.

 

Retail links:
Amazon.com
NewEgg.com

 

[ via cyberciti.biz ]

LEGOs Are Awesome: Facts

image I recently found an article on GIZMODO about LEGOs. Looking back on all the Lego experiments I had as a kid, it’s very interesting to see some facts about Lego’s revealed.

 

Here’s some facts from the article:

Their Mindstorm NXT includes Bluetooth capability for communicating.

In their entire history, there has not been a single report of a Lego decomposing or releasing toxic byproducts.

There are very few bad bricks produced at the plant – mostly due to their very precise brick-making process.

[via GIZMODO]

BASH: Find Orphaned Users and Orphaned Groups

Sometimes, for auditing purposes, it can be useful to look for users and groups which are “orphaned” or have no users/groups associated with them. image

Finding Orphaned Users

Use this script to find orphaned users:

   1: USEREXCLUSIONS=( sync shutdown halt operator )
   2: USEREXCLUSIONSNUM=${#USEREXCLUSIONS[@]}
   3:  
   4: for i in `cat /etc/passwd | awk -F : {'print $1'}`; do
   5:  
   6: command=`grep $i":x" /etc/group | wc -l`
   7: if [ $command -lt 1 ]; then
   8:  
   9:         for ((t=0;t<$USEREXCLUSIONSNUM;t++)); do
  10:         look=${USEREXCLUSIONS[${t}]}
  11:                 if [ $i = $look ]; then
  12:                         orphaned=0;
  13:                         break;
  14:                 else
  15:                         orphaned=1;
  16:                 fi
  17:         done
  18:  
  19:         if [ $orphaned -eq 1 ]; then
  20:                 echo $i" is orphaned!"
  21:         fi
  22:  
  23: fi
  24:  
  25: done   

 

Finding Orphaned Groups

Use this script to find orphaned groups:

   1: GROUPEXCLUSIONS=( sys tty disk mem kmem wheel dip lock users floppy utmp slocate )
   2: GROUPEXCLUSIONSNUM=${#GROUPEXCLUSIONS[@]}
   3:  
   4: for i in `cat /etc/group | awk -F : {'print $1'}`; do
   5:  
   6: command=`grep $i":x" /etc/passwd | wc -l`
   7: if [ $command -lt 1 ]; then
   8:  
   9:         for ((t=0;t<$GROUPEXCLUSIONSNUM;t++)); do
  10:         look=${GROUPEXCLUSIONS[${t}]}
  11:                 if [ $i = $look ]; then
  12:                         orphaned=0;
  13:                         break;
  14:                 else
  15:                         orphaned=1;
  16:                 fi
  17:         done
  18:  
  19:         if [ $orphaned -eq 1 ]; then
  20:                 echo $i" is orphaned!"
  21:         fi
  22:  
  23: fi
  24: done

Homegrown Software Saves a Lost Autistic Man

image Recently I was reading an article here which shows how an application called “Search Tracker” guided searchers to an autistic man named "Keith kennedy late Sunday in a wooded area.

 

The software calculates the possibility that someone would be lost in certain areas based on density of plant life and wooded areas.

 

More on this story at LinuxInsider.

Managing Your EXIM Queue

Have you ever had a hard time with spammers or recently logged in to one of your Linux servers only to find 10-20+ exim processes hogging all of your resources? Check out the commands below to help you manage your queue.

 
Count The Messages

Count the number of messages in your queue. If this number is abnormally large; it’s usually a good indication of some malicious activity on your server.
# exim -bpc

 

View The Messages

After finding out you have 1000’s of messages in your exim queue it might be a good idea to stop the exim service.
# service exim stop

 

After stopping the service run this command to see what’s in the queue:
# exim -bp | less

 

This will pipe the results to the less command to enable you to page through and search the results. Find one of the message ID’s that seem to be duplicates (spam) and copy it to your clipboard.
A message ID looks like this: 1KBB28-0006UC-Fl

 

Run this command to view the header of the suspect message:
# find /var/spool/exim/input -name "1KBB28-0006UC-Fl-H" -exec cat {} \;

or this method with exim
# exim -Mvh 1KBB28-0006UC-Fl

 

The header can show you exactly where the message is originating as well as the recipient. If the spammer is connecting directly to your SMTP server you can also gather the IP address here.

 

Removing The Messages

Let’s get the messages out of the queue. For our example, we’ll use the address [email protected] as the sending address. To remove all emails in the queue for [email protected] run this command:

# exim -bp | awk ‘$4[email protected] { print $3 }’ | xargs exim -Mrm

e2label: Label Your Disks

With cheaper storage you might find yourself literally submersed in storage devices. It is possible to have your block devices change (from sdc to sde) when using multiple controllers of the same model (I’ve experienced this with 3Ware controllers). So how do you know where to mount your devices after a reboot? Use e2label to label your disks (much like NTFS labels in Windows).

 

Labeling Your Device

To label your device follow these steps:

# e2label /dev/sdb1 awesomedisk

 

Modifying Your fstab

Now you can modify your fstab to reflect your label changes. Instead of using the path to the block device (/dev/sdb1) you can use this syntax: (LABEL=awesomedisk)

Example:

LABEL=awesomedisk                 /mnt/awesomedisk                       ext3    defaults        1 1

 

Check Current Label

To check the label currently set for a block device use this command:
# tune2fs -l /dev/sdb1 | grep "Filesystem volume name:"