2 scripts in Crontab

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
NetEye
Posts: 34
Joined: Friday 17 June 2016 7:57
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Spijkenisse
Contact:

2 scripts in Crontab

Post by NetEye »

I have 2 scripts entered in pi@raspberrypi:~$ cd domoticz/scripts
free-mem.sh (28 6,23 * * * /domoticz/scripts/free-mem.sh)
domoticz_state_checker.sh (*/1 * * * * /domoticz/scripts/domoticz_state_checker.sh)
Can I run both in Crontab?
# m h dom mon dow command
28 6,23 * * * /domoticz/scripts/free-mem.sh && */1 * * * * /domoticz/scripts/domoticz_state_checker.sh
or
# m h dom mon dow command
28 6,23 * * * /domoticz/scripts/free-mem.sh & */1 * * * * /domoticz/scripts/domoticz_state_checker.sh &
or
# m h dom mon dow command
28 6,23 * * * /domoticz/scripts/free-mem.sh & */1 * * * * /domoticz/scripts/domoticz_state_checker.sh
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: 2 scripts in Crontab

Post by EddyG »

Just put in 2 lines. I suppose that it is the user crontab?
B.t.w */1 is just the same as only *

Code: Select all

28 6,23 * * * /domoticz/scripts/free-mem.sh
*/1 * * * * /domoticz/scripts/domoticz_state_checker.sh
NetEye
Posts: 34
Joined: Friday 17 June 2016 7:57
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Spijkenisse
Contact:

Re: 2 scripts in Crontab

Post by NetEye »

Dear Eddy,
From the $ when I log on the rpi I typ:
Sudo crontab -e
From this I think there is more then one.
What is the place to put those scripts in ( now they are both in sudo crontab -e).
I googled for the right place for crontab, what is the normal path for crontab (user crontab??) ?
( /home/pi/domoticz/scripts ?)
Thanks for your time, super
Regards
Jan Bekelaar
User avatar
philchillbill
Posts: 396
Joined: Monday 12 September 2016 13:47
Target OS: Linux
Domoticz version: beta
Location: Eindhoven. NL
Contact:

Re: 2 scripts in Crontab

Post by philchillbill »

Where the crontab file resides is actually irrelevant to the user. As long as any commands mentioned in your crontab have the correct paths all will be OK. Be aware that crontab jobs do run with a rather limited environment for path variables and such. Permissions can also be an issue sometimes. If something doesn't work as sudo crontab try the same thing as your own user crontab and it might just work !
Alexa skills author: EvoControl, Statereport, MediaServer, LMS-lite
NetEye
Posts: 34
Joined: Friday 17 June 2016 7:57
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Spijkenisse
Contact:

Re: 2 scripts in Crontab

Post by NetEye »

Thanks philchillbill, super info,
Can you please look at the following I entered as script (bleu and green).
And the entry in crontab -e in red
Can you search for what you said "limited environment for path variables and such and permissions can also be an issue"

You said If something doesn't work as sudo crontab try the same thing as your own user crontab and it might just work.
What do you mean with that, that is way I'am confused......another crontab ??

Please a little time of you to judge what I made and maybe you can tell me how to test it.
sudo ./free-mem.sh
sudo ./domoticz_state_checker.sh
Both entered in de script dir?
Thanks in advance

from pi@raspberrypi:~$ I entered: cd domoticz/scripts and then sudo nano free-mem.sh

#!/bin/bash
free -m
sync
sudo echo 3 > /proc/sys/vm/drop_caches
free -m


from pi@raspberrypi:~$ I entered: cd domoticz/scripts and then sudo nano domoticz_state_checker.sh

#!/bin/bash

DomoticzState=`sudo service domoticz.sh status`

if [[ $DomoticzState == *"active (running)"* ]]
then
echo 'Domoticz is running. Nothing to do.'
elif [[ $DomoticzState == *"inactive (dead)"* ]]
then
echo 'Domoticz is not running. Restarting Domoticz...'
sudo service domoticz.sh restart
echo 'Domoticz restarted.'
fi


sudo crontab -e

# m h dom mon dow command
28 6,23 * * * /domoticz/scripts/free-mem.sh
*/1 * * * * /domoticz/scripts/domoticz_state_checker.sh


the instead of */1 * * * * starts also every minute: * * * * * /domoticz/scripts/domoticz_state_checker.sh)
User avatar
philchillbill
Posts: 396
Joined: Monday 12 September 2016 13:47
Target OS: Linux
Domoticz version: beta
Location: Eindhoven. NL
Contact:

Re: 2 scripts in Crontab

Post by philchillbill »

You probably need to specify a full path to where those scripts are located, so

# m h dom mon dow command
28 6,23 * * * /home/pi/domoticz/scripts/free-mem.sh
*/1 * * * * /home/pi/domoticz/scripts/domoticz_state_checker.sh

assuming your user is indeed 'pi'. You can cd into the scripts directory and do 'pwd' to see the full path name of where you are to check this.

Also, be sure to chmod +x both scripts to make sure they are executable. Then you should be good to go !
Alexa skills author: EvoControl, Statereport, MediaServer, LMS-lite
NetEye
Posts: 34
Joined: Friday 17 June 2016 7:57
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Spijkenisse
Contact:

Re: 2 scripts in Crontab

Post by NetEye »

Dear philchillbill,
Thanks, those tips about in crontab 2 lines and that PWD command gave me the right place of the files, super!!
Indeed it was /home/pi/domoticz/scripts
Thanks again.
I have 2 small questions:
I did that chmod command.... is dooing it once after the file is made enough (when is the best moment)?
How do I know that averthing is working? Is there a command to enter when start Terminal or Putty or else?
When i go to the place of the file is (in this case) /home/pi/domoticz/scripts and type:
[pi@raspberrypi:~/domoticz/scripts$ sudo ./free-mem.sh and
sudo ./domoticz_state_checker.sh the scripts will run, but do they also when Domticz runs normal??
Regards
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest