You are not logged in.

#1 2013-02-12 14:39:22

JaysonWonder
Member
Registered: 2013-02-09
Posts: 13

Running A Startup Script As Root...Safely

Hello,

My issue is how to automate / run the commad at boot time safely. I am logging is as a user not as root.


sudo su
sudo echo -n c>>/sys/devices/platform/i8042/serio1/flags

It is a question of where and how to run it from considering i have no rc.local and apparently I shoud be using the newer method(systemd..??). I have tried running a script from .config/autostart with no success.

Where best can I run this at boot from as SU:
sudo echo -n c>>/sys/devices/platform/i8042/serio1/flags

Thanks,

Offline

#2 2013-02-12 14:42:48

kaszak696
Member
Registered: 2009-05-26
Posts: 543

Re: Running A Startup Script As Root...Safely


'What can be asserted without evidence can also be dismissed without evidence.' - Christopher Hitchens
'There's no such thing as addiction, there's only things that you enjoy doing more than life.' - Doug Stanhope
GitHub Junkyard

Offline

#3 2013-02-12 15:10:52

JaysonWonder
Member
Registered: 2013-02-09
Posts: 13

Re: Running A Startup Script As Root...Safely


Thanks for the wiki link. I have reviewed this. I still really don't understand. Is it a tmp file I want? I mean there has got to be simple clear method that will work for a newbie?

A little guidance will help so I can learn for the future.

Any help is appreciated.

Offline

#4 2013-02-12 15:14:30

kaszak696
Member
Registered: 2009-05-26
Posts: 543

Re: Running A Startup Script As Root...Safely

w /sys/devices/platform/i8042/serio1/flags - - - - c

Should do it, i guess, if the file is empty.

Last edited by kaszak696 (2013-02-12 15:16:25)


'What can be asserted without evidence can also be dismissed without evidence.' - Christopher Hitchens
'There's no such thing as addiction, there's only things that you enjoy doing more than life.' - Doug Stanhope
GitHub Junkyard

Offline

#5 2013-02-12 15:26:01

alphaniner
Member
From: Ancapistan
Registered: 2010-07-12
Posts: 2,604

Re: Running A Startup Script As Root...Safely

JaysonWonder wrote:

I still really don't understand. Is it a tmp file I want? I mean there has got to be simple clear method that will work for a newbie?

I was kind of 'put off' by tmpfiles too at first, the name implying to me it was solely for /tmp or other tmpfs.  Once you get past that, tmpfiles is incredibly simple, clear, and convenient.

Last edited by alphaniner (2013-02-12 15:27:02)


But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner

Offline

#6 2013-02-12 16:38:55

JaysonWonder
Member
Registered: 2013-02-09
Posts: 13

Re: Running A Startup Script As Root...Safely

kaszak696 wrote:
w /sys/devices/platform/i8042/serio1/flags - - - - c

Should do it, i guess, if the file is empty.

So if I understand correctly I need to put the code you said in a temp file? What are you suggesting should be empty, I guess I am confused. I will re-read the wiki and see what I better understand.

Offline

#7 2013-02-12 16:48:55

JaysonWonder
Member
Registered: 2013-02-09
Posts: 13

Re: Running A Startup Script As Root...Safely

Solved!!! Thanks, I went back and review the wiki and understand that tmp file concept and it is working as it should. Thanks for the support!

Offline

#8 2013-02-12 21:03:26

JaysonWonder
Member
Registered: 2013-02-09
Posts: 13

Re: Running A Startup Script As Root...Safely

Actually I may have spoken too early. It works but if I close my laptop lid or it hibernates when I log back in the settings are lost. Does this make sense, how could I force this all the time?

Thanks,

Offline

#9 2013-02-12 21:39:36

skanky
Member
From: WAIS
Registered: 2009-10-23
Posts: 1,838

Re: Running A Startup Script As Root...Safely

If you're using acpid you could put the call in the resume events in the handler script (or similar if using a different method to handle those events).
Seems untidy having to put it in two places, though.


"...one cannot be angry when one looks at a penguin."  - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle

Offline

#10 2013-02-13 00:34:48

JaysonWonder
Member
Registered: 2013-02-09
Posts: 13

Re: Running A Startup Script As Root...Safely

hmmm
sounds tough / scary any tips how to get started? Don't really want it in 2 spots

Offline

#11 2013-02-13 09:24:37

skanky
Member
From: WAIS
Registered: 2009-10-23
Posts: 1,838

Re: Running A Startup Script As Root...Safely

I don't run it any more so can only really point you to this: https://wiki.archlinux.org/index.php/Acpid


However, if you don't run acpid, you can hook to resume in systemd - https://wiki.archlinux.org/index.php/Sy … leep_hooks

There may be a way to tie tmpfiles into those hooks. I have had a quick look at this in the past and the method that immediately springs to mind is to create a resume service file that calls systemd-tmpfiles that triggers your tmpfile.

See "man systemd-tmpfiles" for how that works (it looks pretty simple), and the wiki entry above.

Last edited by skanky (2013-02-13 09:25:03)


"...one cannot be angry when one looks at a penguin."  - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle

Offline

#12 2013-02-13 14:48:02

JaysonWonder
Member
Registered: 2013-02-09
Posts: 13

Re: Running A Startup Script As Root...Safely

Ok I will give this a shot. I am reading wiki, it kinda makes sense but I will play around and see if it will actually work.

Offline

#13 2013-02-13 15:05:08

skanky
Member
From: WAIS
Registered: 2009-10-23
Posts: 1,838

Re: Running A Startup Script As Root...Safely

Good luck. smile


"...one cannot be angry when one looks at a penguin."  - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle

Offline

#14 2013-02-14 12:56:06

JaysonWonder
Member
Registered: 2013-02-09
Posts: 13

Re: Running A Startup Script As Root...Safely

Hi,

Just looking at a bit more info on this. I decided to make a script /etc/systemd/system-sleep/disable-tap-touchpad.sh with the following line in it:

w /sys/devices/platform/i8042/serio1/flags - - - - c

I have mande it executable but no joy.

I am not sure if I need to add other systax to make this work or if this is what they mean when describing making the hook.

It seems a bit confusing any thoughts?

Offline

#15 2013-02-14 13:29:08

skanky
Member
From: WAIS
Registered: 2009-10-23
Posts: 1,838

Re: Running A Startup Script As Root...Safely

That's a temp file, not a script. If you're going to use a script you need:

#!/bin/bash
echo -n c>>/sys/devices/platform/i8042/serio1/flags

Though you probably want to flesh that out a little - only run the line if $1 is "post" and maybe echo some message to appear in the journal.


"...one cannot be angry when one looks at a penguin."  - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle

Offline

#16 2013-02-14 14:23:59

JaysonWonder
Member
Registered: 2013-02-09
Posts: 13

Re: Running A Startup Script As Root...Safely

Ok, that is exactly what I was thinking, hmmm I just don't know scripting. I know that I need to it after (post). I will play around but there are other arguments that need to be passed. Just having a hard time finding any other examples aside from the wiki page.

I just don't see why I need an if or case function. I mean the desired result is to run that script always when coming from sleep / hibernate therefore always post. I am really sorry for struggling, I am learing about this as I go plus there is no man page as the wiki indicates. man system-sleep offers nothing so I feel like I am working in the dark.

Last edited by JaysonWonder (2013-02-14 14:35:57)

Offline

#17 2013-02-14 14:44:29

skanky
Member
From: WAIS
Registered: 2009-10-23
Posts: 1,838

Re: Running A Startup Script As Root...Safely

The script is run both going into suspend/hibernation and coming out. To distinguish which event is occurring, two parameters are passed in. I assume that the operation you're doing (I haven't looked up what it is) only needs to be done on coming out of hibernation. It may be that there's no problem issuing it going in, but there may be a side-effect, so it's probably best to only commit it coming out.

#!/bin/bash
if [[ "$1" = "post" ]]; then
    echo "Waking from $2, applying 18042 flag update..."
    echo -n c>>/sys/devices/platform/i8042/serio1/flags
fi

I should appear in the journal (see the wiki for the command). If not, you could put an echo statement outside the if statement to help debug.

Make it executable.


"...one cannot be angry when one looks at a penguin."  - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle

Offline

#18 2013-02-14 14:47:54

JaysonWonder
Member
Registered: 2013-02-09
Posts: 13

Re: Running A Startup Script As Root...Safely

Do you think this syntax would work. I am just reading about bash but do not wanna break my machine

#!/bin/bash
case "$1" in
'pre')
  echo "Do nothing going to sleep"
;;

'post')
  echo -n c>>/sys/devices/platform/i8042/serio1/flags
;;
esac

Offline

#19 2013-02-14 15:02:52

skanky
Member
From: WAIS
Registered: 2009-10-23
Posts: 1,838

Re: Running A Startup Script As Root...Safely

Yeah, looks fine to me.
You can test it by calling it yourself:

$ sudo /usr/lib/systemd/system-sleep/yourscript.sh "pre"
$ sudo /usr/lib/systemd/system-sleep/yourscript.sh "post"
$ sudo /usr/lib/systemd/system-sleep/yourscript.sh "somethingelse"
$ sudo /usr/lib/systemd/system-sleep/yourscript.sh ""

You may want to put a message echo in the post section, so it appears in the journal.
That way also, when testing you can comment out the line that actually does the job and just see what messages get displayed.


"...one cannot be angry when one looks at a penguin."  - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle

Offline

#20 2013-02-14 16:48:18

JaysonWonder
Member
Registered: 2013-02-09
Posts: 13

Re: Running A Startup Script As Root...Safely

Great suggestions, I have tested and indeed everything is working well and I learned a fair bit working though it. I truly appreciate your support!!

Offline

#21 2013-02-14 16:53:30

skanky
Member
From: WAIS
Registered: 2009-10-23
Posts: 1,838

Re: Running A Startup Script As Root...Safely

That's great to hear. I learned some stuff too, so win win. wink


"...one cannot be angry when one looks at a penguin."  - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle

Offline

Board footer

Powered by FluxBB