October 25, 2013

Spectacle OSX Mavericks fail


Did you upgrade to OSX Mavericks only to find Spectacle failing and no "Enable access for assistive devices" option available?

Me too.

Go to your Systems Preferences, go to Security and Privacy, go to Privacy, then Accessibility, and finally check-mark Spectacle (You may need to click the Lock at the bottom left corner first).



----------
Please consider crypto tipping:
  

October 17, 2013

Batch file: For each live computer in a domain, do something



Need a batch file to perform an action, executable, or script for online domain members only?

Here, for simplicity, our do-something is "echo computer-name is online":

Save the following to a batch file: (two % signs are needed in batch files, one % if at the command-prompt)


@echo off

dsquery * domainroot -filter "(&(objectCategory=Computer))" -limit 0 -attr cn > computers.txt

for /f %%i in (computers.txt) do (
   ping -n 1 -w 500 %%i | find "Lost = 0">NUL && echo %%i is online || echo %%i is offline
)

del computers.txt


This can easily be changed to work on a specific OU and skip sub-OU's (-scope onelevel):

dsquery * "OU=EXAMPLE_OU,DC=EXAMPLE,DC=COM" -filter "(&(objectCategory=Computer))" -limit 0 -attr cn -scope onelevel > computers.txt

So your do-something could be powerful when combined with commands like:
psexec.exe \\%%i some-command
or
START /B some-batch-calling-psexec.bat

You could get fancy and do multiple things by enclosing them in ( ) but separating them with &:
( echo %%i online & script.bat %%i)


So here is an example batch file that runs "gpudate /target:computer /force" on the Computers OU and it's sub OU's (This assumes you are logged in with administrative privileges):

@echo off
setlocal enableextensions enabledelayedexpansion

dsquery * "OU=Computers,DC=EXAMPLE,DC=COM" -filter "(&(objectCategory=Computer))" -limit 0 -attr cn > computers.txt

for /f %%i in (computers.txt) do (
ping -n 1 -w 500 %%i | find "Lost = 0">NUL && ( echo !time! %%i ONline, Launching... & START /B psexec.exe \\%%i -e -d -s -low gpupdate /target:computer /force ) || echo !time! %%i OFFline
)

del computers.txt
echo.

--------------

Please consider crypto tipping:
  

August 24, 2013

Diskfree Watcher script for Linux (Walkthough)

Problem: VMWare does not report Guest OS freespace, and as such there are no alarms triggered and emailed.

Solution: For Linux, script hourly "df" testing within the OS.

We will script the use of “df” to watch disk free space and perform sendmail if the usage is greater-than or equal-to a specified percentage.


Prerequisite: “df”, “sendmail”, “grep”, “awk”, “cut” -- please install them if not installed.
Prerequisite: You will need a valid mail-relay target or mail server target.

Assuming root account.


note: You will alter the script for your specific “df” output.
note: Your drive device will have to be determined manually.
note: “sendmail” my be in some other path than “/usr/sbin”
note: This was all performed on CentOS, a RedHat clone.  Other distributions may be slightly different.


Let’s first run the “df -h” command (diskfree -human_readable)


In my case, this is:
df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_netflow-lv_root
                      90G   64G   22G  75% /
tmpfs                 939M     0  939M   0% /dev/shm
/dev/sda1             485M  115M  346M  25% /boot
/dev/mapper/vg_netflow-lv_home
                     4.9G  160M  4.5G   4% /home


So I have a choice, I can use “df” against any of the listed file-systems. Each one has a Mount point (alias)


I’m interested in my root drive, so I’ll choose “df -h /dev/mapper/vg_netflow-lv_root”.  I could have as easily chose “df -h /” which would be the same in this case.
df -h /dev/mapper/vg_netflow-lv_root
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_netflow-lv_root
                      90G   64G   22G  75% /


Now what I’m interested in is the Use% (75% here).  I can “grep” for “% /” so that only that specific line is printed.
df -h /dev/mapper/vg_netflow-lv_root | grep "\% \/"
produces
                      90G   64G   22G  75% /


Now I’m still only interested in the 75%, which is the 4th item.  Let’s “awk” that.
df -h /dev/mapper/vg_netflow-lv_root | grep "\% \/" | awk '{ print $4 }'
75%


Now I only see 75%.  But I can’t ‘If-Then’ a number containing the %-sign, so I’ll “cut” it.
df -h /dev/mapper/vg_netflow-lv_root | grep "\% \/" | awk '{ print $4 }' | cut -d% -f1
75


This is the result I want to perform an action on -- so now a script can be written.  Here is mine:
cat /root/scripts/diskwatch.sh
#!/bin/sh
used=`df -h /dev/mapper/vg_netflow-lv_root | grep "\% \/" | awk '{ print $4 }' | cut -d% -f1`
echo "diskspace used: $used%";
if [ $used -ge 93 ] ;
then
/usr/sbin/sendmail "myaccount@mydomain.com" << EOF
From: root@netflow.mydomain.com
To: me@mydomain.com
Subject: Alert: netflow diskspace $used% used.
netflow diskspace $used% used.
EOF
fi


This script prints the usage to screen and also sends mail if the usage if greater-than_or_equal-to 93%.


Note the “used”-variable assignment -- The command is single-back-quoted.  The ` character on the ~ (tilde) key.
Change the trigger-limit (93 here) as you see fit. And also, all your email information as it pertains to you and your server.  Make sure to mark your script executable, in my case
chmod +x /root/scripts/diskwatch.sh


You will need to configure your OS for sendmail.  As, stated above, you will need a valid email server or relay target.  This write-up does not go into such.


Now configure sendmail, In my case, I used postfix sendmail, so I added
relayhost = mail.mydomain.com
to the file “/etc/postfix/main.cf” then restarted the postfix service
service postfix restart


You should test sendmail by typing the part of the script between “then” and “fi” directly in the command-line.


If it works, you are ready to cron-job the script.
crontab -e
add
0 * * * * /root/scripts/diskwatch.sh
for hourly execution.

Good Luck!
-----------------
Please consider crypto tipping: