none
Error on .bat script RRS feed

  • Question

  • Hi all,

    We have 3 folders on a Shared folder that contains some files. There're 3 GPO, each one contain a folder. To change mounthly the content between folders, we created a Schedule process that run this .bat:

    **********************************************************

    @echo off

    goto 1

    :1
    ren \\folder\Grupo1 Grupo0

    timeout /t 5

    goto 2

    :2
    ren \\folder\Grupo2 Grupo1

    timeout /t 5

    goto 3

    :3
    ren \\folder\Grupo3 Grupo2

    timeout /t 5

    goto 4

    :4
    ren \\folder\Grupo0 Grupo3

    timeout /t 5

    goto end

    :end

    ************************************************

    The problem is that sometimes, this proces when rename folders, make some (random) folder empty.

    Some idea of what is the error? Running manually also delete some folder content random.

    Thanks and regards,


    Gerardo,

    • Moved by Bill_Stewart Friday, March 15, 2019 6:11 PM This is not "scripts on demand"
    Thursday, January 17, 2019 12:29 PM

All replies

  •  Running manually also delete some folder content random.

    I'm having a hard time following your question. What does it mean for a GPO to "contain a folder"?

    More importantly, if you're having a problem with or without the script (quote above), then the question doesn't doesn't belong here. You shouldn't be complicating whatever your issue is by adding automation on top of it.



    Mike Crowley

    My Blog | MikeCrowley.US

    Baseline Technologies | Baseline.Consulting

    Being ignorant is not so much a shame, as being unwilling to learn

    -Ben Franklin

    Thursday, January 17, 2019 2:56 PM
  • goto 3

    :3
    ren \\folder\Grupo3 Grupo2

    timeout /t 5

    goto 4

    :4
    ren \\folder\Grupo0 Grupo3

    I don't see how that can possibly work. The "\\" indicates a UNC path. The command would have to be:

        ren \\servername\sharename\Grupo0 Grupo3

    And you don't need the goto's, because you are only "going to" the next statement which would be the next statement to be executed anyway.

    And I would not run this over the network, but rather run it locally on the server. 

        ren E:\DataShare\Grupo0 Grupo3

    But your problem is going to be renaming the folder if some other process or user has an open file handle. To see how this works, create a folder named Test1 and create a txt file in it. Open the txt file with notepad, and then from a command prompt run the rename. You will get this: "The process cannot access the file because it is being used by another process."

    You should capture the output of your bat file so that you can troubleshoot problems. That include capturing both stdout and stderr. In the scheduled task, configure it to execute cmd.exe. The parameters should be (example) "/c c:\YourBatFileFolder\YourRenameBat.bat 1> c:\YourBatFileFolder\YourRenameBat.log 2>&1"

    If you determine that files are open, then you will have to decide how to proceed. Ie, is the process running on the server or is a file opened over a network share. You will then need to programmatically  kill the process or network session. 

    In any case, you should be converting this to Powershell. That will be easier when you have to write code to kill open handles. 

    • Marked as answer by gerard_gorrion Thursday, January 17, 2019 3:39 PM
    • Unmarked as answer by gerard_gorrion Thursday, January 17, 2019 3:39 PM
    • Marked as answer by gerard_gorrion Thursday, January 17, 2019 3:45 PM
    • Unmarked as answer by gerard_gorrion Thursday, January 17, 2019 3:45 PM
    Thursday, January 17, 2019 3:05 PM
  • I know thet \\server\\sharedfolder, but i don't wnat that you see our Shared folders ¬¬

    Ok, tomorrow i try to change the old .bat to power Shell to search a better configuration.

    Example of GPO:

    User configuration\Policies\Administrative templates\desktop\desktop\desktop wallpaper\ and here put: \\myserver\sharedfolder\file.dat (here also have the 3 folders of the script change)

    These configuration work, but when .bat change the folders name, sometimes delete his content...

    Regards and thank you,


    Gerardo,



    Thursday, January 17, 2019 3:42 PM
  • If you have files that are in use when you try to rename the folders, then converting to powershell will not make a difference. 

    I don't quite understand your explanation of the "GPO". How does "desktop wallpaper" fit in with a folder rename problem?

    Add diagnostic commands to your bat file. Like this. This will show you all files in folder before and after you rename it. Your scheduled task will need to capture both stdout (1) and stderr (2) as explained earlier. 

      dir /b /s /a \\servername\sharename\Grupo0
      ren \\servername\sharename\Grupo0 Grupo3
      dir /b /s /a \\servername\sharename\Grupo3
     

    Thursday, January 17, 2019 5:29 PM
  • Because the content on the folder is a jpg file that is configure as wallpaper of 33% of the users in my company currently.

    Gerardo,

    Friday, January 18, 2019 7:31 AM
  • Are you sure that the rename is working? I don't see any way that a rename would randomly delete some files in the folder.  

    If you have a lot of files in the folders, then a dir command may take too long. Create a status file like this. Note that ">" will create/overwrite the file, and ">>" will append the text to the file. 

    echo %date% %time% This is the Grupo0 folder and is being renamed to Grupo3 > \\servername\sharename\Grupo0\$FolderStatus.txt 
    ren \\servername\sharename\Grupo0 Grupo3
    echo %date% %time% This was the Grupo0 folder was successfully renamed to Grupo3 >> \\servername\sharename\Grupo3\$FolderStatus.txt  



    • Edited by MotoX80 Friday, January 18, 2019 3:00 PM
    Friday, January 18, 2019 2:59 PM