WishMesh http://wishmesh.com Real men don't make backups Sat, 20 Dec 2014 15:27:36 +0000 en-US hourly 1 http://wordpress.org/?v=4.1 VMware vSphere Client could not connect to vCenter version 5.1.0 http://wishmesh.com/2014/12/vmware-vsphere-client-could-not-connect-to-vcenter-version-5-1-0/ http://wishmesh.com/2014/12/vmware-vsphere-client-could-not-connect-to-vcenter-version-5-1-0/#comments Sat, 20 Dec 2014 15:27:36 +0000 http://wishmesh.com/?p=1299 Continue reading VMware vSphere Client could not connect to vCenter version 5.1.0 ]]> Recently we had an issue, where we were unable to connect to one of our VMware ESXi vCenter’s (v5.1.0) with vSphere Client. Everything worked, all virtual machines were up, except vCenter.

Digging deeper, the log files revealed the following:
2014-09-19T09:01:09.494+03:00 [02156 warning 'Default'] [VdbStatement] SQL execution failed: cleanup_events_tasks_proc
2014-09-19T09:01:09.494+03:00 [02156 warning 'Default'] [VdbStatement] Execution elapsed time: 69482 ms
2014-09-19T09:01:09.494+03:00 [02156 warning 'Default'] [VdbStatement] Diagnostic data from driver is 42000:1:9002:[Microsoft][SQL Server Native Client 10.0][SQL Server]The transaction log for database 'VIM_VCDB' is full. To find out why space in the log cannot be reused, see the log_reuse_wait_desc column in sys.databases
2014-09-19T09:01:09.494+03:00 [02156 warning 'Default'] [VdbStatement] Bind parameters:
2014-09-19T09:01:09.494+03:00 [02156 error 'Default'] [Vdb::IsRecoverableErrorCode] Unable to recover from 42000:9002
2014-09-19T09:01:09.494+03:00 [02156 error 'Default'] [VdbStatement] SQLError was thrown: "ODBC error: (42000) - [Microsoft][SQL Server Native Client 10.0][SQL Server]The transaction log for database 'VIM_VCDB' is full. To find out why space in the log cannot be reused, see the log_reuse_wait_desc column in sys.databases" is returned when executing SQL statement "cleanup_events_tasks_proc"
2014-09-19T09:01:09.494+03:00 [02156 error 'vpxservicesvpxdEventTaskCleanup'] [VpxdEventTaskCleanup] Error during Event/Task Cleanup: "ODBC error: (42000) - [Microsoft][SQL Server Native Client 10.0][SQL Server]The transaction log for database 'VIM_VCDB' is full. To find out why space in the log cannot be reused, see the log_reuse_wait_desc column in sys.databases" is returned when executing SQL statement "cleanup_events_tasks_proc"
2014-09-19T09:01:09.494+03:00 [02156 warning 'VpxProfiler'] VpxUtil_InvokeWithOpId [TotalTime] took 69482 ms

So we need to clean up the Transaction log for the MS SQL server, or clean up some tables… so we found an article from VMware support – KB1025914.

From VMware, to purge the data in the VPX_EVENT table:

1. Connect to Servername\SQL Database and log in with the appropriate credentials.
2. Click databases to expand and select VIM_VCDB > Tables.
3. Right-click the dbo.VPX_PARAMETER table and select Open.

Note: If you are using SQL Server 2008, right-click the dbo.VPX_PARAMETER table and click Edit Top 200 Rows.
4. Modify event.maxAge to 30, and modify the event.maxAgeEnabled value to true.
5. Modify task.maxAge to 30, and modify the task.maxAgeEnabled value to true.

Note: To improve the time of the data cleanup, run the preceding steps in several intervals. To do this, ensure to keep the default value of event.maxAge and task.maxAge and perform step 6 to run the cleanup. Then, reduce the event.maxAge andtask.maxAge value by 60 and run the cleanup. Repeat the steps until the value is reached to 30 for the final cleanup process.
6. Run the built-in stored procedure:
a. Go to VIM_VCDB > Programmability > Stored Procedures.
b. Right-click dbo.cleanup_events_tasks_proc and select Execute Stored Procedure.

This purges the data from the vpx_event, vpx_event_arg, and vpx_task tables based on the date specified for maxAge.
c. When this has successfully completed, close SQL Management Studio and start the VMware Virtual Center Server service.
To ensure that the default Statistics Level is set to 1:

1. Using the vSphere Client, log into vCenter Server as an administrator.
2. Go to Administration > vCenter Server Settings > Statistics.
3. Under Statistics Intervals, ensure the Statistics Level column is set to 1.
4. To change the value, select the Interval Duration, click Edit and select Level 1 from the dropdown

To download SQL Management Studio 2008 R2 follow this Microsoft SQL Server 2008 R2 RTM – Management Studio Express.

Everything went smooth, except, we didn’t know the SQL server name, and SQL Server 2008 R2 didn’t help much. Later we found, that the name is “.\VIM_SQLEXP”, see the screenshot below.

Connect to Server, VIM_SQLEXP SQL Management Studio 2008 R2 installation SQL Management Studio 2008 R2 installation ]]>
http://wishmesh.com/2014/12/vmware-vsphere-client-could-not-connect-to-vcenter-version-5-1-0/feed/ 0
Stopping a DOS batch file http://wishmesh.com/2014/10/stopping-a-dos-batch-file/ http://wishmesh.com/2014/10/stopping-a-dos-batch-file/#comments Thu, 09 Oct 2014 18:48:22 +0000 http://wishmesh.com/?p=1290 Continue reading Stopping a DOS batch file ]]> This article is from our Febooti archive, it was relevant then, and I think that it is still relevant today (a few details changed).
Previous article: First cmd / DOS batch script example.

Usually, OS (Windows, MS-DOS) executes a batch file without stopping. DOS stops processing the batch file while the program runs when the batch file loads a program. As soon as you exit the program, or an automatic termination occurs, OS immediately continues processing the batch file from where it left off. Typically this is what you want, but sometimes you want to give the user time to think, react, and then take action. An example would be giving the user a group of choices that you want them to select from before proceeding.

PAUSE is the command we are looking for. PAUSE stops the batch file until almost any key is pressed. A key that would produce a character on the screen needs to be pressed. Therefore pressing a key like CTRL or ALT or SHIFT will not exit out of the pause state. Earlier we used this command above to see the output on the console. Now we will use this to pause the execution of the batch script.

Though the PAUSE command is really quite helpful, it lacks in power. The keystroke that you press is not capable of being used as a menu selection nor can it be saved in the program in any other way. Below is an example to illustrate how the PAUSE command works along with the ways of terminating a program with the keyboard.

:: PAUSE-IT.bat
:: Example of the PAUSE command
:: and the ways to exit out of a program.
@ECHO OFF
ECHO The next command is a PAUSE
ECHO Do NOT press Ctrl+C or Ctrl+Break
PAUSE
ECHO Press Ctrl+C or Ctrl+Break on your keyboard
PAUSE

The first line is a comment with the name of the file. The second and third line comments are description of the program (batch file). The fourth line turns command-echoing off. Line 5 and 6 gives the first message about which keys you can press for the first example. Line 7 is the PAUSE command that stops the batch file until a key is pressed. The next line (8) displays the message about aborting the program using the keyboard controls. The last line (9) is the final PAUSE that finishes the program.

You can terminate this script in many ways, however, if you follow the ECHO instructions, then you will have the following output:

Batch file: press CTRL+Break CTRL+C
Batch file: press CTRL+Break CTRL+C

As you see in the screenshot, after pressing Ctrl+Break or Ctrl+C, the command interpreter asks you to “Terminate batch job (Y/N)?”. By pressing Y followed by the Enter, the batch file terminates.

This article is from our Febooti archive, it was relevant then, and I think that it is still relevant today (a few details changed).

]]>
http://wishmesh.com/2014/10/stopping-a-dos-batch-file/feed/ 0
First cmd / DOS batch script example http://wishmesh.com/2014/10/first-cmd-dos-batch-script-example/ http://wishmesh.com/2014/10/first-cmd-dos-batch-script-example/#comments Mon, 06 Oct 2014 16:12:43 +0000 http://wishmesh.com/?p=1263 Continue reading First cmd / DOS batch script example ]]> console-screen
Photo: freeimages.com

This article is from our Febooti archive, it was relevant then, and I think that it is still relevant today (a few details changed).

Previous article: What is a batch script?
Next article: Stopping a DOS batch file

Now we are familiar with the command prompt. Batch scripts are one or more DOS commands that are executed sequentially, and the script is written using a text editor. This does not mean you can use Microsoft Word or Google Docs or any other of those fancy programs you might use to type up a report. Those types of programs are called word processors, not text editors. Besides the obvious that these programs allow you to change colors and import graphics, these programs add extra formatting that you don’t see.

A great example of a text editor is Notepad. Notepad comes bundled up with Microsoft operating systems (or better choice is open source editor – Notepad++ which supports syntax highlighting). To access Notepad simply click the Start button followed by the Programs option. Next, click on Accessories which is usually at the top of the column. The next pop-up column should contain the Notepad program option. Or on newer Windows, hit Start, and type Notepad.

Search - Notepad on Windows 8.1
Search – Notepad on Windows 8.1

A helpful hint is to make a shortcut to the Notepad in your desktop or Taskbar by right-clicking on the Notepad option (or Pin to Taskbar on the newer Windows). Subsequently select Send To followed by selecting Desktop (Create a Shortcut). This allows quick access in the future by placing an icon on your desktop. A shortcut can also be made using batch.

At this point I highly recommend to download the Notepad++, or change Folder options in the Windows, to see file extensions, so you can easily change .txt file extension to the .bat for the batch files.

Notepad++ editing .bet file under Windows 8.1
Notepad++ editing .bet file under Windows 8.1

Now that we have the Notepad open we can begin scripting. Let’s begin by printing the words Hello World to the screen. Type the following into Notepad screen. Then save our new text file as helloworld.bat or my-first-batch-script.bat, or anything you like.

@Echo off
Rem helloworld.bat

:: Next line prints Hello World to the screen
Echo Hello World

Pause

Now let’s explain what each line does.

The computer has a habit of taking everything you type and storing it verbatim. This can be annoying and troublesome at first however you will soon realize that predictability is nice. Anyway, this means that all commands will be seen by the end-user. This makes for a very ugly and bothersome execution.

To circumvent this we will type @ECHO OFF at the first line. ECHO OFF makes sure that command echoing is turned off. This fixes our previous problem. However, it creates a new one. ECHO OFF is a command thus it will also be seen. That is where the use the @ (at) sign comes in. This stops the echo of the ECHO OFF command. If you were to leave the @ sign out you would see ECHO OFF above your Hello World message as part of your output.

The majority of the batch scripts have this snippet of code at the beginning. You can also turn echoing back on if you like by using the command ECHO ON. If you type ECHO by itself the status of ECHO will be displayed. The ECHO OFF command only turns off command echoing. The output from the DOS commands will still be seen.

When you copy a file in a batch file, you will still see the 1 File(s) copied message. If you use a batch file to start a GUI program, that program will indeed appear on the screen (For example, Calculator, Notepad, MS Word, MS Excel). ECHO OFF turns off batch file commands seen in the console while that specific batch file is running.

Here is a screenshot of your first batch file’s output:

Hello World.bat output
Hello World.bat output

The ECHO command is great for communicating with the user. Messages and questions can be easily delivered to the end-user. This is great for giving the user a list of choices and wanting feedback before a particular action is performed. Try experimenting with different formats for delivering messages to the user. For example, centering the text using spaces (this works because most consoles uses fixed-width fonts by default). Or adding hyphens and exclamation marks for borders:

@echo off

echo ---------------------------------
echo !     Your hello message...     !
echo ---------------------------------

Using fixed width fonts in the console
Using fixed width fonts in the console

You can create a line break, a blank line, by typing ECHO. but notice the period mark after the echo command. The ECHO and period combination is what creates the line break. Example:

@ECHO OFF
REM helloworld.bat
:: Prints 'Hello World' to the screen...
:: with a line break in between the words.
ECHO Hello
ECHO.
ECHO World
PAUSE

Lines 2, 3 and 4 in this batch file example are comments or remark statements. When writing batch scripts you will want to place two comments at the top of the file. Coding standard style should be in place, which improves the quality of software which results in fewer bugs which is easier to maintain and use. The first line should contain the name of the file and the second remark statement should include a brief statement about the following program. This helps yourself when you start writing many batch files and it also helps someone else (for example, your colleagues) read your script that might not be as familiar with it as you. This could perhaps be the case of having a friend debug your file.

The first remark statement has the REM signifying a remark. Such remarks are used in every programming language to add comments to your code. Since your first batch scripts will be smaller programs, we won’t need very many remark statements, though it is a good idea to get in the habit of documenting your scripts well. Remark statements are ignored by DOS. Notice the :: (two colons) in the next remark statement. This is another way of commenting your batch scripts. The double colon approach is a better way of commenting your code because the command prompt will entirely ignore this line making your program run faster.

Yes, REM is ignored however the command prompt takes a more detailed approach at reading the comment and it takes a longer amount of time to execute (not relevant on modern PC). The double colon makes for a quicker program. This gives you advantages when you start building more complicated programs and you start adding more of them. For the preceding reasons we will not use the REM command rather we will use the double colons when commenting our code.

Another characteristic of batch scripting is that line breaks (spaces between lines) in your batch file are ignored. Here they are used merely for readability. Notice the two above / previous examples each have a different line break scheme. The first implements a double space layout for better readability. The second is more compact.

ECHO is similar to the PRINT command in other programming languages. ECHO is used for displaying a string of text to the screen.

Finally, we have the PAUSE command. Your program will run just fine without this. However, you will not be able to see your output; the text Hello World in this example. If you include the PAUSE command you will see the text string Press any key to continue… If you do not include this command the command prompt may appear, then flash away quickly (depends on how you run batch scripts). Run the program without this and note the difference (first run by double clicking mouse, second – from the CMD.exe console).

Note that batch commands are usually not case sensitive. All caps are shown in this article to help you identify the batch code. When an instance arises where case-sensitivity will matter it will be explained.

This article is from our Febooti archive, it was relevant then, and I think that it is still relevant today (a few details changed).

Edit Oct 9, 2014: Updated formatting and added link to the next article.

]]>
http://wishmesh.com/2014/10/first-cmd-dos-batch-script-example/feed/ 0