Recursive Access Control Lists with Max Depth

Here is a Visual Basics script I put together which will list all of the Access Control Lists (ACL’s) for all folders in a particular directory.

It allows you to specify a start point and a max depth to recurse.

I needed this so that I could generate a report listing the ACLS’s for various shares. It uses the CACLS executable and as long as you have access to the shares it should run without issue. (However, as with anything Microsoft, I make no guarantees that it will function properly on your system). I tried to account for various idiosyncrasies’ in the way windows operates but if you find a bug, let us know and we will try to correct it.

Download -> ACL List script

Monitor a WD ShareSpace using XYMon on any remote network

Do you happen to be a systems support guy who needs a method of getting the basic stats of a WD ShareSpace into your XYmon or MAG monitor? If you are like me then you are a systems admin responsible for many different networks spread across the Internet. You then may have deployed a few NAS systems including the WD ShareSpace that runs a version of BusyBox Linux. This is good news because WD provides access to the shell over SSH if you enable it via the web admin (advanced section). So now go enable SSH access and then puttythe system using the username “root” and a password of “welc0me”  where the 0 in welc0me is a zero.

With shell access we can do many things, one of which is getting the stats from the system.  Currently we have only 1 method to get the stats to XYmon but we are exploring some custom XYmon client binaries we can distribute in future versions of this article.  That may make this article a mute point so check back every so often for updates.

Today we have to do monitoring in 2 parts,

#1 Have a script on WD ShareSpace running on a regular intervals, that executes  the basic commands to produce the files we need to stat the system in XYmon.

#2 Have a Windows system grab the stat files from WD ShareSpace and process them before sending them on to the XYMon server.

First script is the WD Sharespace script which is a very simple shell script that does nothing more then cat to several text files ( meminfo, df, du, uptime and load) and saves them to a share on the WD ShareSpace called Public. You can modify the script to place files on any share you want. The script should then be executed with the following command while SSHed in to the WD ShareSpace

The first time you run the script you will need to make it executible. To do so type:

chmod 0755 ./Report.sh

The to run the shell script type:

Report.sh &

This will place the script in the background as a process and release your shell so you can logout without stopping the script. The script will run then sleep for 5 minutes then run again replacing files with updated files every 5 minutes until you stop it(which should be never).  You will need to change the permissions on the files the first time you run script so that the report files are world readable. To do this use the following command.

chmod 0777 ./*report.txt

We now have stat files on a share that we want to “FTP” off. The key word here is FTP so we will want to allow anonymous FTP to the WD ShareSpace. Login to the web admin of the WD ShareSpace and enable FTP on the device. This allows the Perl script we use next to grab the stat files, process them and then send them on to the XYmon sever via a proxy connection.

WDShareSpace Scripts

The next step is to setup the Windows system to proxy the stats to the remote XYMon server. I normally use one of the Windows server we monitor via XYMon but if this is the only thing you monitor then a windows desktop can be used as well. Either way you will need a Active State Perl set up on a Windows box to be the proxy.

Today the script is Perl, tomorrow it could be a Powershell or some other language suitable for Windows but for today it’s Perl. Perl is not native to Windows so you will need to add it’s language to Windows by the way of Active State Perl for Windows. To install ASP go to Active State Perl.  Install Perl and make sure you select to place Perl in the PATH variables with in Windows during install process. Now download our Perl script and place it in  a directory on your Windows server.

You should edit the script variables so that it reflects your setups, (Share to look for files in, the name of the WDShareSpace as seen on XYMon server ).  The run the Windows Scheduler and create a new daily schedule to run the perl script “WdShareSpace.pl”. After creating the daily schedule go back in and edit the schedule and select the advanced section. Find the “run every” and set it to 5 minutes and the in the “run for” place in 24 for 24 hours a day. This will get the script running every 5 minutes which is the same schedule as the shell script running on the NAS so you will get updates every 5 minutes.

So to summarize:

We have 2 scripts (Report.sh and WDSharespace.pl) Report.sh runs on the NAS and after permissions are changed it is executed with the (&) symbol after it so it drops to the background and keeps running when you close the ssh window. This script creates a set of report text files in the same directory as the script. The WDShareSpace.pl runs on Windows with Active State Perl installed and it has several varibles in script that need to be edited to point it to the NAS and XYMon servers and it is scheduled to run inside of Windows Scheduler(AT) on a 5 minute interval.

If all is successful you should get some thing like the following in your XYmon server if you configured the BBHOST for the WDShareSpace HOST.

Disk view:

Kaseya Agent Procedure – FTP Remote Client Backup Script

Backup Windows Systems to a FTP Server

Download: -> Kaseya FTP Backups

So you have Kaseya clients out on the wire that need some level of backup but are not near a NAS or USB Drive. Have thoes clients backup to a FTP server by using WinSCP and a Kaseya Script to do the job for you.

This script has several peices and can be customized for what ever need you have. I currently have the script setup in 3 files.

File #1 (WinSCP_Backup.bat) This is executed by the Kaseya script and passed 2 variables. The variables are the name of the local folder and the name of the remote folder you want to sync.

Example:

c\temp\WinSCP_backup.bat userA FTPdirA >> c\temp\backup.log

We call the BAT file passing “userA” and “FTPDira” this could be the users name for their home directory and the remote directory which could be any folder on your ftp minus the first “/”

File #2 (WinSCP_backup.txt) This file tells WinSCP how to connect to your FTP server and what root directories to start looking in for the folder names provided above. You need to edit this file adding your FTP server information, username and password for FTP if needed.

File #3 is WinSCP.exe, This is a freely available FTP and SCP client for windows that is very configurable and has CLI functions.

This set of scripts in it’s current form will allow you to sync the local systems users home directories to a remote FTP server.

Sync is currently one direction as shown below. But you can sync any way you want.
c:\Documents and Settings\username  -> ftp://ftp.domainname.com/foldername

 Enjoy

Cubert  😎

Scripts to be used at your own descression, no warranty is implied.

VBScript code: View CPU usage for a process name

So you need a VB script to check for a process or set of processes CPU usage? Let’s say I want to see all “svchost.exe” process PID’s and the amount of CPU each process is using? see in line 6 and 7 the name of the process your looking for? Just edit the name of the process and run the script. It will print out the PID and the CPU

So you need a VB script to check for a process or set of processes CPU usage? Let’s say I want to see all “svchost.exe” process PID’s and the amount of CPU each process is using? see in line 6 and 7 the name of the process your looking for? Just edit the name of the process and run the script. It will print out the PID and the CPU usage for each process it finds that matches the Process Name provided.

Then I would copy the code below to a .vbs file and run it in a the CLI.


DIM MyPID(20), objProcess, objItems, objitem
DIM XX, I
XX = -1
set objService = getobject("winmgmts:")
for each Process in objService.InstancesOf("Win32_process")
if Process.Name = "svchost.exe" Then XX = XX + 1
if Process.Name = "svchost.exe" Then MyPID(XX) = Process.processid
Next
For I = 0 To 20
Set objProcess = GetObject("winmgmts:{impersonationLevel=impersonate}//localhost")
Set objItems = objProcess.ExecQuery("Select PercentProcessorTime from Win32_PerfFormattedData_PerfProc_Process where IDProcess=" &MyPID(I)& "")
for each objItem in objItems
Wscript.Echo MyPID(I) & " = " & objItem.PercentProcessorTime

Next
Next