Batch file using WGET to download from FTP

One batch file that will allow you to download certain dated files while excluding some folders using WGET.

I need to download files from an FTP site:

and these are the conditions:

1) Download all files except the ones with extentions .R, .A, .C, .E, .P, .A

2) Download only files starting with 0066, 7019, 0124, 2039, 5002, 5003, 0064, 5244, and 0660

3) Exclude folders archive and batch

4) Download only yesterday files - the files on the FTP have MMDD at the end.

This is the batch file:

FOR /f “tokens=1-3 delims=/ ” %%a in (’DATE/T’) do set date=%%b%%a
FOR /f “tokens=1-3 delims=/ ” %%a in (’DATE/T’) do set day=%%a
FOR /f “tokens=1-3 delims=/ ” %%a in (’DATE/T’) do set month=%%b

REM ———————————————————
REM Test by setting the next two variable to a day and month
REM SET day=01
REM SET month=04
REM ———————————————————

SET /a iDay=%day:~0,1%
SET /a iMonth=%month:~0,1%

ECHO iDay IS: %iDay%
ECHO iMonth IS: %iMonth%

if %iDay%==0 (SET /a iDay=%day:~1,2%) else (SET /a iDay=%day%)
if %iMonth%==0 (SET /a iMonth=%month:~1,2%) else (SET /a iMonth=%month%)

ECHO iDay1 IS: %iDay%
ECHO iMonth1 IS: %iMonth%

REM —————————————————–
REM If first day of month then rollback to previous month
REM —————————————————–

if %iDay% EQU 1 GOTO :CheckMonth
if %iDay% NEQ 1 GOTO :DecrementDay

:CheckMonth
if %iMonth% NEQ 1 GOTO :DecrementMonth
if %iMonth% EQU 1 SET /a iMonth=12
GOTO :LastDayOfMonth

:DecrementMonth
SET /a iMonth=%iMonth%-1

:LastDayOfMonth

REM ——————————————————-
REM Now figure out the correct day  number for the new month
REM ——————————————————-
if %iMonth% EQU 1 SET /a iDay=31
if %iMonth% EQU 2 SET /a iDay=28
if %iMonth% EQU 3 SET /a iDay=31
if %iMonth% EQU 4 SET /a iDay=30
if %iMonth% EQU 5 SET /a iDay=31
if %iMonth% EQU 6 SET /a iDay=30
if %iMonth% EQU 7 SET /a iDay=31
if %iMonth% EQU 8 SET /a iDay=31
if %iMonth% EQU 9 SET /a iDay=30
if %iMonth% EQU 10 SET /a iDay=31
if %iMonth% EQU 11 SET /a iDay=30
if %iMonth% EQU 12 SET /a iDay=31
GOTO :ScriptEnd
)

:DecrementDay
SET /a iDay=%iDay%-1

:ScriptEnd

if %iDay% LSS 10 (SET day=0%iDay%) else (SET day=%iDay%)
if %iMonth% LSS 10 (SET month=0%iMonth%) else (SET month=%iMonth%)

MOVE D:\Test\logs\ftpsync.log D:\Test\logs\%month%%day%_ftpsync.log

wget –passive-ftp -R “A”,”C”,”E”,”P” -A “0066*%month%%day%*”,

“7019*%month%%day%*”,”0124*%month%%day%*”,

“2039*%month%%day%*”,”5002*%month%%day%*”,”5003*%month%%day%”,

“0664*%month%%day%”,”5244*%month%%day%*”,”0660*%month%%day%*”

-X “archive”,”batch” -m -nH ftp://testingsite.com -P d:\Test\ -a D:\Test\logs\ftpsync.log

Add to Bookmark: bookmark bookmark bookmark bookmark bookmark

Monitor Juniper SSG 550 using Zabbix

Enable SNMP on the Juniper firewall

  • Configuration=>Report Settings=>SNMP
  • Create a new SNMP Community. Hosts is the Zabbix server and select the interface you want to monitor
  • At the interface level, make sure SNMP is ticked.

 

On the ZABBIX server

  • Make sure SNMP is installed
  • Find out the SNMP community string of the item you want to monitor using snmpwalk command => snmpwalk -v 1 x.x.x.x -c CommunityName>/tmp/snmpcommand. -v is the version of snmp, and -c is the community name you’ve specified in Juniper. And this command will write to an output file in /tmp directory.
  • Find the OID of the SNMP community string using SNMPGET command. snmpget -v 1 -On x.x.x.x CommunityString -c CommunityName
  • Go to http://net-snmp.sourceforge.net/docs/mibs/IF-MIB.txt for Community String explanation.
  • Follow the Zabbix Manual 1.6 for the rest of the configuration at the SNMP Agent section
  • Just note that in the Configuration of Items, you need these: Units=Bit, Use Multiplier with value 8, and choose Delta(speed per second) for Store Value

 

 

Add to Bookmark: bookmark bookmark bookmark bookmark bookmark

Moving Zabbix MySQL DB to new hardware

This document assumes that linux (Ubuntu) has already been installed on the new MySQL server.

Login to new MySQL server - IP Address with account Username
Install MySQL: enter the following command line.
apt-get install mysql-server

Assign password to root account and take note of it.
Install ssh: enter the following command line.
apt-get install ssh-server

 

Login to old MySQL server - IP Address with account Username

Dump Zabbix database with following command line.

mysqldump -u root -p zabbix > /tmp/zabbix_db_dump
Enter the password when prompted.

When complete copy the dump file across to the new MySQL server using scp, the command line is:

Scp /tmp/zabbix_db_dump Username@IP Address:/tmp

 

Enter the password when prompted; the file will be copied to /tmp
Login to new MySQL server - IP Address

Create the zabbix database. Enter the following from the command line.

mysql -u root -p

Enter the password when prompted.

In MySQL issue the following command

Create database zabbix;

Exit MySQL session. You will then import the tables and data with the following command line.

mysql -u root -p zabbix < /tmp/zabbix_db_dump

Enter the password when prompted.

Now you will create the zabbix account that can only be used from the Zabbix Server (IP Address). Enter the following from the command line.

mysql -u root -p zabbix

Enter the password when prompted.

From the MySQL prompt run the following commands.

create user ‘zabbix’@'IP Address’ identified by ‘Password’;

use zabbix;

grant all privileges on zabbix.* to ‘zabbix’@'IP Address’;

exit;

 

In order to connect remote, the zabbix server must be configured to allow remote connections. Edit the /etc/mysql/my.cnf file. Search for bind-address and comment out this line. Save and exit.

Now, restart mysql daemon. Enter the following on the command line.

sudo /etc/init.d/mysql restart.

Login to Zabbix Server

Test the connection to the new MySQL server. Enter the following on the command line:

mysql -u zabbix -p -h IP Address

Enter the password when prompted. You should get a MySQL session.

The next step is to configure the Zabbix Server to point to and use the new zabbix database on the new MySQL server. First, stop Zabbix Agent and Server. Enter the following at the command line.

sudo /etc/init.d/zabbix-agent stop

sudo /etc/init.d/zabbix-server stop

Edit the following file: /etc/zabbix/zabbix_server.conf.Search for DBHost. Update the line to:

DBHost=IP Address

Save and quit. Restart bot the Agent and Server. Issue the following from the command line.

sudo /etc/init.d/zabbix-server start

sudo /etc/init.d/zabbix-agent start

 

The web interface for zabbix now has to be configured to point to the new MySQL database and Server. Edit the following file: /home/zabbix/public_html/zabbix.conf.php. Search for $DB["SERVER"] and change the ip address to IP Address.

Login to old MySQL server - IP Address with account Username

All that remains is to turn off the old MySQL server. Issue the following from the command line.

sudo /etc/init.d/mysql stop

Add to Bookmark: bookmark bookmark bookmark bookmark bookmark

Booting CD/DVD from ESXi 3.5 on Dell PowerEdge 2950

We tried to create/install a new virtual machine (Ubuntu system) in our new ESXi 3.5 server and we got confused about setting up the cd boot. There are two ways to connect a CD/DVD to an ESXi 3.5 VMware machine.

  1. Use Client Device - which means use the CD/DVD rom on your local PC
  2. Use Host Device - which means use the ESXi 3.5 server local CD/DVD rom

To achieve number 1, insert the Ubuntu CD onto your local dvd rom. Create a blank virtual machine, and edit the settings. Add a CD/DVD drive and choose the option “Client Device”. Also go to Options tab and in the “Boot Options” make sure you delay the boot. In my case I entered 10,000 milliseconds. Start the new VM, and it will boot with the Ubuntu install cd

To achieve number 2, you need to make sure the server CD/DVD rom drive is compatible with ESXi 3.5. In my case, I have a Dell PowerEdge 2950 and ESXi 3.5 doesn’t detect the dvd rom.

Add to Bookmark: bookmark bookmark bookmark bookmark bookmark

Monitoring VMWare ESXi 3.5 through DRAC

We have a Dell PowerEdge 2950 running VMWare ESXi 3.5. To monitor the Dell hardware, we are using the DRAC feature. Make sure you have a DRAC management card installed, and set it up with an IP address. Access the management page with any browser, and from there you can setup email notifications whenever there’s an alert raised on the system.

Add to Bookmark: bookmark bookmark bookmark bookmark bookmark

Managing VMWare ESXi 3.5

Four ways to manage VMWare ESXi 3.5. 

  • VI Client - Provides you with a GUI to manage your virtual machines. This can be downloaded from VMware website or if you go to your ESXi server Welcome Page, you can get it there too.

  

 

  • SSH - Before you can SSH onto the ESXi machine, you need to enable SSH first. Follow this link here.

 

  • VMware Infrastructutre Remote Command Line - This is similar to the VI Client but is a command line version instead of GUI. Download from here.

 

  • VMware Infrastructure Tookit - Allows VMware administrators to automate tasks such as backup. Download from here.

Add to Bookmark: bookmark bookmark bookmark bookmark bookmark

Moving Exchange 2007 to new hardware and keeping the same name

Old server is an IBM with an EXP400 external storage attached

New server is a Dell PowerEdge 2950

I’m using setup.com /M:RecoverServer /DoNotStartTransport

Steps:

  1. Make sure the new server has the same drive configurations. If you had C:\OS, D:\LOGS, and E:\Database on the old server, make sure you have the same on the new one.
  2. Install the same OS. In my case I had a Win 2003 STD x64 R2.
  3. Install the same service packs and patches on the new server
  4. Install all the required Windows Components for Exchange such .Net 2, powershell, iis, etc
  5. At this stage the new server must not be on the domain. And it must have a unique name and IP
  6. Get a latest backup of the exchange database
  7. Get a backup of your Client Access Server (IIS settings) - refer to Microsoft Technet
  8. Make sure you document your existing connectors configurations. Take screenshots.
  9. Shutdown existing server
  10. Reset the Exchange Computer account in AD
  11. Rename the new server to the same name as the old one
  12. Change the IP address to reflect the old one
  13. Add it to the domain
  14. Run Exchange setup with  setup.com /M:RecoverServer /DoNotStartTransport (the DoNotStartTransport option will stop the Exchange Transport Service after the setup)
  15. Install exchange service packs and patches (only if you had those on the old one)
  16. Restore database and IIS settings.
  17. Mount database
  18. Check all the Connectors configurations
  19. Start the Exchange Transport Service
  20. Test emails internally and externally

 

Sources:

http://technet.microsoft.com/en-us/library/bb332343.aspx

http://www.msexchange.org/tutorials/Moving-Exchange-Server-2007-database-Mailbox-servers.html

Add to Bookmark: bookmark bookmark bookmark bookmark bookmark

Exchange 2007 Offline Defrag - Beware of the tmp file

Last weekend, we had to do an offline defrag of our exchange database. According to the event log and online defrag results, we can free up 21GB of space from the EDB files. The EDB file was originally 60GB in size.

So, we followed Microsoft Technet instructions on the offline defrag which are pretty straight forward.

There is one thing however that you need to be very careful about. Make sure you run the eseutil command from a drive that has enough space. We ran the offline defrag from the C:\ drive, and eventually if failed due to C:\ drive running out of space. We had 75MB of space left, and had to delete the tmp file from the Exchange bin folder.

Add to Bookmark: bookmark bookmark bookmark bookmark bookmark

Useful PowerShell Scripts

Windows PowerShell is a new scripting language from Microsoft.  Below are some useful PS scripts I’ve written for Zabbix. We are using Zabbix Sender and Zabbix Trapper to check for file age, file size and string in files.

 

To check File Age in Minutes

# FileAging.ps1
# This script developed and tested with PowerShell RTM
 

Param($filepath)
if ($filepath -isnot [string]) {
Write-Host “ERROR: You must specify a file path!” `
-foregroundcolor “RED” -backgroundcolor “Black”;`
return
}
#verify $file exists as a path
if (Test-Path $filepath) {

    $now=Get-Date
    #only get file objects, not folder objects
    $file=Get-ChildItem -path $filepath

    #enumerate files and get information

    $ageminutes=($now.subtract(($file.LastWriteTime))).minutes
    $agehours=($now.subtract(($file.LastWriteTime))).hours
    $agedays=($now.subtract(($file.LastWriteTime))).days

    $ageminutes = $ageminutes + ($agehours * 60) + ($agedays * 24 * 60)

    $SendZabbix = $ageminutes
  }
  else {
  Write-Host “Failed to find” $filepath.ToUpper() -foregroundcolor “Red” `
  -backgroundcolor “Black”
  $SendZabbix = 1000000
  }

 

Check File Size in KB

# FileSize.ps1
# This script developed and tested with PowerShell RTM
 

Param($filepath)
if ($filepath -isnot [string]) {
Write-Host “ERROR: You must specify a file path!” `
-foregroundcolor “RED” -backgroundcolor “Black”;`
return
}
#verify $file exists as a path
if (Test-Path $filepath) {

    $file=Get-ChildItem -path $filepath

    #enumerate files and get information
    $filesize=($file.Length)
   
    #get file size in bytes
    $filesizekb = “{0:N0}” -f ($filesize / 1kb)    

    #get file size in kb
    $SendZabbix = $filesizekb
 

  }
  else {
  Write-Host “Failed to find” $filepath.ToUpper() -foregroundcolor “Red” `
  -backgroundcolor “Black”
  $SendZabbix = 1000000
  }

 

String Search in File

# PowerShell cmdlet to find a string pattern in a file.
# Parameter 1 = the file to be searched    (mandatory)
# Parameter 2 = the string to find in the file   (mandatory)
# Parameter 3 = the length of the string   (optional)
# Parameter 4 = the delimiter between strings   (optional)

# parameters 3 and 4 are used in conjuction and are used to find a string
# of a certain length that is clearly seperated from other text in the file
# with a delimiter of some sort.

# When parameters 3 and 4 are not specified then finding he string is any line
# is sufficent to report found.
Param($Location, $SearchStr, $StrLen, $SplitToken)

If ($Location -eq $null -or $SearchStr -eq $null)
{
 write-host “Syntax: test.ps1 <File Path> <Search String> | <Length of String> <Delimiter>”
 write-host “”
 write-host “parameters 3 and 4 are optional but must be used in conjunction.”
 write-host “When not used the routine does a simple search for the string in every line.”
 write-host “When parameters 3 and 4 are specified the routine searches for the string of a certain length”
 Write-host “and that the string is delimited from the rest of line in someway.”

 write-host 0
}

$SendZabbix = 0
If ($SplitToken -eq $null -and $StrLen -eq $null)
{
 $str = select-string -pattern $SearchStr -path $Location

 If ($str -ne $null)
 { 
  $SendZabbix = 1
 }

}
Else
{
 foreach ( $xx in (select-string -pattern $SearchStr -path $Location | foreach-object {$_.line} | foreach-object  {$_.split($SplitToken)}) )
 {
  if ( ($xx.length -eq $StrLen) -and ($xx -eq $SearchStr) )
  {
   $SendZabbix = 1
  }
 }
}

Add to Bookmark: bookmark bookmark bookmark bookmark bookmark

ESXi 3.5 on Dell Optiplex GX620

I am currently setting up a brand new test environment, and I will be writing down the whole project here.

  • Hardware - Using Dell Optiplex GX620. This is one of the Dell workstations that will support ESXi 3.5. I tried to get ESXi working on Dell Optiplex 745, without any luck. It has a 3 GHZ processor, 2GB of RAM, and an 80GB drive.
  • Installing ESXi 3.5 build 123629 - I installed the VMware server successfully, and I managed to connect to the VMware server infrastructure using the VI client version 2.5.0 build 119801. Note that you need to download and install the latest build of ESXi 3.5 because the previous build 103908 has critical issues with it, and you will not be able to start the VMs.
  • Using VMware Converter 3.0.3 build 89816 - I am converting physical machines into virtual machines (workstation 6.x) and saving the images onto an external USB
  • Importing VMX files into ESXi 3.5 - I used VMware Converter to convert Virtual Machine 6(.vmx) into VMware Virtual Infrastructure Machine, and this error happened:

This was really bad news, because I had spent hours converting my physical machines into virtual machines (.vmx) and I was not able to import them into my ESXi 3.5 server.

I then converted the VMX file into a Virtual Appliance using VMware Converter, and was hoping to import the Virtual Appliance into my ESXi server. And this the error I received:

 

Luckily, there is a workaround. After converting the .VMX file into a Virtual Appliance (.OVF), you need to edit the OVF file. Do a search for this string “<vssd:VirtualSystemType>vmx-06″ and changed it to 04. You will now be able to import the Virtual Appliance into the ESXi server.

13/02/09

I fixed the issue.

There is NO limitations on the VMware Converter 3.0.3 build 89816 . You can use it to convert Workstation 5.x and 6.x to ESXi 3.5.

It seemed to be a space issue.

But this is really strange because:

1) The physical machine I converted has 75GB HDD

2) After converting to Workstation 6 (VMX), I got a a .vmdk file of 16GB

3) I was trying to convert this to a datastore of 111GB in my ESXi 3.5

4) I extended the datastore from 111gb to 223gb, and ran the converstion again with success.

 

Can anyone can explain this behaviour?

 

 

 

Add to Bookmark: bookmark bookmark bookmark bookmark bookmark