?
Solved

Batch File Issues

Posted on 2012-09-06
10
Medium Priority
?
940 Views
Last Modified: 2012-11-17
Client has an automated process to send statement files generated out of their practice management program a company. The process is scripted to sweep the directories that they save these exported statements into and it sends them a company through .exe by means of Windows scheduled task. All works fine on my Server 2003 OS.

Here is where I am seeing an issue.

I have the exact same setup on the 2008 R2 x64 server as I do on the 2003 x86 Standard but they act differently.

Here is the basic version:

On the 2008 server – The script is below:

for %%a in ("C:\Path\*.txt") do abc.exe -u username -p password -d "Client Statement File" -f "%%a" >> abc.log

move "C:\Path\*.txt" "C:\Path\Processed"

Notice there are two parts. The first sends it to the company and the second just moves the file out of the original directory so it won’t get picked up again next time.

1. When we use a Server 2008 Scheduled Task and point it at the batch file with the commands above – it moves the file (step2) and NOTHING is written to the abc.log and if I check the company, it is never received .

2. If I run the batch script by either double clicking on it or through a command prompt – it will move the file and write to the abc.log that it was sent.

We have checked that all the abc.exe and abc.log have full permissions and obviously the scripting is written correctly because it works when run manually.

We have created a new scheduled task on the Server 2008 with Server 2003 compatibility – same result.

Also booted the server – same result.

We have even tried setting up a remote scheduled task firing off of a 2003 server in the same domain – (utilizing psexec - which we have done before when scheduled tasks wouldn't work with Server 2008 but would work when manually run) - same result.

I tried changing the abc.exe compatibility to XP but still nothing.

Confused
0
Comment
Question by:vpnsol123
  • 5
  • 2
  • 2
  • +1
10 Comments
 
LVL 43

Expert Comment

by:Steve Knight
ID: 38372450
Ok, first thoughts... Where is abc.exe ?  Is it accessible, i.e. in the path, or in the same dir as the script.  Is the script ran with working directory correct?

Try adding this to scheduled script:

@Echo off
( echo Run at %date% %time% as %userdomain% \ %username% on %computername%
 echo Current dir is %cd%
  dir abc.exe
  abc.exe /?  ) > "c:\path\test.log"

Assuming the exe abc.exe has a /? param which will give some output for instance.

Then see what it reports back for your scheduled job vs manual.
0
 
LVL 22

Expert Comment

by:Christopher McKay
ID: 38372480
Hi vpnsol123,

Have you tried checking the properties of the scheduled task, to make sure that under security options it's set to run as a user rather than the system?

Start > All Programs > Accessories > System Tools > Task Scheduler

Select Task Scheduler Library
Right click on your task,
choose properties,
Under Security Options, Ensure it's using a user account, if not, click on Change User or Group button.


Hope this helps!

:o)

Bartender_1
0
 

Author Comment

by:vpnsol123
ID: 38372574
Hi all -

I have the same question as above into the company who gave us the .exe - as it may have something to do with that exe and 2008 for all I know but I came here to make sure I wasn't missing anything from an IT standpoint that I could try.

abc.exe and the abc.log are in a direcory on C and that directory is shared with full control and full access as far as local security as well

The exe doesn't respond to a /? probably because its proprietary, I assume - should I still try to insert your scripting then?

The scheduled task is running under domain admin user account with the Run as highest privileges checked

Thx all
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 43

Expert Comment

by:Steve Knight
ID: 38372587
Was just suggesting then you could confirm what environment it is running under by looking at the log file it makes.

Steve
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 38372604
Does the abc.log file appear at all btw?

You could also do some other checks:

@Echo off
(
echo Run at %date% %time% as %userdomain% \ %username% on %computername%
echo Current dir is %cd%
dir abc.exe
for %%a in ("C:\Path\*.txt") do echo abc.exe -u username -p password -d "Client Statement File" -f "%%a"
for %%a in ("C:\Path\*.txt") do echo abc.exe -u username -p password -d "Client Statement File" -f "%%~a"
) > c:\path\logfile.txt

And see whether that loops through the files OK or not... do they have one set of " " around the filenames at the ends of the lines?  

Perhaps you could post a part of the log - change the pc / user names if needed.
0
 

Author Comment

by:vpnsol123
ID: 38373065
the log file is present at all times and gets updated when the batch file is successful so basically as its not successful - it never gets written to so I have nothing to post and the user name and password in the file are fine as the whole process works if you double click the .bat.

It just baffles me that it does exactly what is should when we double click the batch file rather than pointing the 2008 scheduled task at the batch file it just does the second step - the move portion - but never the first part of the batch file

Update -

I ended up using a 2003 server in that same domain – set up the scheduled tasks there – brought over the abc.exe’s, abc.logs and batch files from all the different processes we have – changed the batch files to reference a network path rather than local and tested and they work. This is a band aid but for now – the automation is back in play so the severity is decreased.

Really weird.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 38373275
So did the log of debugging information appear when you ran with the code above?

Steve
0
 
LVL 11

Accepted Solution

by:
paultomasi earned 2000 total points
ID: 38374640
Have you tried doing it like this:

@echo off
for %%a in ("C:\Path\*.txt") do (
  abc.exe -u username -p password -d "Client Statement File" -f "%%a" >> abc.log
  move "%%~fa" "C:\Path\Processed"
)

Open in new window

0
 
LVL 11

Expert Comment

by:paultomasi
ID: 38608182
Thank you.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 38608505
So did you get this working that way then?  We asked for arious debugging logs but got no answer so there wasn't anything else to suggest without it frankly.
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
Resolving an irritating Remote Desktop connection that stops your saved credentials from being used.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question