bash command
Posted: Tuesday 07 March 2023 14:31
Hi,
I have the follwing script working. Is checks if there are file on a folder and if so , move them to another folder. Accept for file gelukt.txt and file that starts with XXX.
This scripts works and uses a bash script to move the files.
I tried to script the move command from the working bash script in this script (see REMARK 1-3) but that didnt work.
Can you help ?
I have the follwing script working. Is checks if there are file on a folder and if so , move them to another folder. Accept for file gelukt.txt and file that starts with XXX.
This scripts works and uses a bash script to move the files.
I tried to script the move command from the working bash script in this script (see REMARK 1-3) but that didnt work.
Can you help ?
Code: Select all
local timer_overdag = 'every 15 minutes between 06:20 and 23:50 on mon,tue,wed,thu,fri,sat,sun'
return {
on = {
timer = {timer_overdag},
devices = {'filecopy'},
},
execute = function(dz,item,info)
local sourceDir = '/mnt/mymotion'
local targetDir = '/mnt/nasdata'
function exec_os(cmd)
local f = assert(io.popen(cmd, 'r'))
s = assert(f:read('*a'))
f:close()
return tonumber(s)
end
if (item.isDevice and item.name == 'filecopy' and item.state == 'On') or (item.isTimer and item.trigger == timer_overdag) then
cmd='ls /mnt/myimages -I gelukt.txt | wc -l'
if exec_os(cmd) > 0 then
dz.devices('motion files aanwezig').switchOn().checkFirst()
-- REMARK 1. NOW IN BASHSCRIPT --> find $sourceDir -type f -not -name "xxx*" -and -not -name "gelukt.txt" -exec mv {} $targetDir \;
-- REMARK 2. TRY TO EXECUTE ABOVE CMD FROM THIS SCRIPT --> cmd="find " .. sourceDir .. " -type f -not -name " .. '"xxx*"' .. " -and -not -name " .. '"gelukt.txt"' .. " -exec mv {} " .. targetDir .. " \;"
-- REMARK 3. DOES NOT WORK, SO USE THE BASH SCRIPT INSTEAD, see below cmd. In this bashscript line 1. is used
cmd="/opt/domoticz/userdata/filecopy.sh filecopy"
exec_os(cmd)
else
dz.devices('motion files aanwezig').switchOff().checkFirst()
end
dz.devices('filecopy').switchOff().afterSec(5)
end
end
}