[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Command scheduler , batch files, and file piping.

Posted on 1998-11-09
9
Medium Priority
?
585 Views
Last Modified: 2013-12-19
I'm executing a batch file from the Command Scheduler (on server1) which executes ok until I add file piping. The batch file resides on server2, but it executes on server1.
The batch file maps a network drive and then sends ECHO command output to a file in the current directory. The commands used are:

net use y: \\my_server\share
y:
cd folder1\folder2\folder3
ECHO ***** Start of TEST BATCH FILE Processing. ***** >test.log
ECHO | MORE | DATE | FIND "date is" >>test.log

Test.log is to be created in the \\my_server\share\folder1\folder2\folder3 directory. Everything was ok until I added the piping for logging purposes. Now I have a mapped network drive that I can't get rid of. It shows up in Explorer and at the command prompt. The drive letter is available both places, but I can't delete it from Explorer or at the command promt. NT says that the driver letter isn't available when I use 'net use y: /delete'.

My first question is "How can I get the piping in the batch file to work properly?"

And my second question is "How can I easily get rid of the 'phantom' driver mappings?" (I'd like to avoid rebooting as this is an in-use server.)
0
Comment
Question by:jpas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 2

Expert Comment

by:livni
ID: 1565344
I think the problem is that you are using a share with scheduler.
scheduler runs under system account and therefor cannot access shares.

I think your mapping doesn't work correctly during the running of the batch file on scheduler.

Try to add to your net use command /user:username password
net use y: \\server\share /user:username password

This should do it...
0
 

Author Comment

by:jpas
ID: 1565345
Sorry. I should have mentioned that the Schedule service is logging on as a user. The batch file executing works ok from the scheduler until I add the file piping to the batch file. Your previous suggestion of using a user logon for the schedule service (or mapping a driver using a user logon), both worked, so I think I'm past that problem.
0
 
LVL 2

Expert Comment

by:livni
ID: 1565346
1. I couldn't understand what is the problem with the test.log file. could you explain again ?
2. Try to add the net use y: /delete at the end of your script (after your next boot...)
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:jpas
ID: 1565347
1. I'm trying to pipe output from the batch file into the test.log logfile. I thought everything was working ok until I added the piping (>test.log) command to the end of the ECHO statements. These don't seem to be working and NT gets confused about whether the drive is mapped or not. Now I'm running into the message 'The process cannot access the file because it is being used by another process.'

I'll do some more testing to try to narrow the problem down.

2. The end of the batch file does release the driver mapping.
0
 

Accepted Solution

by:
dragonfire earned 400 total points
ID: 1565348
I suspect that the problem with the share is that is is in use in a 'hidden' command prompt (One that was started by the scheduler). You can tell by making sure any command prompts are closed (And no scheduled processes are running) then running Task Manager and looking for CMD.EXE under processes - If you are sure nothing else is using it, kill it.

The reason why I think this happened (And your batch script doesn't work) is that the command line:
ECHO | MORE | DATE | FIND "date is" >>test.log
doesn't make sense without an interactive session, a simpler way is:
ECHO.| DATE | FIND "date is" >>test.log
(Don't miss the '.' )

I know this works in schedule scripts as I use it. (With some even more odd command structures using the FOR command to select just the date code).
0
 
LVL 5

Expert Comment

by:carmine
ID: 1565349
To pipe the date why not just use?

date/t>>file.ext
0
 

Author Comment

by:jpas
ID: 1565350
Using 'date /t' does look better and is easier to use. Thanks.

The problem with piping to a particular file seems to be caused by something else having the file open. Everytime the batch file tries to access it, a message displays that the file can't be accessed because it's being accessed by another process. That must be from an earlier attempt at logging. Checking Task Manager didn't reveal any hidden command sessions, and I didn't see anything in Server Manager indicating the file was open.

Using a different file name clears up the problem. So it is working now.
0
 
LVL 5

Expert Comment

by:carmine
ID: 1565351
You could try putting a

NET USE \\my_server\IPC$ /DELETE

in your batch file before connecting the drive.  This should close any existing connections and give you a clean start.
0
 

Author Comment

by:jpas
ID: 1565352
The drive mappings still hang around even after using NET USE \\<my_server>\IPC$ /DELETE. I'm guessing they'll clear up the next time the machine is rebooted.

0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

FIPS stands for the Federal Information Processing Standardisation and FIPS 140-2 is a collection of standards that are generically associated with hardware and software cryptography. In most cases, people can refer to this as the method of encrypti…
This article offers some helpful and general tips for safe browsing and online shopping. It offers simple and manageable procedures that help to ensure the safety of one's personal information and the security of any devices.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

649 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