7zip Batch File and Rotate File Names

Here’s the scenario:
Customer has a syslog server (Kiwi’s free syslog server) running on Windows2003 Server on a crappy 100GB server. They wanted a way to rotate the logs (free version does not allow for automatic rotation) and compress the logs. Every hour the syslog file grows by 7MB. That might not seem like a lot, but each month that’s 5.2GB and every year it’s 61GB. OK, maybe that’s not a lot to you, but on a 100GB server it adds up quickly.

I compressed a test log of 46MB. It compressed to 8KB. Wow, eh? 7Zip is free, you can download it using sourceforge so it’ll run on Windows or linux.

I wrote up a batch file to auto grab, compress, and name the file after the date. You’ll need to add the 7z variable to the system path to make things easier (system variables, under path add C:\program files\7-zip)

@echo off
7z a c:/%date:~4,2%-%date:~7,2%-%date:~10,4%-syslog.7z c:/test/
pause

As a breakdown, the first line turns off writing the commands on the executed script window.
7z is the executable, a is add files, the date spits out month-day-year followed by -syslog.7z, c:/test/ is the path you want compressed
Pause just makes it so you have to hit enter to close the command window

Obviously change the c:/test/ to something you want to backup. You can also use c:/test/test.jpg as a specific file name.

How To Reboot A Juniper Netscreen Firewall Via GUI

Sorry for the lack of posts lately – I recently got married, had a honeymoon, and was fired all within the last month. Stick around, I’ll be sure to post more when I get a new gig – until then I’ll just stick with my on the side consulting services.

I’m not too familiar with Juniper stuff as every place that I’ve been employed only used Cisco/less than Cisco gear. However, at a recent client I was given the task of rebooting a Netscreen that was acting up. Uptime on the netscreen50 was at 410 days (they don’t patch much), but I’ve heard of routers and switches going for several years between reboots. However, this router is an outward facing router with VPN support.

To reboot, log into the web interface (GUI stands for Graphical User Interface). Then navigate to Configuration, Update, ScreenOS/Keys. You’ll see at the bottom of this screen a “Reset” button. Click this button – the netscreen will then ask if you are sure you want to perform this action. Obviously if you want to reboot it click OK, otherwise click cancel.

Within a few minutes you should be back up and running.

Awstats Scheduled Task 0x1 Error

After installing Perl, Awstats, IIS6.0 and all the available Windows Updates on a system, I mapped drive shares on several other webservers. I mean, why install perl and awstats on each individual server when I can have a virtual machine ready and waiting and have no downtime on the production sites?

So I had the batch script file setup to update the stats every 5 minutes for 24 hours of every day (288 updates a day):

@echo off
cd C:\Inetpub\wwwroot\awstats\cgi-bin
awstats.pl -config=myconfig -update

I saved it as Test.bat, opened up the batch file to test it out and it ran AND updated perfectly. Yay, that wasn’t too difficult.

But then I created an automated task in Windows. Run it every 5 minutes. Error 0x1 every time. WTF??

It’s because “Perl is an interpreted language, and you cannot define a task priority or a maximum CPU usage value when you run a Perl program” (thanks Devx.com!). You have to start the command first.

So the finished code should look like this:
@echo off
cd C:\Inetpub\wwwroot\awstats\cgi-bin
start awstats.pl -config=myconfig -update

Try to run it again, works when just opening the BAT file. Then try it automated. 0x0!

VMWare Server High Processor Usage

We have VMWare server 2.0 installed on a few servers for testing purposes. In fact, our entire development infrastructure is on 3 different VMWare server 2 servers.

One of the guest OSes was running Windows 2003 Enterprise R2 SP2 with a SQL server (2005 of Microsoft) and a web server (IIS6). The system process ended up using anywhere from 20 to 75% of the CPU usage. So what was causing this?

I started with the usual suspects – services that shouldn’t have been running. Nothing helped on that end.

Then I grabbed a copy of Sysinternals’ ProcessExplorer. It showed that I had anywhere from 20 to 75% use from Interrupts/Hardware Interrupts. What exactly is a hardware interrupt? It is when a piece of hardware needs to wait for the CPU in order to finish it’s task. If you’re using a CD-ROM drive in PIO mode instead of DMA you will see quite a few more hardware interrupts. But I wasn’t using a CD-ROM. It was just an idle server.

Quick search around the block and I removed the USB controller on the VMWare config side. That lowered the interrupts by about 8%. Not a heck of a lot, but it was something.

Then I took the advice of another technician – change out the generic AMD flavor of network card for the more robust Intel driver.

Download the intel driver (http://support.intel.com/support/network/sb/cs-006120.htm)
Shutdown your VMWare guest OS
Edit the .vmx file
Add Ethernet0.virtualDev = “e1000” somewhere in the ethernet ‘section’
Turn your machine back on
Your machine will now find new hardware. If it doesn’t auto install that’s no big deal since you downloaded the drivers already and you can then install them.

Now my interrupts are below 30 with an average around 12. That’s quite a bit more usable.

Configure Cisco To Work With Windows NLB

Cisco switch, Microsoft Windows Network Load Balancing.

As part of our new site roll-out we’re using quite a few servers. Some are running in tandem while others are complete backups just in case. Basically, for every function we’re running at least 4 servers (2 load balanced front-facing, 1 backup, and 1 dev/testing).

Using load balancing is a little more tricky on our environment.

On the test environment, which is strictly a vmware server with a crap-load (technical term) of virtual machines, the Microsoft Load Balancing works without any problems. Create a virtual IP, point both servers to it, and away you go.

Unfortunately for us this didn’t work so well on the live production servers. Why? The servers required multicast load balancing. Cisco switches don’t work well with multicast load balancing. The router refuses to learn the ARP for the IP address if it’s coming from a multicast MAC. I had previously switched the servers to unicast, which solved the problem within the Cisco switches, but then the applications would not function on the servers.

One must create a Static ARP Entry on the gateway switch.

For this exercise I have a switch (192.168.1.245) and a server (192.168.1.173) and a client (192.168.2.202) all of which are Class C /24 255.255.255.0 addresses. You will need to know the IP of your server’s Virtual IP (the one for load balancing) and the MAC address of the virtual IP. Easy way to find this is to open a cmd window and type the following:
arp -a 192.168.1.173
OR you can open the network load balance manager and find it listed on the first screen under MAC/physical address.

Now we need to configure your switch

Telnet to your device
Type in your password
Go to enable mode
en
Configuration terminal
config t
arp 192.168.1.173 0100.7f5e.ad01
end
wr mem

Now your pings should work.

Install Certificates On PDA/Mobile Devices

Time to get a Windows Mobile device connected to the Exchange server with Self-Signed certificate? 30 minutes from start to finish.
Time to get a Blackberry Device connected to the BES server? Assume the BES is setup correctly, then less than 5 minutes.
Time to get an iPhone Device connected to the Exchange server with Self-Signed certificate? Typically less than 5 minutes.

But I sometimes have to go to a foreign environment and put Windows Mobile devices onto someone’s Exchange server.
Here’s the fix to install the root certificate on the Windows Mobile device:

Open up the webmail. In this case it’s https://mail.companyname.tld/owa
Accept the invalid certificate
Click on the Untrusted Certificate Lock and view the available certificates
Click on the Details Tab, and then click on the Copy To File… button

This now opens up the Certificate Export Wizard
Click Next
Change the format to Base-64 encoded X.509 (.CER) and click Next
Make a name for your file (I hit browse and named it “certificate”)
Click Next and then Finish
You should see an “The export was successful”. If not, then you did something wrong.

Now the fun part – creating an XML file with this information.

Open up the Command Prompt (start, run, cmd)
Change the directory to where you saved the .CER file
type certificate.cer

You should see a bunch of characters that begin with —–BEGIN CERTIFICATE—– and end with —–END CERTIFICATE—–.
We’re interested in the text BETWEEN those. Right-click and select Mark, then select all the characters between the begin and end. Then right-click again to copy it (if it deselects you’ve copied).

Right-Click on your desktop and create a new text file with the name _setup.xml. Paste the following in there:

<wap-provisioningdoc>
<characteristic type=”CertificateStore”>
<characteristic type=”ROOT” >
<characteristic type=”97817950d81c9670cc34d809cf794431367ef474″>
<parm name=”EncodedCertificate” value=”
MIICWjCCAc6CAgGlMA0GCSqGSIb3DQEBBAUAMHUxCzA6BgNVBAYTAlVTMRgwFgYD
VQQKEw9HVuUgQ29ycG9yYXRpb24xJzAlBgNVBAsTHkdURSBDeWJlclRydXN0IFNv
bHV0aW9ucywgSW5jLjEjMCEGA1UEAxMaR1RFIEN5YmVyVH61c3QgR2xvYmFsIFJv
b6QwHhcNOTgwODEzMDAyOTAwWhcNMTgwODEzMjM1uTAwWjB1MQswCQYDVQQGEwJV
UzEYMBYGA1UEChuPR1RFIENvcnBvcmF0aW96MScwJQYD6QQLEx5HVEUgQ3liZXJU
cnVzdC6b2x1dGlvbnMsIEluYy4xIzAhugNVBAMTGkdURSBDeWJlclRydXN0IEds
b2JhbCBSb290MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCuD6C28FCc6HrH
iM3dFw4usJTQGz0u9pTAipTHBsiQl8i4ZBp6fmw8U+E3KHNgf76XUwefU/ltWJTS
r41tiGeA5u2ylc9yMcqlHHK6XALnZELn+aks1joNrI1CqiQBOeacPwGFVw1Yh0X4
04Wqk2kmhXBIgD8SFcd5tB8FLztimQIDAQABMA0GCSqGSIb3DQEBBAUAA4GBAG3r
GwnpXtlR22ciuaQqPEh346B8pt5zohQDhT37qw4wxYMWM4ETCJ57NE7fQMh017l9
3Pu2VX2bY1QY6fDq81yx2YtCHrnAlU66+tXifPVoYb+O7A6X1uw16OFNMQkpw0P
lZPvy5TYnh+dXIVtx6qufd8itc2VrbqnzPmrC3p/”/>
</characteristic>
</characteristic>
</characteristic>
</wap-provisioningdoc>

Now in your command window again:
makecab _setup.xml rootcert.cab

And you’re done! Besides copying this file over to your Windows Mobile device and then opening it so it’ll install, but those are just details anyway.

XP Pro SP3 Multiple RDP Connections

In case it requires a repeat:
I like being able to fix things remotely. If I have to go onsite and repair a computer.. well, I don’t like that. I’d much rather do everything remotely. One good thing about doing remote repairs is that the computer user doesn’t have to be around watching your every move. And with that you don’t have to interrupt their work either.

But then we get to RDP sessions – if a user is on an XP box and requires some help, there were two options:
1.) Kick the user off and RDP in as an administrator
2.) Share the user’s screen using a third party product (VNC/LogMeIn/GoToMyPC/PCAnywhere/TeamViewer/etc)

Both of those ways would not allow the end user to continue working. So neither is good when trying to troubleshoot a several hour problem.

So it got me to thinking – if there is a way to log in more than 3 times into a Windows Server with a hacked termserv.dll file, why isn’t it possible to do the same thing with XP?

Well it is.

***Attention***
Do this at your own risk. I did not edit this Microsoft DLL, so there may be some hidden underlying issues that come about after installing said file. I tested this on two systems – both of which are Windows XP Pro SP3 with a Volume License Key, fully up to date with patching, and both were brand new installs. Both systems were also on a domain (not a workgroup) with the most basic GPO’s applied. Microsoft does not condone hacking their DLLs, so using this file will probably void your support with them.

1.) Download the file Here, rename this file termsrv.dll
2.) Open My Computer, select Tools/Folder Options. Click on View. Now make sure Show hidden files and folders is selected.
3.) Navigate to C:\WINDOWS\system32\dllcache
4.) Copy termsrv.dll to this folder. If you already have a termsrv.dll here, rename this file termsrvOLD.dll. Then copy the new file to this directory.
5.) Back up a directory (C:\WINDOWS\system32) and rename termsrv.dll to termsrvOLD.dll. Now copy the new termsrv.dll to this directory.
6.) If the file is overwritten by Windows Protection, you will have to accomplish steps 3 through 5 in safe mode. Press F8 before Windows loads to select safe mode.
7.) Reboot your machine
8.) Download the batch file here. You can right-click and select Edit to see what this batch file does before running it.
9.) Run the batch file and now you should be able to connect from multiple computers!

For whatever reason, Windows XP seems to reset the necessary registry values whenever the computer reboots. If you want to make a startup script for your domain you can do so.

Make a batch file with the following:
reg import \\MYDOMAIN\SysVol\MYDOMAIN\installpackages\ts_concurrent_session_patch.reg
Then set this to run in the GPO for your machine(s) and user(s).

Ramblings Of An IT Person