0

OK, I'd like to implement some kind of 'child protection' for someone who acts like a child, to turn the computer off at night. I can easily put a shutdown command at 11pm in cron, but it's then easy to turn it back on.

I don't think it's possible to keep it off until the morning. Is it ? Any suggestion ? Put a shutdown command in the autostart that activates only at certain hours ?

1
  • 1
    Depends on how clever and experienced your child is. Everything can be surpassed eventually. I believe previous post(s) exists somewhere. WIll look it up... Jan 15, 2017 at 8:56

1 Answer 1

1

How about creating a simple script like this. I assume that the user you want to manage is called ADAM and that you want to prevent them logging on between 23:00 and 07:00 (note I only manage time to the nearest hour):

#!/bin/sh
user=ADAM
off_time=23
on_time=7

h=$(date +%H}
if [ $h -ge $on_time -a $h -lt $off_time ]; then
    # OK to use system
    passwd -u $USER
else
    # Outside permitted time
    # Prevent a login
    passwd -l $USER
    # and force them off the system
    pkill -KILL -u $USER
fi

(passwd -u allows a user to login, passwd -l disables their login)

I would then call this script every hour in /etc/crontab, and at startup in /etc/rc.local

(I haven't tested the above)

1
  • Interesting, I didn't know about the passwd -u / -l options.
    – dargaud
    Jan 16, 2017 at 14:48

Not the answer you're looking for? Browse other questions tagged or ask your own question.