Page 1 of 1

error with an os command is dzvents

Posted: Tuesday 11 February 2020 17:48
by pvklink
Hi,


I need to change my file sync script.
I made a dashboard with webcams and push the images to my nest hub.
My sync script sometimes moves files that are to be published.
So i gave my files to be published names like: xxx<name> . I like to exclude them from the mv command from the sync script

I found out that this works:

Code: Select all

find /media/pi/motionfiles/ -type f ! -name "xxx*" -exec mv {} /home/pi/test2/ \;

-- so i tadjust the original script below and changed the move command with

osCommand('sudo find ' .. sourceDir .. '/ -type f ! -name "xxx*" -exec mv {} ' .. targetDir .. '/ \;')    
I get this error: (it is the last part of the string, the sign: \

Code: Select all

/DZ_service_filecopy.lua':
2020-02-11 17:46:27.444 ...cripts/dzVents/generated_scripts/DZ_service_filecopy.lua:53: invalid escape sequence near ''/ \;'
2020-02-11 17:46:27.635 Error: dzVents: Error: (2.5.7) error loading module 'DZ_service_filecopy' from file '/home/pi/domoticz/scripts/dzVents/generated_scripts/DZ_service_filecopy.lua':
2020-02-11 17:46:27.635 ...cripts/dzVents/generated_scripts/DZ_service_filecopy.lua:53: invalid escape sequence near ''/ \;'
2020-02-11 17:46:27.763 Error: dzVents: Error: (2.5.7) error loading module 'DZ_service_filecopy' from file '/home/pi/domoticz/scripts/dzVents/generated_scripts/DZ_service_filecopy.lua':
2020-02-11 17:46:27.763 ...cripts/dzVents/generated_scripts/DZ_service_filecopy.lua:53: invalid escape sequence near ''/ \;'
2020-02-11 17:46:28.039 (zwavepluspvk) Current (Unknown)
20

original script

Code: Select all

return 
{
    on =    { 
            timer = {timer_overdag,timer_nacht},
            devices = {'filecopy'},
            },
            
    logging =   {
                level   = domoticz.LOG_ERROR,
                },                  

    execute = function(dz,item,info)
    _G.logMarker = _G.moduleLabel -- marker wordt scriptnaam, _G.logMarker = info.scriptName is idem

        if (item.isDevice and item.name == 'filecopy' and item.state == 'On') or item.isTimer then
            local messageTable = {}
            local sourceDir = '/media/pi/motionfiles'
            local targetDir = '/mnt/mntnas'

            local function osCommand(cmd)
                local fileHandle     = assert(io.popen(cmd, 'r'))
                local commandOutput  = assert(fileHandle:read('*a'))
                local returnTable    = {fileHandle:close()}
                if returnTable[3] ~= 0 then
                    dz.helpers.globalMessage2(dz,item,info,messageTable,'add', '\nCommand:       ' .. cmd  .. '\nReturnCode:   ' .. returnTable[3] .. '\ncommandOutput: ' .. commandOutput)

                end
                return commandOutput
            end

            local function fileCount(dir)
                return tonumber(osCommand('ls ' .. dir .. ' | wc -l'))
            end    

            if fileCount(sourceDir) > 0 then
                dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' NAS: Er zijn bestanden op de SHARE aanwezig...')
                dz.devices('motion files aanwezig').switchOn().checkFirst()

                if (item.isDevice and item.name == 'filecopy' and item.state == 'On') or (item.isTimer and item.trigger == timer_overdag) then
                    --osCommand('sudo mv ' .. sourceDir .. '/* '  .. targetDir .. '/')
                    -- alles wat met xxx begint laten staan (worden gebruikt en later gerenamed zodat ze alsnog worden verplaatst)
                    -- dit werkt mv `find /home/pi/test '!' -type d | fgrep -v xxx*` /home/pi/test2

                    --find /media/pi/motionfiles/ -type f ! -name "xxx*" -exec mv {} /home/pi/test2/ \;
                    osCommand('sudo find ' .. sourceDir .. '/ -type f ! -name "xxx*" -exec mv {} ' .. targetDir .. '/ \;')     

                    dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' NAS: Er zijn bestanden verplaatst...')
                    dz.devices('motion files aanwezig').switchOff().checkFirst()
                end
            else
                --dz.helpers.globalMessage2(dz,item,info,messageTable,'add', ' NAS: Er zijn geen bestanden op de SHARE aanwezig...')    -- teveel berichten

                dz.devices('motion files aanwezig').switchOff().checkFirst()
            end
        
            if item.isDevice and item.name == 'filecopy' and item.state == 'On' then
                item.switchOff().afterSec(5)
            end
            dz.helpers.globalMessage2(dz,item,info,messageTable,'chg') -- dump

        end
    end
}

Re: error with an os command is dzvents  [Solved]

Posted: Tuesday 11 February 2020 18:05
by waaren
pvklink wrote: Tuesday 11 February 2020 17:48 I get this error: (it is the last part of the string, the sign: \

Code: Select all

zDZ_service_filecopy.lua':
2020-02-11 17:46:27.444 ...cripts/dzVents/generated_scripts/DZ_service_filecopy.lua:53: invalid escape sequence near ''/ \;'
You will have to 'escape' the \ by a \
so use

Code: Select all

osCommand('sudo find ' .. sourceDir .. '/ -type f ! -name "xxx*" -exec mv {} ' .. targetDir .. '/ \\;')    

Re: error with an os command is dzvents

Posted: Tuesday 11 February 2020 20:42
by pvklink
Yes, it works!
Yeeeee, is was searching my as@@@@ off, for this...one character...