Latest Updates: bsd

  • Kill a GNU Screen Session from the Command Line

    17:48 on January 4, 2010 | 1 Comments Tweet This! | Digg This!
    Tags: bsd, ,

    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.

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

    00:21 on January 2, 2010 | 0 Comments Tweet This! | Digg This!
    Tags: bsd, ,

    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
     
  • Using SCP Aliases to Upload Files Quicker (OS X, BASH)

    15:32 on August 2, 2009 | 0 Comments Tweet This! | Digg This!
    Tags: bsd, , ,

    If like me, you have a particular path on a server you always upload files to, via SCP, then you’ll probably want a better way than typing the full path into the scp command everytime you upload a file!

    This command has been tested on OS X, but there’s no reason it wouldn’t work on a Linux or BSD machine running BASH, either.

    I personally have a “stuff” directory on a web server, where I put random files to share with people, but it’s path is pretty long on the remote web server, and I have to type it everytime I run the scp command – not quick or great!

    There’s a way around it, though, by using bash aliases.  By editing the ~/.bash_profile file (.bash_profile in your home directory), we can alias common scp commands.

    So, for example, if I have a file called screenshot.png and I want it to go to /var/www/stuff on a remote server called server.example.com, I would normally have to do:

    scp screenshot.png server.example.com:/var/www/stuff

    This can get boring quick, especially if you do it a lot during the day.  We can, however, alias this to a command called whatever we want (take care though not to use an alias of an already existing command/application!)  So, if I wanted just a command of “scpstuff” I could do that by editing the ~/.bash_profile file by adding:

    alias scpstuff="scp $1 server.example.com:/var/www/stuff"

    You will need to close the terminal and reopen it for the alias to take affect, after saving the file.

    What this will do is, take the first argument to “scpstuff” (represented by $1), and run the command with it in, so, to upload something to the /var/www/stuff directory on server.example.com, all I would need to do now is:

    scpstuff screenshot.png

    You will be prompted for your SSH password as normal (unless you use SSH keys) but it’s much quicker than typing the whole line out each time!

    Of course, you could set up lots of aliases, such as scpstuff, scpimage, scpscreenshot – anything you do a lot would be useful!