• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Help me with a batch file?

alyarb

Platinum Member
I have an XP workstation and an old old SCO UNIX version 3 server with often-modified files on it. I have a batch file that XP runs as a scheduled task every day. It is a simple XCOPY over samba. Here's what I have:

Code:
@ECHO ON
call :Logit>>unix_backup.log 2>&1
exit /b 0
:Logit

net use u: \\192.168.0.100\Unix-u /user:Owner owner /persistent:yes
xcopy U:\advant\*.* /e/h/k/r/c/y c:\nordic_advant

When XP first starts up, I get an error saying it can't get into the server. If I browse manually to the shared location, however, and then run the batch file, it works perfectly. There is something that must be initialized with the shared location and/or drive mapping that the batch file is not doing, so if the computer reboots and this missing component is not initialized, the xcopy will fail. Any suggestions on fixing that would be great.

Secondly, what switch do I use to put timestamps in the log file? Thanks guys
 
Maybe the batch file is running before the network connection is established. Try inserting this line at the top of your batch file:

ping 123.45.67.89 -n 1 -w 5000 > nul

The 5000 is the delay time. Be sure to try at least 20000 milliseconds if 5000 doesnt help.


Code:
net use u: \\192.168.0.100\Unix-u /user:Owner [B]owner[/B] /persistent:yes
xcopy U:\advant\*.* /e/h/k/r/c/y c:\nordic_advant


See the bolded word? Is that correct syntax? I am wondering why you need the user listed when the user appears to be a local user. That user is probably already logged in and is the one running the batch file, right?
 
Last edited:
See the bolded word? Is that correct syntax? I am wondering why you need the user listed when the user appears to be a local user. That user is probably already logged in and is the one running the batch file, right?

Correct. That line is there to ensure that a mapped letter is created to that location and the credentials necessary to get in are saved (user owner pass owner).
 
Secondly, what switch do I use to put timestamps in the log file? Thanks guys
Would this work?

Code:
date /t >> unix_backup.log
time /t >> unix_backup.log
edit: If you mean the timestamp for each file, I guess you could do this:

Code:
dir U:\advant >> unix_backup.log
 
Last edited:
Ok thanks, I will try that. I just need some way of giving (ensuring) the batch process access to the share, and then going in and xcopying the share and timestamping each copy.

the network interface is up because i am doing all of this remotely. it's not that this batch file runs immediately after reboot, but if the machine is rebooted some time that day, the batch process cannot get into the share unless some user browsed with the mouse to the share. so there is some component of the sharing that is activated by the browser and not the batch process.
 
Last edited:
Could it be that U: is already mapped and the net use command is failing?

Maybe try net use u: /delete before mapping it.

Snapshot1
 
Could it be that U: is already mapped and the net use command is failing?

Maybe try net use u: /delete before mapping it.

Snapshot1

This...had the exact same issue on a copy script i was working on. Worked fine with someone logged in, but wouldn't always work in weird scenarios, similar to what you have.

Do the /delete command, then recreate it.

If you dont (and even if you use /persistent), the connection will say disconnected until you manually browse to it.

You can see this if you type "net use" right after bootup *before browsing anywhere*. It will show the link, but disconnected. If you then browse to it in windows explorer, it will reconnect, and youll see that reflected if you use "net use" again.

I've always just gotten around it by not using /persistent and just mapping it each time.
 
Yep, if you never delete the map, it's going to try to re-use a drive letter already in use. /persistent doesn't save credentials, just the drive mapping between user sessions. /savecred saves credentials, but requires actual input at the command line...it shouldn't be needed anyway.

Also, include the /y switch to bypass the "are you sure" prompt.

net use u: /delete /y

Or, as mentioned, don't use /persistent at all. It shouldn't be necessary if you're just temporarily mapping the drive for the purpose of copying files.

Code:
net use u: \\192.168.0.100\Unix-u /user:Owner owner
xcopy U:\advant\*.* /e/h/k/r/c/y c:\nordic_advant
net use u: /delete /y
 
Last edited:
Yep, if you never delete the map, it's going to try to re-use a drive letter already in use. /persistent doesn't save credentials, just the drive mapping between user sessions. /savecred saves credentials, but requires actual input at the command line...it shouldn't be needed anyway.

Also, include the /y switch to bypass the "are you sure" prompt.

net use u: /delete /y

Or, as mentioned, don't use /persistent at all. It shouldn't be necessary if you're just temporarily mapping the drive for the purpose of copying files.

Code:
net use u: \\192.168.0.100\Unix-u /user:Owner owner
xcopy U:\advant\*.* /e/h/k/r/c/y c:\nordic_advant
net use u: /delete /y


What OS are you normally doing net use on? On my win7 box it never asks me if I'm sure?
 
What OS are you normally doing net use on? On my win7 box it never asks me if I'm sure?

Mixed Win7/XP in my lab. Yeah Win7 doesn't seem to ask me either; XP must then. I use it some login/startup scripts...I don't think I would have added it for shits and giggles.

I'm also using net use *, instead of a drive letter. Maybe that makes a difference.

Doesn't hurt in any case.
 
Last edited:
Also, don't map a drive to a letter just net use \\server\\path. The drive letter just makes things harder and use xcopy referencing the UNC path directly.
 
Back
Top