Author: sotech

  • OS X Mavericks: How to show the date in the menu bar

     

    This one is nice and easy – go to System Preferences -> Date & Time -> Clock and then tick “Show Date”:

     


    apple-os-x-mavericks-show-date-in-menu-bar

    A small thing, but quite useful.

  • Fedora 20: ifconfig missing on minimal install

     

    If you have selected the minimal install option you might be surprised by just how minimal it is; one example is that the ifconfig command is not available. The command yum install ifconfig doesn’t work – it’s part of another broader package. We can find out which one that is by running:

    yum provides ifconfig

     

    Through that we can see that the net-tools package installs it. Run:

     

    yum install net-tools

     

    …and you should be able to now use ifconfig.

  • How to kill a KVM virtual machine in Promox via the command line or terminal

     

    Sometimes a Proxmox KVM VM will stop responding to the GUI’s attempts to shut it down; fortunately it’s easy to shut it down from the command line. Make note of the VM ID (next to the name of the VM in the left pane of the Proxmox GUI), log into the server via SSH as root and run:

     

    qm stop [vmid]

     

    e.g.:

     

    qm stop 124

     

    Check back in the GUI a few seconds later and you should see that the KVM has stopped.

  • How to cache yum repositories on CentOS using apt-cacher-ng on Debian or Ubuntu

     

    If you have a lot of virtual (or real) machines running Debian or Ubuntu and a limited internet connection, it can make a lot of sense to use apt-cacher-ng to create a local cache of the packages you use so that they are only downloaded once. The current version of apt-cacher-ng can also help out with yum repositories!

     

    On CentOS, edit /etc/yum.conf and add:

     

    proxy=http://[ip-of-your-local-apt-cacher-ng-server]:3142

     

    If you have changed the default port of apt-cacher-ng from 3142, you will need to modify that. Our example file:

     

    [main]
    cachedir=/var/cache/yum/$basearch/$releasever
    keepcache=0
    debuglevel=2
    logfile=/var/log/yum.log
    exactarch=1
    obsoletes=1
    gpgcheck=1
    plugins=1
    installonly_limit=5
    bugtracker_url=http://bugs.centos.org/set_project.php?project_id=16&ref=http://bugs.centos.org/bug_report_page.php?category=yum
    distroverpkg=centos-release
    proxy=http://10.1.1.12:3142

    #  This is the default, if you make this bigger yum won’t see if the metadata
    # is newer on the remote and so you’ll “gain” the bandwidth of not having to
    # download the new metadata and “pay” for it by yum not having correct
    # information.
    #  It is esp. important, to have correct metadata, for distributions like
    # Fedora which don’t keep old packages around. If you don’t like this checking
    # interupting your command line usage, it’s much better to have something
    # manually check the metadata once an hour (yum-updatesd will do this).
    # metadata_expire=90m

    # PUT YOUR REPOS HERE OR IN separate files named file.repo
    # in /etc/yum.repos.d

     

    As you can see, our local apt-cacher-ng VM is 10.1.1.12.

     

    Run yum update and check your apt-cacher-ng’s cache – you should now see some CentOS respositories cached there.

  • How to reset a user password in Windows without knowing the original password

     

    Today we were asked how to reset a Windows user password (in this case the administrator account for a Windows Home Server 2011 install) without knowing the original password. The user had a logged-in Administrator session but had typo’d their password twice successfully during the install and was not keen on reinstalling then repeating the several hours of setup they had just completed.

     

    If this happens to you, open up a CMD window with Administrator privileges (in the WHS 2011 example the CMD window automatically has these) and type the following:

     

    net user [username] *

     

    In this case:

     

    net user administrator *

     

    You will be prompted to enter a new password without having to provide the existing password first. To get a list of the users on the system, you can run:

     

    net users

     

    Use this for good, not evil!

  • Postfix basic example – how to send an email from the command line

     

    If you have a system with a working Postfix install (in this case, it’s likely that it was configured during install) and you want to send an email from the command line, you can do so with the following:

     

    mail -s “subject” [email protected]

    email content goes here

    .

     

    Type in the first line, hit enter, type out your content, hit enter, type a single fullstop, hit enter, and your email is sent!

  • Debian Wheezy: /etc/sudoers missing

     

    If you’re looking to add something to the /etc/sudoers file in a Debian Wheezy install, you may find that the file isn’t there! To create the file while logged in as the root user you need to install the sudo package:

     

    apt-get install sudo

     

    Once that install completes the file will appear:

     

    #
    # This file MUST be edited with the ‘visudo’ command as root.
    #
    # Please consider adding local content in /etc/sudoers.d/ instead of
    # directly modifying this file.
    #
    # See the man page for details on how to write a sudoers file.
    #
    Defaults        env_reset
    Defaults        mail_badpass
    Defaults        secure_path=”/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin”

    # Host alias specification

    # User alias specification

    # Cmnd alias specification

    # User privilege specification
    root    ALL=(ALL:ALL) ALL

    # Allow members of group sudo to execute any command
    %sudo   ALL=(ALL:ALL) ALL

    # See sudoers(5) for more information on “#include” directives:

    #includedir /etc/sudoers.d

     

  • Awk: Remove everything after the first word in each line

     

    Another awk question. How to remove everything after the first word in each line? E.g., if we wanted to remove everything but the names in this input (FILENAME.txt):

     

    Anna 123 09123 Main Street

    Bob 109 09800 Smith Street

    Joe 0981 123123 King Street

     

    We can use awk like so:

     

    awk ‘{ print $1 }’

     

    e.g.:

     

    cat FILENAME.txt | awk ‘{ print $1 }’

     

    which will print:

     

    Anna

    Bob

    Joe

     

    Short and sweet.

  • Awk: Remove first line of file

     

    Short and sweet – when piping data through awk, how do we remove the first line of the input?

     

    awk ‘{if (NR!=1) {print}}’

     

    e.g.

     

    cat FILENAME.txt | awk ‘{if (NR!=1) {print}}’

     

    Done!