Grab files from workstations

Started by phoneman, January 30, 2015, 12:56:10 PM

Previous topic - Next topic

phoneman

This should be so easy to automate but I can't seem to get it to work.  I simply want to grab a debug file from some workstations and put it in a folder on my server.  I tried making an INI file and have it easily customizable so I can put in the file name, enter the computer names with the network shared path.  Copy it to a folder on my server.  With the code, If one of the computers becomes unreachable, I don't want the whole script to fail.

a=TimeYmdHms()
yyyy= strsub(a,1,4)
mm= strsub (a,6,2)
dd= strsub (a,9,2)
hh =strsub (a,12,2)
mi =strsub (a,15,2)
ss =strsub (a,18,2)
a=strcat (mm,dd,yyyy,hh,mi,ss)

f1= "debugparsed.txt"
d= "f:\debug data\"

s1="\\computer07\debug\"
s1=strcat (s1,f1)
d1=strcat (d,"computer07"," ",a," ",f1)
FileCopy (s1,d1,@false)

s1=\\computer02\debug\
s1=strcat (s1,f1)
d1=strcat (d,"computer02"," ",a," ",f1)
FileCopy (s1,d1,@false)

s1=\\computer03\debug\
s1=strcat (s1,f1)
d1=strcat (d,"computer03"," ",a," ",f1)
FileCopy (s1,d1,@false)

s1=\\computer04\debug\
s1=strcat (s1,f1)
d1=strcat (d,"computer04"," ",a," ",f1)
FileCopy (s1,d1,@false)


s1=\\computer05\debug\
s1=strcat (s1,f1)
d1=strcat (d,"computer05"," ",a," ",f1)
FileCopy (s1,d1,@false)

s1=\\computer06\debug\
s1=strcat (s1,f1)
d1=strcat (d,"computer06"," ",a," ",f1)
FileCopy (s1,d1,@false)

exit

td

I like to use 'ini' files myself.  Here's a UDF lifted from a much larger script that illustrates one way to approach loading the data into a useful format.

Code (winbatch) Select

#DEFINEFUNCTION GetSolutions( strBuildIni )
   Constants()

   ; Check file access.
   if FileExist(strBuildIni) != 1
      Message("Build Tool Error", "Unable to access the ":strBuildIni:" initialization file.")
      return ""
   endif

   lSections   = IniItemizePvt("", strBuildIni )
   nSections   = ItemCount(lSections, @Tab)
   aReturn     = ArrDimension(nSections, 7)
   
   for nItem = 1 to nSections
      nRow                         = nItem - 1
      strSection                   = ItemExtract( nItem, lSections, @Tab )
      aReturn[nRow,I_SECTION]      = strSection
      aReturn[nRow,I_FILE]         = IniReadPvt(strSection, "file",      "", strBuildIni )
      aReturn[nRow,I_VSVERSION]    = StrReplace(IniReadPvt(strSection, "vsversion", "", strBuildIni ), "|", @Tab)
      aReturn[nRow,I_PROJECTS]     = StrReplace(IniReadPvt(strSection, "projects", "", strBuildIni), "|", @Tab)
      aReturn[nRow,I_PLATFORMS]    = strUpper(StrReplace(IniReadPvt(strSection, "platforms", "", strBuildIni), "|", @Tab))
      aReturn[nRow,I_VERSIONCHECK] = strUpper(StrReplace(IniReadPvt(strSection, "versioncheck", "", strBuildIni), "|", @Tab))
      aReturn[nRow,I_OUTFILES]     = strUpper(StrReplace(IniReadPvt(strSection, "outfiles", "", strBuildIni), "|", @Tab))
   next   
     
   return aReturn
#ENDFUNCTION


Note that the I_* variables are defined in the constants subroutine at the top of above function's body and the  StrReplace calls are used because each entry can have multiple values separated by vertical bars.

There are many ways to detect if a share is available but the simplest may be to use ErrorModes around your FileCopy.

Code (winbatch) Select
nMode = ErrorMode(@Off)
FileCopy(...
ErrorMode(nMode)
if LastError()
   ; Note error somehow...
endif


There are many other approaches besides the above but it's a place to start.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade