error with an os command is dzvents  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
pvklink
Posts: 822
Joined: Wednesday 12 November 2014 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest b
Contact:

error with an os command is dzvents

Post 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
}
Raspberry (raspbian on rpi 3) , Domoticz Beta, dzVents , RFXtrx433e, P1, Hue, Yeelight, Zwave+, X10, ESP(easy), MQTT,Weather Underground, System Alive Checker, Domoticz Remote Server to RPI with Google Assistant,
Jablotron connection, Ikea
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

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

Post 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 .. '/ \\;')    
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
pvklink
Posts: 822
Joined: Wednesday 12 November 2014 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest b
Contact:

Re: error with an os command is dzvents

Post by pvklink »

Yes, it works!
Yeeeee, is was searching my as@@@@ off, for this...one character...
Raspberry (raspbian on rpi 3) , Domoticz Beta, dzVents , RFXtrx433e, P1, Hue, Yeelight, Zwave+, X10, ESP(easy), MQTT,Weather Underground, System Alive Checker, Domoticz Remote Server to RPI with Google Assistant,
Jablotron connection, Ikea
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest