• Running a BASH script when my Laptop is opened at home – Part 2

    As I mentioned in this post I should be able to run a script to find my current gateway’s MAC address. With this info, I should be able to tell when I am home, and launch a script. In this post, I talk about sleepwatcher, which runs a script when the machine is woken up. Sleepwatcher looks for a file named .wakerc and executes it when the machine wakes. If I put the following in my .wakerc, it will execute whatever I like (for example a rsync script) when the machine is woken up and at home:

     

    #!/bin/bash
    sleep 120
    GATEWAY=`/usr/sbin/netstat -rn | /usr/bin/grep default | /usr/bin/grep en1 | /usr/bin/cut -c20-35`
    MACADDRESS=`/usr/sbin/arp -n $GATEWAY | /usr/bin/cut -f4 -d' '`
    if [ "$MACADDRESS" = "xx:xx:xx:xx:xx:xx" ]; then
    	/bin/echo "$(date): I am at home now: $MACADDRESS" >> ~/Desktop/wake.txt
    	# script I want to run at home is next line
    	rsync Documents/ server:Documents/
    else
    	/bin/echo "$(date): I don't know where I am: $GATEWAY $MACADDRESS" >> ~/Desktop/wake.txt
    fi
    
    

  • How to remove a machine from a RHN Satellite

    I wanted to move a VM from a RHN Satellite back to the default Red Hat Network. I found these two files contained all the info:

    /etc/sysconfig/rhn/up2date
    /etc/sysconfig/rhn/systemid

    I just moved them aside and ran rhn_register to re-register the system.

    Then I ran “yum clean all” to make yum happy


  • Rebuild your the default CentOS yum.repo.d folder

    On a dev machine, somehow, I managed to erase my yum.repo.d contents. I wanted to rebuild the repo files back to their default. First you need to figure out what version you are using:

    • cat /etc/redhat-release

    Then visit the correct release at : http://vault.centos.org/

    • navigate to the correct os/x86_64/CentOS/ directory (could be os/x86_64/CentOS/ i386/)
    • Download the following files to the server:
      • wget http://vault.centos.org/5.x/os/x86_64/CentOS/centos-release-notes-5.x-0.x86_64.rpm
      • wget http://vault.centos.org/5.x/os/x86_64/CentOS/centos-release-5-x.el5.centos.x86_64.rpm
    • Then install the two rpms:
      • rpm -Uivh *.rpm
    Should be back to the original shipping repo files.

  • Install VMware ESX4.1 via PXE

    We recently received 2 new servers that I needed to install the newest ESX on. I downloaded the IOSs, but I did not want to have to burn them. So I decided to try and install ESX via PXE. I did not have an answer file (kickstart), so I wanted to run an interactive install from PXE.

    I already had a PXE/TFTP server configured, so I just needed to add a new instance to the pxelinux.cfg file.

    LABEL VMWARE-ESX
    KERNEL images/vmware/esx/vmlinuz
    APPEND initrd=images/vmware/esx/initrd.img vmkopts=debugLogToSerial:1 mem=512M url=http://server.name.local/vmware

    The different options for “APPEND” can be found here. Works like a charm.


  • xcopy: permissions,recursive,incremental

    I can never remember xcopy’s flags, so I am creating a post for myself.

    xcopy SourceDrivePath DestDrivePath /X /C /E /H /Y /D

    /X Perms
    /C continue on error
    /E Recursive with empty folders
    /H (hidden and system) Copy hidden and system files
    /Y (yes) No Prompts
    /D (date) SourceDate is newer then DestDate (incremental)


  • PowerShell Function to get uptime on multiple computers

    I wanted to create a function that I could use to find the uptime of several workstations. I did not want to read a list of machine name from csv, I just wanted pass a list of workstation names and get their uptime back. I also added a ping check to make sure the machine is alive.

     

    Function Get-Computer-LastBootTime {
    $Args | ForEach-Object -Process {
    $ping = gwmi Win32_PingStatus -Filter ("Address='" + $_ + "'") | Select-Object StatusCode
    if ($ping.statusCode -eq 0) {
    
    $wmi = gwmi Win32_OperatingSystem -EA silentlycontinue -ComputerName $_
    $localdatetime = $wmi.ConvertToDateTime($wmi.LocalDateTime)
    $lastbootuptime = $wmi.ConvertToDateTime($wmi.LastBootUpTime)
    $uptime = $localdatetime - $lastbootuptime
    $days=$uptime.Days
    $hours=$uptime.Hours
    $mins=$uptime.Minutes
    echo "$_ uptime: $days days $hours hours $mins mins"
    
    }
    else {
    echo "$_ is offline"
    }
    } 
    }
    
    

  • php53 included in CentOS 5.6

    I wish I read release notes, it would make my life easier. In my previous post, I was worried about CentOS 5.x not having a new enough version of PHP to run the soon to be release WordPress 3.2. Well, RedHat’s 5.6 release notes clearly say:

    Version 5.3.3 of PHP is now available in Red Hat Enterprise Linux 5.6 as the separate php53 package

    To move to the 5.3 version of PHP, I ran the following commands:

    • yum erase php\*
    • yum install php53 php53-gd php53-mysql php53-pdo php53-mbstring  php53-cli php53-devel php53-common php53-xml

    That was easy.


  • “error establishing a database connection” in a previously working WordPress site

    My site just crashed!!! I received the oh-so-helpful error “establishing a database connection” when I went to my site. Other sites on the server were fine.  The site was working fine, and my config had not changed. The httpd error log showed nothing.

    Then I found this in the MySQL logs (/var/log/mysqld.log)

    [ERROR] /usr/libexec/mysqld: Table ‘./db_name/wp_options’ is marked as crashed and should be repaired

    To fix I ran:

    mysql -e “use db_name;REPAIR TABLE wp_options”

    And we are back . . .