+ Post New Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 26
Scripts Thread, Stupid batch files... in Coding and Web Development; Not sure if this should be in Server 2008 R2 or in Scripts... or coding... or "how do?" I've got ...
  1. #1

    X-13's Avatar
    Join Date
    Jan 2011
    Location
    /dev/null
    Posts
    9,637
    Thank Post
    640
    Thanked 2,155 Times in 1,474 Posts
    Blog Entries
    19
    Rep Power
    894

    Stupid batch files...

    Not sure if this should be in Server 2008 R2 or in Scripts... or coding... or "how do?"

    I've got a quick and dirty batch file to backup our staff drive to a couple of network HDDs... It works if I manually run it, but not if I schedule it.

    Code:
    @echo off
    echo %DATE% - %TIME% - BEGIN! >> log.txt
    net use Y: "\\[server]\[share]" && echo %TIME% - set first drive letter! >> log.txt || echo %TIME% - map first drive failed >> log.txt 
    echo %TIME% - copy started! >> log.txt
    robocopy "D:\RMDelivery\RMStaff" Y:\ /mir && echo %TIME% - First backup complete! >> log.txt || echo %TIME% - First copy failed! >> log.txt
    net use Y: /delete
    echo %TIME% - Cleared first drive letter! >> log.txt
    net use Z: "[server]\[share]" && echo %TIME% - set second drive letter! >> log.txt || echo map %TIME% - second drive failed >> log.txt 
    robocopy "D:\RMDelivery\RMStaff" Z:\ /mir && echo %TIME% - Second backup complete! >> log.txt
    echo %TIME% - copy started! >> log.txt
    net use Z: /delete
    echo %TIME% - Cleared second drive letter! >> log.txt
    echo %TIME% - ALL DONE! >> log.txt
    exit
    When I let the schedule run, or I run the task manually, it gets as far as the first line... then nothing.

    The task says it completed, but continues to run [doesn't kill it either].


    Any ideas what the pauseballs is going on?


    Le EDIT: [command] && [other command] || ['nother command] is a success/fail indicator... I just learned this.
    Last edited by X-13; 11th June 2014 at 12:10 PM.

  2. #2


    Join Date
    Mar 2009
    Location
    Leeds
    Posts
    6,919
    Thank Post
    231
    Thanked 900 Times in 775 Posts
    Rep Power
    303
    what user is it running as and does that user have access to the nas? best bet is to set task scheduler to run it as the same user you use to manually test it

  3. #3

    X-13's Avatar
    Join Date
    Jan 2011
    Location
    /dev/null
    Posts
    9,637
    Thank Post
    640
    Thanked 2,155 Times in 1,474 Posts
    Blog Entries
    19
    Rep Power
    894
    Quote Originally Posted by sted View Post
    what user is it running as and does that user have access to the nas? best bet is to set task scheduler to run it as the same user you use to manually test it
    It's running as SYSTEM because the scheduler doesn't want to save credentials.
    Fails on my domain admin account as well... even when I'm logged in.

    I have access to the drive.

  4. #4

    nephilim's Avatar
    Join Date
    Nov 2008
    Location
    Dunstable
    Posts
    12,420
    Thank Post
    1,682
    Thanked 2,036 Times in 1,481 Posts
    Blog Entries
    2
    Rep Power
    460
    you may well have access to the drive, but what about permissions to the drive to run these sorts of things?

  5. #5


    Join Date
    Mar 2009
    Location
    Leeds
    Posts
    6,919
    Thank Post
    231
    Thanked 900 Times in 775 Posts
    Rep Power
    303
    is uac turned on on the server? might not have access to the files. If it fails on you domain admin account how does it work when you run it manually?

  6. #6

    Join Date
    Mar 2007
    Posts
    1,844
    Thank Post
    90
    Thanked 317 Times in 241 Posts
    Rep Power
    90
    might be worth deleting the y drive before you connect to it.

  7. #7

    X-13's Avatar
    Join Date
    Jan 2011
    Location
    /dev/null
    Posts
    9,637
    Thank Post
    640
    Thanked 2,155 Times in 1,474 Posts
    Blog Entries
    19
    Rep Power
    894
    Quote Originally Posted by nephilim View Post
    you may well have access to the drive, but what about permissions to the drive to run these sorts of things?
    It runs the .bat file, gets as far as the first line, then just stops.

    Running it manually has no problems.

    If the account didn't have permission to run it, it wouldn't even get to the first line.

    Quote Originally Posted by strawberry View Post
    might be worth deleting the y drive before you connect to it.
    I have been doing that.
    Last edited by X-13; 11th June 2014 at 11:42 AM.

  8. #8

    X-13's Avatar
    Join Date
    Jan 2011
    Location
    /dev/null
    Posts
    9,637
    Thank Post
    640
    Thanked 2,155 Times in 1,474 Posts
    Blog Entries
    19
    Rep Power
    894
    Quote Originally Posted by sted View Post
    is uac turned on on the server? might not have access to the files. If it fails on you domain admin account how does it work when you run it manually?
    Quote Originally Posted by X-13 View Post
    It works if I manually run it, but not if I schedule it.
    ^^^^

  9. #9


    Join Date
    Mar 2009
    Location
    Leeds
    Posts
    6,919
    Thank Post
    231
    Thanked 900 Times in 775 Posts
    Rep Power
    303
    shouldnt
    Code:
     @echo offecho %DATE% - %TIME% - BEGIN! >> log.txt
    be
    Code:
     @echo off
    echo %DATE% - %TIME% - BEGIN! >> log.txt
    Last edited by sted; 11th June 2014 at 11:58 AM.

  10. #10

    X-13's Avatar
    Join Date
    Jan 2011
    Location
    /dev/null
    Posts
    9,637
    Thank Post
    640
    Thanked 2,155 Times in 1,474 Posts
    Blog Entries
    19
    Rep Power
    894
    Quote Originally Posted by sted View Post
    shouldnt
    Code:
     @echo offecho %DATE% - %TIME% - BEGIN! >> log.txt
    be
    Code:
     @echo off
    echo %DATE% - %TIME% - BEGIN! >> log.txt
    In the file, it is...

    Copy/paste broke it.

  11. #11

    jinnantonnixx's Avatar
    Join Date
    Mar 2011
    Location
    In the Calamatorium.
    Posts
    2,049
    Thank Post
    121
    Thanked 525 Times in 352 Posts
    Blog Entries
    2
    Rep Power
    295
    You should specify a full path for the log.txt file.
    When it's running as a schedule, unless you specify the 'start in' path, it has no relative location for log.txt. You can understand its confusion - where on earth should log.txt live?

    Even if you use the 'start in' option, it's always better for specify full paths in all scripts.

    I'm mostly Linux these days, but if my DOS memory is still working, you might want to try something like this to give you more flexibility if you need to change/rename the log file.
    Code:
    SET LOGFILE=c:\someplace\log.txt
    
    ....
    
    
    echo 'stuff I want' >> $LOGFILE
    Last edited by jinnantonnixx; 11th June 2014 at 12:44 PM.

  12. #12

    X-13's Avatar
    Join Date
    Jan 2011
    Location
    /dev/null
    Posts
    9,637
    Thank Post
    640
    Thanked 2,155 Times in 1,474 Posts
    Blog Entries
    19
    Rep Power
    894
    Quote Originally Posted by jinnantonnixx View Post
    You should specify a full path for the log.txt file.
    When it's running as a schedule, unless you specify the 'start in' path, it has no relative location for log.txt.

    Even if you use the 'start in' option, it's always better for specify full paths in all scripts.

    I'm mostly Linux these days, but if my DOS memory is still working, you might want to try something like this to give you more flexibility if you need to change/rename the log file.
    Code:
    SET LOGFILE=c:\someplace\log.txt
    
    ....
    
    
    echo 'stuff I want' >> $LOGFILE
    Again... That part works.

    It does the first [stuff] >> log.txt without any issues... then just stops.

    It doesn't even attempt to map the drive, if it did it would output whether it worked or not.


    It used to work perfectly fine as 2 robocopy commands using IPs... then it just stopped working for some reason.

  13. #13

    jinnantonnixx's Avatar
    Join Date
    Mar 2011
    Location
    In the Calamatorium.
    Posts
    2,049
    Thank Post
    121
    Thanked 525 Times in 352 Posts
    Blog Entries
    2
    Rep Power
    295
    Ah. Are you running it as a particular user with the correct permissions in Task Manager?

    Get back to basics, change the code to direct errors to a file to see if that helps
    Code:
    net use > wtf.txt
    net use Y: "\\[server]\[share]" >> wtf.txt
    Last edited by jinnantonnixx; 11th June 2014 at 12:53 PM.

  14. #14
    AlexB's Avatar
    Join Date
    Jul 2006
    Location
    Warwickshire
    Posts
    409
    Thank Post
    40
    Thanked 48 Times in 42 Posts
    Rep Power
    26
    Try adding echo %username% >> [logfile] near the top to see what user the script is running as, it may have permission to run, but not permission the connect to the shares.

  15. #15

    X-13's Avatar
    Join Date
    Jan 2011
    Location
    /dev/null
    Posts
    9,637
    Thank Post
    640
    Thanked 2,155 Times in 1,474 Posts
    Blog Entries
    19
    Rep Power
    894
    Quote Originally Posted by jinnantonnixx View Post
    Ah. Are you running it as a particular user with the correct permissions in Task Manager?

    Get back to basics, change the code to direct errors to a file to see if that helps
    Code:
    net use > wtf.txt
    net use Y: "\\[server]\[share]" >> wtf.txt

    huh... "cannot find the path specified"



SHARE:
+ Post New Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 8
    Last Post: 28th May 2012, 03:02 PM
  2. prezzie batch file to collect dps logs
    By russdev in forum ICT KS3 SATS Tests
    Replies: 4
    Last Post: 16th May 2006, 01:16 PM
  3. batch file help
    By beeswax in forum Scripts
    Replies: 9
    Last Post: 3rd March 2006, 08:48 PM
  4. numbers and batch files
    By russdev in forum Windows
    Replies: 4
    Last Post: 19th November 2005, 10:51 PM
  5. Blocking Batch Files using Group Policy in Server 2003
    By markwilliamson2001 in forum Windows
    Replies: 13
    Last Post: 4th October 2005, 06:28 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •