You are not logged in.

#1 2015-09-12 13:08:52

Mr. Alex
Member
Registered: 2010-08-26
Posts: 623

[Solved] Perform as root commands in /usr/local/bin

Hello! In continuation of https://bbs.archlinux.org/viewtopic.php?id=202016 : I have "poweroff" file in /usr/local/bin with contents:

#!/bin/bash

if grep -qs 'mapper' /etc/mtab
then
    echo 'TrueCrypt volume is mounted!'
else
    hwclock --utc -w
    systemctl poweroff
fi

The problem is that "hwclock" program doesn't do its task because it needs root permissions to run. But the file itself has root owner and root group. And I also did "chmod +s" for that file. Still hwclock complains that I am not root and thus cannot perform this operation. AFAIK it should be done. As root. Where is my mistake?

Last edited by Mr. Alex (2015-09-12 15:09:24)

Offline

#2 2015-09-12 13:13:03

brebs
Member
Registered: 2007-04-03
Posts: 3,742

Re: [Solved] Perform as root commands in /usr/local/bin

Offline

#3 2015-09-12 13:20:57

Chazza
Wiki Maintainer
Registered: 2013-06-02
Posts: 506

Re: [Solved] Perform as root commands in /usr/local/bin

I think you might be able to accomplish this with sudo. Use visudo to add something like the following to /etc/sudoers:

username  ALL=(ALL) NOPASSWD:  hwclock

The call sudo hwclock from your script.

Last edited by Chazza (2015-09-12 13:22:30)

Offline

#4 2015-09-12 13:23:51

Mr. Alex
Member
Registered: 2010-08-26
Posts: 623

Re: [Solved] Perform as root commands in /usr/local/bin

So there's no simple way of configuring the system to allow what I want to do?

Offline

#5 2015-09-12 13:24:41

Mr. Alex
Member
Registered: 2010-08-26
Posts: 623

Re: [Solved] Perform as root commands in /usr/local/bin

Chazza, got your reply after my post #4. I'll try to do it now.

Offline

#6 2015-09-12 13:32:13

Mr. Alex
Member
Registered: 2010-08-26
Posts: 623

Re: [Solved] Perform as root commands in /usr/local/bin

My line for sudoers is now

alex   ALL=(ALL) NOPASSWD:hwclock

and it doesn't work:

sudo: parse error in /etc/sudoers near line 1

Can't figure out why. Everything looks correct.

Offline

#7 2015-09-12 13:39:43

Chazza
Wiki Maintainer
Registered: 2013-06-02
Posts: 506

Re: [Solved] Perform as root commands in /usr/local/bin

Just figured it out. It wants the full path to hwclock.

Offline

Board footer

Powered by FluxBB