home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / lptoo212.zip / lpts.cmd < prev    next >
OS/2 REXX Batch file  |  2000-01-31  |  10KB  |  238 lines

  1. /* Synchronize local and remote directory using LPT 1.78     JvW 25-02-97    */
  2. /*                                                                           */
  3. /* 28-02-1997 JvW Added options 1, T and S for subdirectories; L for logging */
  4. /* 21-01-2000 JvW Made some minor updates for reliability (with LPTool 2.11) */
  5. /* 23-01-2000 JvW Temporarily removed 'screen on' (caused screen corruption) */
  6. /* 31-01-2000 JvW Re-enabled (partly) 'screen on' making sync a bit faster   */
  7.  
  8.    Parse Source with . myself .
  9.    Parse Arg lspec rspec options attribs
  10.  
  11.    if lspec <> '' then
  12.    do
  13.       if Address() <> 'LPT' then
  14.       do
  15.          Address cmd '@lptq run' myself lspec rspec options attribs
  16.       end; else
  17.       do
  18.          call lptslog '>>> LPTS lspec: "'lspec'" rspec: "'rspec'"' ||,
  19.                                 ' options: "'options'" attribs: "'attribs'"'
  20.          Say ''
  21.          Say 'Synchronize directories using LPTool, (c) 1997-2000 Jan van Wijk'
  22.          Say 'Test connection to remote LPTool (daemon) ...'
  23.          prc = lptc('ping')
  24.          if (prc = 0) | (prc = 8) then
  25.          do
  26.             select
  27.             when substr(lspec,1,1) = '\'   then
  28.             do
  29.                lspec = substr(directory(),1,2) || lspec
  30.             end
  31.             when lspec = '.'                then lspec = directory()'\*'
  32.             when substr(lspec,2,2) <> ':\'  then lspec = directory()'\'lspec
  33.             otherwise nop
  34.             end
  35.  
  36.             select
  37.             when (rspec = '') | (rspec = '=') then rspec = lspec
  38.             otherwise nop
  39.             end
  40.             call lptslog 'lspec: "'lspec'" rspec: "'rspec'"'
  41.  
  42.             Say 'Synchronize local' lspec 'with remote' rspec
  43.             lbase = GetDirFromSpec( lspec, '')
  44.             rbase = GetDirFromSpec( rspec, 'r')
  45.             call lptslog 'lbase: "'lbase'" rbase: "'rbase'"'
  46.                                                                            /* 
  47.                                                                            */
  48.             Say 'Get remote file-list :' rspec '          Please wait ...'
  49.             call lptc 'screen off'
  50.             call lptc 'lptqscr off'
  51.             call lptc 'rexec @say LPTS sync started; Send file-list for:' rspec
  52. /*
  53.             remote screen-off makes local system miss the REXX CopyOutput !!!
  54.             call lptc 'rexec @screen off'
  55. */
  56.             call lptc 'rexec @tstree' rspec lbase 'F'options attribs
  57.             call lptc 'CopyOutput     rtree.'
  58.             call lptc 'rexec @screen on'
  59.             call lptc 'screen on'
  60.             call lptc 'lptqscr on'
  61.             call lptc Say 'Get local  file-list :' lspec
  62.             call lptc 'screen off'
  63.             call lptc 'lptqscr off'
  64.             call lptc 'tstree'      lspec  rbase 'F'options attribs
  65.             call lptc 'CopyOutput   ltree.'
  66.             call lptc 'screen on'
  67.             call lptc 'lptqscr on'
  68.  
  69.             if pos('T', Translate(options)) <> 0 then
  70.             do
  71.                lptcmd = 'show'
  72.                remote = 'rexec '
  73.                sverb  = 'to be sent'
  74.                rverb  = 'to be received'
  75.             end; else
  76.             do
  77.                lptcmd = 'send'
  78.                remote = '*'
  79.                sverb  = 'sent'
  80.                rverb  = 'received'
  81.             end
  82.                                                                            /* 
  83.                                                                            */
  84.             NUMERIC DIGITS 20
  85.             rdone = 0
  86.  
  87.             if pos('1', options) <> 0 then
  88.             do
  89.                method = 'One'
  90.             end; else
  91.             do
  92.                method = 'Two'
  93.             end
  94.             rtext = method'-way sync' Translate(lptcmd) 'remote:'
  95.             ltext =                   '                   local:'
  96.             Say rtext right( rtree.0 -2, 5) 'files in' rspec
  97.             Say ltext right( ltree.0 -1, 5) 'files in' lspec
  98.  
  99.             if pos('1', options) = 0 then
  100.             do
  101.                if rtree.0 <> 0 then Say ''
  102.                Say 'Sync REMOTE to local :' lbase
  103.                do i=1 to rtree.0
  104.                   parse value rtree.i with rstamp rname '»' ldest
  105.                   exist = 0
  106.                   do j=1 to ltree.0
  107.                      parse value ltree.j with lstamp lname '»' .
  108.                      rrelative = substr(strip(rname), length(rbase))
  109.                      lrelative = substr(strip(lname), length(lbase))
  110.                      if rrelative = lrelative then
  111.                      do
  112.                         exist = 1
  113.                         if (lstamp < rstamp) & (lname <> '') then
  114.                         do
  115.                            call lptc remote || lptcmd rname ldest 'p'
  116.                            rdone = rdone + 1
  117.                         end
  118.                      end
  119.                   end
  120.                   if exist = 0 then
  121.                   do
  122.                      call lptc remote || lptcmd rname ldest 'p'
  123.                      rdone = rdone + 1
  124.                   end
  125.                end
  126.                'watch 1 1'
  127.             end
  128.             if ltree.0 <> 0 then Say ''
  129.             Say 'Sync LOCAL to remote :' rbase
  130.             ldone = 0
  131.             do i=1 to ltree.0
  132.                parse value ltree.i with lstamp lname '»' rdest
  133.                exist = 0
  134.                do j=1 to rtree.0
  135.                   parse value rtree.j with rstamp rname '»' ldest
  136.                   rrelative = substr(strip(rname), length(rbase))
  137.                   lrelative = substr(strip(lname), length(lbase))
  138.                   if rrelative = lrelative then
  139.                   do
  140.                      exist = 1
  141.                      if (rstamp < lstamp) & (lname <> '') then
  142.                      do
  143.                         call lptc lptcmd lname rdest 'p'
  144.                         ldone = ldone + 1
  145.                      end
  146.                   end
  147.                end
  148.                if exist = 0 then
  149.                do
  150.                   call lptc lptcmd lname rdest 'p'
  151.                   ldone = ldone + 1
  152.                end
  153.             end
  154.                                                                            /* 
  155.                                                                            */
  156.             Say ''; Say 'LPTS' lptcmd 'finished, ' ||,
  157.                                            sverb':' ldone rverb':' rdone
  158.  
  159. /*          Remote-exec after send/receive often causes timeouts ...
  160.             call lptc 'screen off'
  161.             call lptc 'lptqscr off'
  162.             call lptc 'rexec @say LPTS'  lptcmd 'finished, ' ||,
  163.                                          sverb':' rdone rverb':' ldone
  164.             call lptc 'rexec @say'
  165.             call lptc 'screen on'
  166.             call lptc 'lptqscr on'
  167. */
  168.          end; else
  169.          do
  170.             Say 'Remote LPT (deamon) not running or not connected ...'
  171.          end
  172.       end
  173.    end; else
  174.    do
  175.       Say ''
  176.       Say 'Synchronize directories using LPTool, (c) 1997-2000 Jan van Wijk'
  177.       Say ''
  178.       Say 'Usage:' myself 'Local-Spec [Remote-Spec [options [attributes]]]'
  179.       Say ''
  180.       Say '  Local-Spec  =  Local directory specification including final "\",'
  181.       Say '              or Local directory + file-specification (wildcard),'
  182.       Say '              or "." for the current directory.'
  183.       Say ''
  184.       Say '  Remote-Spec =  Remote directory specification including final "\",'
  185.       Say '              or Remote directory + file-specification (wildcard),'
  186.       Say '              or "=" or empty for same as Local-Spec'
  187.       Say ''
  188.       Say '  options     :  s for subdirectories included (recursive)'
  189.       Say '                 1 for one-way update from local to remote only'
  190.       Say '                 t Test modus, just show files to be updated'
  191.       Say '                 l Log  modus, log lpt commands to LPTSCMDS.log'
  192.       Say ''
  193.       Say '  attributes  =  File attributes for files to include in the sync:'
  194.       Say '                 A = Archive, R = Read-only, S = System, H = Hidden'
  195.       Say '                     Prefix each with "+" for set and "-" for reset'
  196.       Say ''
  197.       Say 'Examples:' myself '.'
  198.       Say '         ' myself 'H:\data\*.txt D:\myfiles\archive\*.txt'
  199.       Say '         ' myself 'R:\code\*     =   s'
  200.    end
  201. exit 0
  202.  
  203.                                                                            /* 
  204.                                                                            */
  205. GetDirFromSpec: procedure
  206.    Parse arg fspec, at
  207.    dir = '.\'
  208.    p = LastPos('\', fspec)
  209.    if p = 0 then                                /* relative, use current .   */
  210.    do
  211.       if substr(fspec,2,1) = ':' then           /* drive only, get curdir    */
  212.       do
  213.          'screen off'; 'lptqscr off'
  214.          at 'cd' substr(fspec,1,2)
  215.          'CopyOutput    curdir.'
  216.          'screen on';  'lptqscr on'
  217.          if curdir.0 = 1 then dir = curdir.1
  218.       end
  219.    end; else dir = substr( fspec, 1, p)
  220.    return strip(dir)
  221.  
  222. lptc:
  223.    Parse arg lpt_cmd
  224.    lpt_cmd
  225.    lptrc = rc
  226.    call lptslog 'RC:' lptrc 'on: "'lpt_cmd'"'
  227.    rc = lptrc
  228.    return lptrc
  229.  
  230. lptslog:
  231.    Parse arg logline
  232.    if pos('L', Translate(options)) <> 0 then
  233.    do
  234.       call lineout 'LPTSCMDS.log', logline
  235.       call Stream  'LPTSCMDS.log', 'C', 'close'
  236.    end
  237.    return ''
  238.