<div dir="ltr">I hope this result will confirm that I have followed your instruction:<div><br></div><div>daryl@trieli:~$ ls -al /etc/sudoers.d/acpi<br>-r--r----- 1 root root 162 Sep 13 09:45 /etc/sudoers.d/acpi<br>daryl@trieli:~$ sudo cat /etc/sudoers.d/acpi<br>#instead of adding directly to sudoers file, this file was created<br><br>#mythtv,%mythtv ALL = NOPASSWD: /sbin/shutdown, /usr/bin/setwakeup.sh, /usr/bin/checklogin.sh<br><br>daryl@trieli:~$ ls -al /sbin/shutdown<br>lrwxrwxrwx 1 root root 14 Jul  6 17:38 /sbin/shutdown -> /bin/systemctl<br>daryl@trieli:~$ ls -al /usr/bin/setwakeup.sh<br>-r-xr-xr-x 1 root mythtv 1221 Sep 10 16:37 /usr/bin/setwakeup.sh<br>daryl@trieli:~$ ls -al /usr/bin/checklogin.sh<br>-r-xr-xr-x 1 root mythtv 1222 Sep 10 16:47 /usr/bin/checklogin.sh<br>daryl@trieli:~$ cat /usr/bin/setwakeup.sh<br>#!/bin/bash<br>#$1 is the first argument to the script. It is the time in seconds since 1970<br>#this is defined in mythtv-setup with the time_t argument<br><br>echo 0 > /sys/class/rtc/rtc0/wakealarm      #this clears your alarm.<br>echo $1 > /sys/class/rtc/rtc0/wakealarm     #this writes your alarm<br><br>LOG_FILE='/var/log/mythtv/hwclock-rebootTime.log' #log file<br><br># Now write the time the system is expected to come out of power save mode<br># so there is at least a small record of when if it was supposed to recover<br><br># Note:- Log file will just keep growing<br><br># date in Epoch format<br>a="`date  +%s`"<br><br># Subtract Current time from Future time<br>let "b=$1-$a"<br><br># echo $b<br># echo "result of time subtraction `date -d @$b`"<br><br># Get Date and Subtract 1,.. as date starts from 1st Jan 1970<br>dte=`date -d @$b +%d`<br>let "dte -= 1"<br><br>echo "Current Time      ->`date`" >> $LOG_FILE<br><br># Simple check to determine if to include days in output string<br>if (dte=0)<br>then<br>    echo "Shutting down for ->`date -d @$b +%Hhrs:%MMins`" >> $LOG_FILE<br>else<br>    echo "Shutting down for ->$[dte]Days `date -d @$b +%Hhrs:%MMins`" >> $LOG_FILE<br>fi<br><br>echo "Wake up at approx.->`date -d @$1`"  >> $LOG_FILE<br>echo "------------------------------------------------------" >> $LOG_FILE</div><div><br>daryl@trieli:~$ cat /usr/bin/checklogin.sh<br>#!/bin/bash<br># Check to see if anyone is currently logged in or if the machine was recently switched on.<br># Echoed text appears in log file. It can be removed and --quiet added to the <br># grep command once you are satisfied that mythTV is working properly.<br># Exit codes:-<br># 2 - Machine recently switched on, don't shut down.<br># 1 - A user is logged in, don't shut down.<br># 0 - No user logged in, OK to shut down.<br><br># Customizable variables<br>MIN_UPTIME=10   # Minimum up time in minutes<br># End of customizable variables<br><br># Get a date/time stamp to add to log output<br>DATE=`date +%F\ %T\.%N`<br>DATE=${DATE:0:23}<br><br>UPTIME=`cat /proc/uptime | awk '{print int($1/60)}'`<br><br>if [ "$UPTIME" -lt "$MIN_UPTIME" ]; then<br>    echo $DATE Machine uptime less than $MIN_UPTIME minutes, don\'t shut down.<br>    exit 2<br>fi<br><br># Some configurations ( at least lxdm + xfce4) do not report GUI-logged-on users<br># with "who" or "users".<br># pgrep tests if processes named xfce* exist<br><br>XFCE_PROCS=`pgrep xfce`<br><br>USERS=`who -q | tail -n 1 | sed 's/[a-z #]*=//'`<br><br>if [ "$USERS" == "0" ] && [ "$XFCE_PROCS" == "" ]; then<br>    echo $DATE No users are logged in, ok to shut down.<br>    exit 0<br>  else<br>    echo $DATE Someone is still logged in, don\'t shut down.<br>    exit 1<br>fi<br><br>daryl@trieli:~$ <br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Sep 13, 2020 at 1:42 AM Stephen Worthington <<a href="mailto:stephen_agent@jsw.gen.nz">stephen_agent@jsw.gen.nz</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Sat, 12 Sep 2020 16:38:11 -0400, you wrote:<br>
<br>
>Still no joy. When I ran "sudo visudo" the comments said "consider creating<br>
>a sudoers.d file" (or something similar) which I didn't because the wiki<br>
>saed add this to the end of the file. Should I try the former?<br>
<br>
visudo will only edit the /etc/sudoers file.  It is usually better<br>
just to create a new file under /etc/sudoers.d, as the /etc/sudoers<br>
file can be updated by package updates.  However, visudo does do basic<br>
sanity checks on your edits, which does not happen if you create a new<br>
/etc/sudoers.d file.  For a /etc/sudoers.d file to work, it needs to<br>
be owned by root and you need to remove all write privileges.  It is<br>
also important that any executable file or script you are listing in<br>
the sudoers.d file is also not writeable at all (or only writeable by<br>
root).  So when I created my /usr/local/bin/mythtv-systemctl-helper.sh<br>
script, I did this:<br>
<br>
sudo chown root:mythtv /usr/local/bin/mythtv-systemctl-helper.sh<br>
sudo chmod u=rx,g=rx /usr/local/bin/mythtv-systemctl-helper.sh<br>
<br>
Then I created a /etc/sudoers.d/mythtv-systemctl-helper file<br>
containing this:<br>
<br>
mythtv,%mythtv ALL=NOPASSWD:/usr/local/bin/mythtv-systemctl-helper.sh<br>
<br>
which says that the mythtv user or any user in the mythtv group<br>
(%mythtv) can run the mythtv-systemctl-helper.sh file with sudo<br>
without needing a password.  I did this:<br>
<br>
sudo chown root:root /etc/sudoers.d/mythtv-systemctl-helper<br>
sudo chmod u=r,g=r /etc/sudoers.d/mythtv-systemctl-helper<br>
<br>
to secure that file and make sudo accept it as valid.<br>
_______________________________________________<br>
mythtv-users mailing list<br>
<a href="mailto:mythtv-users@mythtv.org" target="_blank">mythtv-users@mythtv.org</a><br>
<a href="http://lists.mythtv.org/mailman/listinfo/mythtv-users" rel="noreferrer" target="_blank">http://lists.mythtv.org/mailman/listinfo/mythtv-users</a><br>
<a href="http://wiki.mythtv.org/Mailing_List_etiquette" rel="noreferrer" target="_blank">http://wiki.mythtv.org/Mailing_List_etiquette</a><br>
MythTV Forums: <a href="https://forum.mythtv.org" rel="noreferrer" target="_blank">https://forum.mythtv.org</a><br>
</blockquote></div>