The usual IT babble
Posts tagged Coding
VBscript & Active Directory and printers ?
Oct 13th
Well, since our current solution for mapping printers is an ugly batch file, which needs to be put into Startup, I today poked at doing it in VBscript (I know, but it’s less ugly than the batch script, trust me).
As some of you know, printers are only applicable to users (as in you can’t put a startup script onto an OU, which is going to map the printers). So as we store users and the computes in different OU’s in our Active Directory (we do have about 15.000 students), I can’t apply the printer.vbs to the users OU directly either, unless I implement some intelligence into the script itself.
And that’s basically what I did. Since different pools at the university have different DNS suffixes (like pools.rz.barfoo.org, that our or pools.fmz.barfoo.org) and we only want them students to have our printers when they logon at our pool, I just made the script to get the DNS DomainName of the current active interface and compare it against a given pattern.
' The problem is, if you apply something like this the users get the printers regardless whether they
' are at our location or a different one. So we either need to look up the current AD object (this computer),
' or just compare our current DNS suffix/DomainName against a known pattern.
' Now, lets get the DomainName from the WMI-Interface
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colNicConfigs = objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
For Each objNicConfig In colNicConfigs
strDNSDomain = objNicConfig.DNSDomain
Next
' Apply some regexp foo, to see if we're at the computing center or not!
Dim regexp
Set regexp = New RegExp
regexp.Pattern = "pools.rz.barfoo.org"
if regexp.Test(strDNSDomain) Then
'If so, then lets just connect the printers we need!
Set WshNetwork = CreateObject("WScript.Network")
WshNetwork.AddWindowsPrinterConnection "\\nas.barfoo.org\Kyocera Mita FS-9100DN KX"
' Set the default printer to something useful
WshNetwork.SetDefaultPrinter "\\nas.barfoo.org\Kyocera Mita FS-9100DN KX"
End If
Nagios & plugins
Oct 6th
Since we started utilizing Nagios‘s power two months ago, I finally came up with a C-based ram-plugin for nagios. The biggest problem I had with the python and perl based plugins, that some distributions (yes, SLES and Debian) don’t install either Python or Perl.
Since I wanted a manageable setup (as in unified code base across all distributions), I wanted it to work without installing too much. So I took the swap plugin and basically removed what wasn’t necessary and voila!
Here we go, yay ME!
Only thing I need to finish sometime soon, is getting the NSClient++ work on my Windows boxen (which I do have quite a few, the domain controllers, nas-cluster, …)
TYPO3 and MySQL replication
Sep 8th
Apparently the TYPO3 version we are using, doesn’t play too nice with the MySQL Master< ->Master replication.
Sometimes, something like this is going to happen:
070826 0:44:32 [ERROR] Slave: Error 'Duplicate entry '75-222419149' for key 1' on query. Default database: 't3nb'. Query: 'INSERT INTO cache_pagesection
070826 0:44:32 [ERROR] Error running query, slave SQL thread aborted. Fix the problem, and restart the slave SQL thread with "SLAVE START". We stopped at log 'dbc-mysql1.000192' position 611861372
Well, as you can see from the last line in the log, the Slave-SQL thread found a duplicate entry and thought it is smart to just turn off the thread instead of disregarding the just made entry. So from now on, both databases drift since there ain’t no replication anymore until someone kick starts the replication again (someone being me).
Anyway, I think I finally traced the fucker down, supposedly one of the problematic cases is located in t3lib/class.t3lib_tstemplate.php on line 362.
$GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_pagesection', 'page_id='.intval($GLOBALS['TSFE']->id).' AND mpvar_hash='.t3lib_div::md5int($GLOBALS['TSFE']->MP));
$GLOBALS['TYPO3_DB']->exec_INSERTquery('cache_pagesection', $insertFields);
Basically what TYPO3 is doing is a DELETE and an INSERT right afterwards. But apparently, it doesn’t check whether the DELETE even succeeded. I hacked it for now, simply adding this:
- $GLOBALS['TYPO3_DB']->exec_INSERTquery('cache_pagesection', $insertFields);
+ // Only insert a new cache entry with the same value, if the DELETE succeeded
+ if ($GLOBALS['TYPO3_DB']->sql_affected_rows() == 1)
+ $GLOBALS['TYPO3_DB']->exec_INSERTquery('cache_pagesection', $insertFields);
+
Sadly, this looks more and more like a race-condition between the two boxes (as in the replication / UPDATE being too slow), when users visit a edited site, that hasn’t had it’s cache regenerated yet. Problem is, it ain’t just this single spot, but also the search indexing, image cache and the whole page cache. For now we switched the cluster to active/passive load balancing, till we have a chance to see if a newer TYPO3 fixes those issues.
Handling files/directories with spaces in `for’-loops
Jul 7th
So I have one or the other file, that needs to be extracted to a directory. And why not name it as the archive itself .. Only problem with it is the handling of variables with bash …
Try it yourself, stuff some directories with a space in inside a variables, and use something like this:
epimetheus tmp [0] $ mkdir files
epimetheus tmp [0] $ touch files/"I hate directories.archive" files/"Me luuv you looong time.archive"
epimetheus tmp [0] $ for i in $( /bin/ls --color=none files/ ); do mkdir "${i/.archive/}"; done
And now take a look at the output of that ..
epimetheus tmp [0] $ ls
I/ Me/ directories/ files/ hate/ looong/ luuv/ time/ you/
Means, the `mkdir‘ created a directory for every entry in the `ls‘ output that was separated by a space char … and I’ve no frickin clue on how to get that thing right …
Update:
Thanks to Roy I know how one handles such things …
It’s rather simple *g*
epimetheus tmp [0] $ for i in files/*; do mkdir "$( basename "${i/.archive/}" )"; done
That should give you the desired effect