📜 ⬆️ ⬇️

Updating the files in the branch network (via SMB)

We have a network of branches at work and periodically there is a task to update something.
A good admin is a lazy admin, so doing it constantly constantly at least contradicts the religion of the profession.

Baseline: CentOS 5 + samba bundle as domain controllers and file servers.
All branches are networked using openVPN.

I will give the script update files 2GIS (do not consider the advertising). The script can easily be modified for other purposes.
Immediately, I note the questions about the on-site update with the help of the built-in update program - we do not use the Windows Server, but it is wrong to give the authority to update the office staff for security reasons and their forgetfulness.
Of course, the update task can be accomplished in other ways. I advise you to read as a profit.

An important requirement is that a user with write access to the 2gis folder should be entered everywhere.
Let it be adminuser with password samplepassword.
One more note - in all branches, the folder with 2GIS is in the public ball.

You need to run the script from the computer where there are updated files.

var WshNetwork = WScript.CreateObject("WScript.Network"); FSO = new ActiveXObject("Scripting.FileSystemObject"); var WshShell = WScript.CreateObject("WScript.Shell"); //  IP  ,  ,       . var filials = new Array(); filials.push(new Array("","PERM","Data_Perm.dgdat","portable\\2gis\\3.0")); filials.push(new Array("","KRASNODAR","Data_Krasnodar.dgdat")); filials.push(new Array("","ROSTOV","Data_Rostov.dgdat","2gis")); filials.push(new Array("","TUMEN","Data_Tyumen.dgdat","portable\\2gis")); filials.push(new Array("","UFA","Data_Ufa.dgdat","portable\\2gis\\3.0")); filials.push(new Array("","SAMARA","Data_Samara.dgdat","info\\2gis")); //  ,      try { WshNetwork.RemoveNetworkDrive ("Q:",true,false); // force, dont update profile } catch(e) { } //    for (i in filials) { //    SMB try { WshNetwork.MapNetworkDrive ("Q:", "\\\\"+filials[i][0]+"\\public", false, filials[i][1]+"\\adminuser", "samplepassword"); } catch(e) { WScript.Echo(filials[i][1]+" (map): "); } path2gis = "Q:\\"+filials[i][3]+"\\grym.exe"; pathmap = "Q:\\"+filials[i][3]+"\\"+filials[i][2]; //     //    , .. DeleteFile -   try { WshShell.Run("cmd /C del /Q /F "+path2gis,0,true); WshShell.Run("cmd /C del /Q /F "+pathmap,0,true); } catch(e) { } //    if (FSO.FileExists(pathmap) || FSO.FileExists(path2gis)) { WScript.Echo(filials[i][1]+": can't delete"); } //  try { FSO.CopyFile("C:\\Program Files\\2gis\\3.0\\grym.exe", "Q:\\"+filials[i][3]+"\\",true); FSO.CopyFile("C:\\Program Files\\2gis\\3.0\\"+filials[i][2], "Q:\\"+filials[i][3]+"\\",true); } //    catch(e) { WScript.Echo(filials[i][1] + " (copy): " + e); } //   WshNetwork.RemoveNetworkDrive ("Q:",true,false); } 

Finally, a link to the documentation:
Windows Script Host

Source: https://habr.com/ru/post/105449/

All Articles