Monday, September 19, 2016

Listing all Physical Drives on a Remote Machine

Getting Physical drive lists for remote machines using PSExec

You can use PsExec and wmic to easily get disk information about remote machines. From a command prompt run as a user with login rights on the remote machine

PsExec.exe \\remote1 wmic.exe logicaldisk get

 This returns a nice garbled list of data :)  Adding some filtering commands to wmic gets us a little better list:

PsExec.exe \\remote1 wmic.exe logicaldisk get caption,drivetype,volumename

We then get a much nicer formated list including drive letters, drive types and the volume name.

Adding a windows filter of find "3" we can then return just the rows that have an actual physical volume for a finished command of

PsExec.exe \\remote1 wmic.exe logicaldisk get caption,drivetype,volumename | find "3"

This is a nice command to use to be able to quickly identify what drives on a remote machine you might want to monitor.

Friday, June 24, 2011

Delay for a few seconds in a Batch file

This is simple:

choice /T 10 /D Y /N

Replace 10 with the number of seconds to replace.  This will return an error code of 1 (1st choice on the list) so just be aware that errorcode=1 is success for this.

Zabbix monitoring MySQL on a windows Server

In order to monitor MySQL on windows you need a few extra utilities.  I downloaded and used the cut, wc, and grep utilities out of that.

Then add the following lines to your agentd configuration file:

UserParameter=mysql.queries[*],mysql -u root -ptest -N -e "show global status like 'Com_$1'" -s | cut -f2,mysqladmin -uroot -ptest ping | grep alive | wc -l | cut -d" " -f 7
UserParameter=mysql.uptime,mysqladmin -uroot -ptest status | cut -d: -f2 | cut  -d " " -f2
UserParameter=mysql.threads,mysqladmin -uroot -ptest status | cut -d: -f3 | cut  -d " " -f2
UserParameter=mysql.questions,mysqladmin -uroot -ptest status | cut -d: -f4 | cut  -d " " -f2
UserParameter=mysql.slowqueries,mysqladmin -uroot -ptest status | cut -d: -f5 | cut  -d " " -f2
UserParameter=mysql.qps,mysqladmin -uroot -ptest status | cut -d: -f9 | cut  -d " " -f2
UserParameter=mysql.version,mysql -V
 Replace test with the root@localhost password for your MySQL box.  Once you have done this you can use the Template_App_MySQL to monitor all of those UserParameters.  I ended up making a clone of that template so that I could change the service from "mysql" to "mysqld.exe" in order to monitor it.

Tuesday, September 23, 2008

Mounting Shares with Spaces

In linux sometimes you want to mount a windows share that has spaces in the name. This is actualy quite easy, just use \040 in place of the space

//ip.of.server/Home\040Folders/ejh /home/ejh/Documents cifs username=ejh,password=*****,uid=500,gid=500 0 0

Monday, September 22, 2008

Removing SVN folders from a directory

If you need to removing a folder from subversion run the following command

rm -rf `find . -type d -name .svn`

Incorrect DNS Settings Reappearing

I recently moved a virtualized server to a new host machine. In the process its virtual hardware changed, and so its MAC address changed. It got a new address from DHCP correctly and reported it to DNS, but DNS would only hold that information for about 15 minutes before switching back and reporting the old DNS.

After many frustrating hours I decided to check DHCP, and sure enough, DHCP had the old and new leases both with the same host name and was reporting them both to Active Direcotry.

Solution: Simply remove the old lease from DHCP, I'm sure eventualy it would have expired and fixed itself as well.

Monday, March 3, 2008

Hiding SVN Directories using .htaccess

You can use the .htaccess file to hide specific directories pretty easily using a simple rewrite rule
RewriteEngine on
RewriteRule \.svn/ - [F]
This same format could be used to hide any directory on a web server.

Thursday, February 21, 2008

Finding Disk space Hogs

I occasionaly have a system go off the deep end eating up all of its space. This can be very difficult to track down. In order to find the offending files/directories goto the root and do
du -k -s * |sort -n
this will list the directories and files in the current directory in asc order so that the last one you see is the largest. Using this it is easy to move down the directory tree and quickly identify the offending files.

Using date in file name (and compressing files)

Yea this is stupid an easy, and also very annoying if you forget how!

    backup=`date +%Y%m%d`
tar czvf SQL-$backup.tar.gz *.sql
That backs up all the current .sql files in a directory into a file with todays date as the name

Deleting Files over Certain Age

The command to delete files over a certain age is deceptivly easy in linux.

   find * -mtime +5 -exec rm {} \;

That finds all files over 5 minutes old in the current directory. This is quite usefull in a backup script run from cron.