Kill a GNU Screen Session from the Command Line

This article is about GNU Screen – you can read about GNU Screen here: http://www.gnu.org/software/screen/

There may be times when you have multiple, or even a single, screen session which you want to kill without attaching to it and ending it as you normally would.

You can kill a screen session using the session ID or the name (if the name is unique enough).

Warning: Both ways end all processes within the screen session, so if you have any open files/applications, make sure you don’t need/want them – they’ll be kill’d along with the session.

Killing by session ID

First, run screen -list to get the id of the current sessions (we use the id to kill the screen session)

daz@scampi:~$ screen -list
There are screens on:
11493.irssi     (04/01/10 16:25:44)     (Detached)
30784.newapps   (01/01/10 19:42:38)     (Detached)

As you can see in this example, I have two sessions, a session called “irssi” with id 11493, and a session called “newapps”, with an id of 30784.

So, to kill the “newapps” session, I’d run:

daz@scampi:~$ screen -X -S 30784 kill
daz@scampi:~$

.. and the session will now be gone.  You can verify that by running screen -list again.

Killing by session name

If your screen session name is unique enough (for example, if you have one called “newapps” and another called “irssi” as per my example) you can kill by name:

daz@scampi:~$ screen -X -S newapps kill
daz@scampi:~$

The reason I say unique enough –  if you have a session called “newapps” and one called “newapps1”, you will need to use the ID to end “newapps” before “newapps1” – you’ll simply be asked to specify the session again otherwise.

How to Stop .DS_Store From Being Created on Network Drives (OS X)

.DS_Store files can make even the tidiest network shares look horrible to none-OS X users.

Whenever an OS X machine accesses a network share, it creates a .DS_Store file for it’s own use (on SMB/CIFS, AFP, NFS, and WebDAV servers).  These files are invisible to the OS X user, but will show up to anyone else using other operating systems such as Windows or a Linux distribution.

Turning them off is easy though, by running the following command:

defaults write com.apple.desktopservices DSDontWriteNetworkStores true

You will need to either log off or restart the computer for the changes to take affect.

For more information, please see the official knowledge base article here:  http://support.apple.com/kb/HT1629

Removing packages only installed as dependancies and no longer needed (Ubuntu, Debian)

We’ve all installed packages, using apt-get, where it’s installed a lot of other packages to satisfy dependancies.

But what if you remove that package at a later date that needed all of those dependancies?  You’ll probably find it’s left the dependancies installed.. and if you’ve not installed any other packages which also need those dependacies, they’re just taking up hard drive space.

It’s easy to remove them, though – after all, you no longer need them so why keep them?

The command is simple (and needs to be run as root):

apt-get autoremove

… and that’s it.  The man page entry for this command:

“autoremove is used to remove packages that were automatically installed  to satisfy dependencies for some package and that are no more needed.”

So the next time you install a package which needs lots of dependancies, and you decide you want to remove it for whatever reason, remember to run apt-get autoremove afterwards!

Warning: You do need to be careful when running this – always check which packages it’s proposing to uninstall before confirming.  I have seen reports of random packages being removed, breaking the entire system – even though it is an officially supported feature of apt-get, and it can be very useful, use it with caution.

Windows 7 Experience Index Performance on the Atom-powered, Asus 1005HA Netbook

The question of “How does Windows 7 run on ………….” is often asked.

I’ve been running an Asus Seashell 1005HA (6-Cell Battery, 63Wh) with Windows 7 for some time now, and use it as my main machine 90% of the time.

Just as a side note, the only thing I have done is upgraded the RAM to 2GB (from the standard 1GB) by adding a single 1GB SO-DIMM to the Netbook.  For the cost and how easy it was, it was well worth the upgrade!

The Windows 7 Experience Index is often a good guide to see how a machine will perform (processor, memory (RAM), graphics, hard disk) – the results for this Netbook are below:

windows-7-performance-asus-1005ha-netbook

Finding out when (and where from) a user last logged into a Linux/BSD machine

There may be times when you want to find out when and where from a user last logged into a Linux or BSD machine.

Of course, you could trawl through auth logs, but there is a quicker way by using “lastlog“.

lastlog is a command which shows you the last login time and also from where (if it was a remote session, it’ll show you the IP/Hostname) a user logged in.

If you log into the machine and at a terminal run, you’ll get the information:

droptips@server:~$ lastlog
Username         Port     From             Latest
root                                       **Never logged in**

(I’ve removed all of my information for security reasons)

There is a man page available for “lastlog” accessible via:

droptips@server:~$  man lastlog

You can also read the Ubuntu 9.10 man page for lastlog here: http://manpages.ubuntu.com/manpages/karmic/man8/lastlog.8.html
The Wikipedia page is here:  http://en.wikipedia.org/wiki/Lastlog

iPhone Apps Not Launching? Do they Open and then Close Instantly?

Have you been happily using all of your third party apps from the AppStore for ages, and then, one day, none of them load?

We’ve all had applications which seem to start loading then close instantly.. but what if they are all doing it?  The default Apple applications work fine, but your downloaded ones don’t.

I’ve seen this on a couple of iPhone’s now, and the standard “turn it off and on again” doesn’t seem to work, nor does doing a soft reset by holding the Home and Power button.  However, there is hope, and this has worked both times for me:

Go to the AppStore, download any application you want, free or paid for.  It doesn’t matter; I’ve downloaded whatever was first in the Top Free section on both occasions.  Let it download and install, and, once that is complete, you’ll probably find that all of your other apps start working too.

If this works, then awesome… if it doesn’t work, then, at least you’ve tried!  I tried this out of pure luck the first time, and it’s now worked twice for me.

If you come across this problem, and the above has worked for you, let me know in the comments below!

Windows 7 Keyboard Shortcut: Snap Current Window to Left or Right

A new feature in Windows 7 is the ability to “snap” a window to the left or right of the screen, for side by side viewing.

You can, of course, just drag the window to the side you want, but what if you don’t want to use the mouse?  Well, there’s a keyboard shortcut for that!

Windows Key + Left Arrow
Windows Key + Right Arrow

By pressing the Windows Key with either the left arrow or right arrow, the current window will snap to whichever side you select!
If you keep pressing the same keyboard combination, it will go round in a circle.  So, if you keep going left, it’ll snap to left, then right, then back to normal again.  If you’re lucky enough to have a multiple monitor setup, it’ll cycle through all of the monitors in turn.

No E-Mail Client in Windows 7? Where’s Windows Mail or Outlook Express?

So, you’ve just installed Windows 7 and go to add your e-mail account. You go to Start, and look for Mail – it’s not there. You look in All Programs – same story, it’s not there, it’s “missing” – so, what do you do?

Microsoft have removed the default e-mail client found in Vista, Windows Mail, from Windows 7 – no longer is it installed by default. But what if you need to check that POP3 or IMAP account? Well, you have to install a client manually.

If you’ve been used to Outlook Express in Windows XP or Windows Mail in Vista, you’ll probably be most comfortable with “Windows Live Mail“. This application is part of the Microsoft Live set of applications, which also includes Messenger. You can download Windows Live Mail here:

http://download.live.com/wlmail

Once you download the package, select the applications you want, and let them install. After a short while of downloading and installing, you’ll now have Windows Live Mail installed, ready for your e-mail account!

Reading STDIN to PHP from the Command Line (CLI)

There may be times when you want to read from STDIN to a PHP script you’ve created from the command line.

Code below:

$in = fopen('php://stdin', 'r');
while(!feof($in)){
    $text = $text . fgets($in, 4096);
}

What this will do is read from STDIN, and create a $text variable of the contents.  It does this until the whole of STDIN has been read.

So:

cat file.txt | php my-php-file.php

… will put the contents of file.txt into the variable $text for use within the PHP script.