executeCommandLine, mv is working cp not

Hi,

really really sorry about it, but i do not find the error.

Anyone an idea why the second “cp” is not working while the “mkdir” is working?

var Exec = Java.type('org.openhab.core.model.script.actions.Exec');
Exec.executeCommandLine("/usr/bin/mkdir","/openhab/userdata/logs_saved/" + BackupFolderName);
Exec.executeCommandLine("/usr/bin/cp","/openhab/userdata/logs/*", "/openhab/userdata/logs_saved/" + BackupFolderName + "/");

Merci!

See How to use executeCommandLine and pay attention to the first few replies as well.

tl;dr if you don’t know why an executeCommandLine isn’t working, log out what the command is returning.

Note, if this is JS Scripting and not Nashorn the code should be (complete with a duration so it returns the output of the command): JavaScript Scripting - Automation | openHAB

console.info(actions.Exec.executeCommandLine(time.Duration.ofSeconds(1), "/usr/bin/mkdir","/openhab/userdata/logs_saved/" + BackupFolderName));
console.info(actions.Exec.executeCommandLine(time.Duration.ofSeconds(1), "/usr/bin/cp","/openhab/userdata/logs/*", "/openhab/userdata/logs_saved/" + BackupFolderName + "/");

If the problem isn’t a permission problem, when you do not give executeCommandLine a Duration as the first argument, it returns before the command completes. I bet that the mkdir hasn’t completed when the cp command is run and therefore the folder doesn’t exist yet.

Hi,

sorry for the very late answer.
What really helped me is adding the timeout to get the return values.

For the copy itself it is really a bit strange.
I can create the file but if i do an “ls” I just can see the UID file and no foders.

BR
/Franz

Try

Exec.executeCommandLine("/usr/bin/cp","-R","/openhab/userdata/logs", "/openhab/userdata/logs_saved/" + BackupFolderName);
1 Like

Thanks @Oliver2 , that worked great!