Batch Copy Logs From Server At Multiple Intervals Using Task Scheduler

I came across a situation where a vendor wanted logs files from a server at around 2am in the morning to troubleshoot why an application wasn’t sending a specific email at that time. Problem was, I wasn’t planning on being up at that early in the morning to grab log files and I didn’t know exactly what time it was supposed to send it. The time was usually around 1:30am but sometimes, when it worked, I’ve seen it sent at 4:30am.

So the plan was to come up with a simple batch file to handle the copying of the logs at every hour between 11PM and 5AM to my local Win 7 desktop,

This required a few things:

  1. A batch file that would a) make a directory based on the current time b) copy the files into that directory
  2. A task to run the batch file, triggered at every hour between 11pm and 5am.
  3. Access to the server where the logs are kept

 

Batch File

My batch file consisted of  the following:

@echo off
SET datestmp=%date:~-4,4%%date:~-10,2%%date:~-7,2%
SET HOUR= %time:~-11,2%
CALL :TRIM %HOUR%
SET timestmp=%HOUR%_%time:~-8,2%
MKDIR logs\servername\%datestmp%_%timestmp%
@echo on
COPY \\servername\logs\email.log  logs\servername\%datestmp%_%timestmp%\ @echo off
GOTO EOF
:TRIM
SET HOUR=%*
:EOF

 

The above batch file first gets the date and time, formats it, and creates a directory with the date/time as part of the directory name. So if the date and time was 6/09/15 and the time was 2am, the directory would be called “20150609_2_00”

Then it takes the email.log file from the \\servername\logs\ folder and copies it to a local folder on my machine called logs\servername\20150609_2_00\, which would be relative to where the batch file is run from.

I named the above batch file copylogs.bat and saved it on my local desktop under the C:\temp folder.

I ran the batch file to make sure it works and instead it failed! The reason being, the batch file ran under my desktop login account. I have a separate admin login for the server. So I mapped to the server using my admin login first. With that connection being made, I reran the batch file, and sure enough, it worked.

Next up was creating the tasks to run the batch at certain intervals…

Task Scheduler

1. Start by Creating a Basic Task:

basic task

2. Give the task a name:

task name

3. Set your trigger. In my case I’m setting to “One time” and will give it a specific time to start (probably about 20 minutes into the future so that I can test to see if it will run properly). Later, I will schedule it to run at particular times throughout the night.

trigger

4. Set your action. In My case I’m starting a program (my batch file):

action

5. Here’s where things start to get tricky.

Since it’s a batch file, the Program/script I’m running is cmd (command prompt). The Additional arguments will be:

/k start “” “c:\temp\copylogs.bat”

And it’s starting in c:\temp (no quotes).

start

6. After saving the task, one last thing I had to do was go back, edit it, and Change User or Group, so that it ran under my server admin account, and Run whether I was logged in or not, saving my password.

final

After I finished, and tested it successfully, I went back and edited the task, adding more Triggers:

more triggers

That’s it! Hopefully someone else will find this useful.

 

 

Internet Explorer 8 Crashes on Manage Add-Ons

Problem: In IE8, when you click to Tools –> Manage Add-Ons, Internet Explorer crashes with a Data Execution Prevention error.

Symptoms: Application Event Logs show Event ID 1000 – Faulting Application iexplore.exe

I tried reinstalling IE8, but that did not help

Solution: For me, the problem was due to a faulty ActiveX control or Java applet. Go to C:\WINDOWS\Downloaded Program Files and check the status of the controls There, I found one add-on that had a status of “Damaged”. Some were also “Unknown”. Others were “Installed”. You can right-click on the add-on and select “Remove”. I actually removed them all, then reinstalled my Java.

Internet Explorer 8 – Does Not Remember Password

Problem: Internet Explorer 8 won’t remember the user’s password information for a website

Symptoms:

User starts IE8, types in “salesforce” in the address bar, which automatically brings him to to Salesforce.com. He clicks on the Login link, enters his Username and Password, checks off the box that says “Remember User Name”, and goes about his work. Afterwards, he closes out IE8 and then reopens it later on. He proceeds to Salesforce.com again, but it takes him to the login page and prompts for the password (User Name field is already populated). It should remember his password and log him in automatically.

Solution:

I added salesforce.com to the list of websites to be always allowed to use cookies (in the Per Site Privacy Actions in the Privacy tab of Internet Options). The change did not work. Next, I tried deleting all browsing history and made sure the “Preserve Favorites website data” was checked off (Press the Delete button under Internet Options –> General Tab –> Browsing history) and the “Delete browsing history on exit” option was NOT checked off . This too, did not work.

What did work was deleting all the salesforce.com bookmarks from the user’s Favorites!

Simply Security – EU proposes data protection overhaul; criticism ensues

The European Commission this week revealed a proposed overhaul to decades-old data protection rules in an effort to improve online privacy and Internet security across the European Union (EU) and beyond. However, even before the effects of the proposed rules could settle, backlash was felt from companies and governments around the world.

But here’s the real kicker…

The U.S. government was also quick to respond to the commission’s proposal. According to news provider the AFP, U.S. Coordinator for International Communications and Information Philip Verveer told reporters that the United States would examine the legislation closely in order to determine whether the proposal would be too costly for American businesses.

Sooo…as usual, the government would rather protect business interests rather than the public’s interest.  It should be mandatory, that any business that retains any consumer’s Personally Identifiable Information, should have that info encrypted.

Read more…EU proposes data protection overhaul; criticism ensues | Simply Security.

Can Authorities Force You to Give Up Laptop Password?

%d bloggers like this: