[SOLVED] My Exec commands do not work


(Juan) #1

Hi there,

I use the following commands, one for get the IP and aother one for backup. But I do not get they work.

rule "IP"
when Time cron "0 0/10 * 1/1 * ? *"
then
var String ippublic = executeCommandLine("dig@@+short@@myip.opendns.com@@@resolver1.opendns.com",5000)
postUpdate(ip_net,ippublic)
end
rule "Backup"
when Time cron "0 0 12 1/1 * ? *"
then
logInfo("RULE","BACKUP")
executeCommandLine("sudo@@influxd@@backup@@-portable@@/mnt/", 5000)
end

I have the binding properly installed.

the Sudoers is like this:

openhab ALL=(ALL) NOPASSWD: /bin/ip, /bin/bash, /usr/bin/ssh, /var/lib/, /etc/openhab2/scripts, /bin

I do not know what I am missing.


(CM6.5 H102) #2

Me either, but anyone wanting to help might be missing your Things and Items file.:wink:

A few minutes reading this post might save you, and someone trying to help, a little bit of time.


(Rich Koshak) #3

I’m pretty sure you can’t just give sudoer permissions to all the binaries in a folder. You have to list each binary individually.

Given that, I see that you are trying to run influxdb with sudo but influxdb is not in the list.

For the second one, are you sure that dig is installed? I know it isn’t installed by default on raspbian.

Logs would be a lot of help.

Actually since he is using the executeCommandLine action, there are no Things or Items that are relevant to the problem.


(Juan) #4

Well, actually I am asking about Exec binding, Things files does not have anything to do with this questions or Items list because, the issue is that the Exec command does not execute. However, Items works fine, and Things files is empty.

The issue is with some permissions or sudoers, I do not know, I am not very good in Linux. Always I am confused with permisions.

Dig is installed, and works fine on the terminal.

DiG 9.10.3-P4-Raspbian

What you mean with “you have to list each binary individually” I have to type one line? I thought I could put everything separated by ,

For me, influsd only works with sudo, not without

[21:35:31] openhabian@openhabianpi:~$ influxd backup -portable /mnt/
2018/12/07 21:35:44 backing up metastore to /mnt/meta.00
backup: open temp file: open /mnt/meta.00.pending: permission denied
[21:35:49] openhabian@openhabianpi:~$ sudo influxd backup -portable /mnt/
2018/12/07 21:35:57 backing up metastore to /mnt/meta.00
2018/12/07 21:35:57 No database, retention policy or shard ID given. Full meta store backed up.
2018/12/07 21:35:57 Backing up all databases in portable format
2018/12/07 21:35:57 backing up db=
2018/12/07 21:35:57 backing up db=_internal rp=monitor shard=1 to /mnt/_internal.monitor.00001.00 since 0001-01-01T00:00:00Z
2018/12/07 21:35:57 backing up db=_internal rp=monitor shard=3 to /mnt/_internal.monitor.00003.00 since 0001-01-01T00:00:00Z
2018/12/07 21:35:58 backing up db=_internal rp=monitor shard=4 to /mnt/_internal.monitor.00004.00 since 0001-01-01T00:00:00Z
2018/12/07 21:35:58 backing up db=openhab_db rp=autogen shard=2 to /mnt/openhab_db.autogen.00002.00 since 0001-01-01T00:00:00Z
2018/12/07 21:35:58 backup complete:
2018/12/07 21:35:58 	/mnt/20181207T203557Z.meta
2018/12/07 21:35:58 	/mnt/20181207T203557Z.s1.tar.gz
2018/12/07 21:35:58 	/mnt/20181207T203557Z.s3.tar.gz
2018/12/07 21:35:58 	/mnt/20181207T203557Z.s4.tar.gz
2018/12/07 21:35:58 	/mnt/20181207T203557Z.s2.tar.gz
2018/12/07 21:35:58 	/mnt/20181207T203557Z.manifest
[21:35:58] openhabian@openhabianpi:~$ 


(Rich Koshak) #5

The path to the influxdb command is not in the list and you have directories in the list. You can’t grant sudo permission to all the files in /var/lib. You have to list each file in /var/lib that you want to grant sudo permissions to individually.


(Juan) #6

I do not know exactly what I have to put:

In terminal, this is working for me, bt though openhab not

dig +short myip.opendns.com@resolver1.opendns.com

this too:

sudo influxd backup -portable /mnt/

I have changed sudoers like this, but nothing change::slight_smile:

# User privilege specification
root    ALL=(ALL:ALL) ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d
openhab ALL=(ALL) NOPASSWD: /bin/ip, /bin/bash, /usr/bin/ssh, /var/lib/influxdb, /bin

(Juan) #7

Solved.

I added the following:

/usr/bin/dig, /usr/bin/influxd

I have assigned permisions to all users to the MTN folder.
It works fine.


Regarding this:

var String ippublic = executeCommandLine("dig@@+short@@myip.opendns.com@@@resolver1.opendns.com",5000)
postUpdate(ip_net,ippublic)

Keep on working.

These senteces work fine:

var String ipplex = executeCommandLine("ssh@@server@192.168.2.121@@dig@@+short@@myip.opendns.com@@@resolver1.opendns.co$
postUpdate(ip_plex,ipplex)
var String loplex = executeCommandLine("ssh@@server@192.168.2.121@@/usr/local/bin/wget@@-qO-@@ipinfo.io/city",5000)
postUpdate(lo_plex,loplex)

Items:

String ip_plex "IP-VPN [%s]"
String lo_plex "VPN CITY [%s]"
String ip_net "IP-PUBLIC [%s]"

(Juan) #8

OK, I do not know why is not working. I have solved the issue, creating an IP.sh file, and write the sentence over there. Like this is working.

Thanks and regards.