The officially official Devuan Forum!

You are not logged in.

#1 2018-11-14 20:47:39

alphalpha
Member
From: Germany
Registered: 2018-01-23
Posts: 137  

Autorun a script at boot

Hey Guys,
i want to run a script each time my computer boots up

problem is since i compiled a new kernel, my screen backlight will go very dark once open-rc starts booting up
i tried the bootloader thing that people suggest on the internet but it only works randomly sometimes

so i wrote this short script that i want to execute with root rights during startup

brightness="/sys/class/backlight/intel_backlight/brightness"
if [[ -f $brightness ]] && [[ "$(cat $brightness)" != "3000" ]]; then
tee $brightness <<< 3000
fi

i tried to add it into /etc/rc.local but that does nothing...
any ideas how to make it work?

Offline

#2 2018-11-14 22:46:22

yeti
Member
From: I'm not here: U R halucinating
Registered: 2017-02-23
Posts: 304  

Re: Autorun a script at boot

Translate all BASHisms to standard SH because:

$ head -1 /etc/rc.local 
#!/bin/sh -e          

<πš‹πš˜πšπš’ πš˜πš—πš•πš˜πšŠπš='πšπš˜πšŒπšžπš–πšŽπš—πš.πš‹πš˜πšπš’.πš’πš—πš—πšŽπš›π™·πšƒπ™Όπ™»="π™³πš’πšœπšŠπš‹πš•πšŽ π™Ήπš‚!";'>
π”“π”©π”’π”žπ”°π”’ π”©π”’π”žπ”³π”’ 𝔢𝔬𝔲𝔯 π”£π”žπ”²π”©π”±π”° 𝔦𝔫 𝔱π”₯𝔒 𝔰𝔒𝔠𝔱𝔦𝔬𝔫 π”Ÿπ”’π”©π”¬π”΄ π”žπ”«π”‘ 𝔑𝔬𝔫'𝔱 𝔣𝔬𝔯𝔀𝔒𝔱 𝔱𝔬 π”²π”«π”°π”²π”Ÿπ”°π” π”―π”¦π”Ÿπ”’!

Offline

#3 2018-11-15 00:22:31

arnaiz
Member
From: Leon
Registered: 2018-10-28
Posts: 28  
Website

Re: Autorun a script at boot

For me that script its fine, so try to guest when and who are running /etc/rc.local

I suggest put something like this on your /etc/rc.local to debug your startup:

date >> /var/log/rc.local.test

if the file its not created, maybe its because /etc/rc.local hasnt execution permissions.

Offline

#4 2018-11-15 00:37:30

yeti
Member
From: I'm not here: U R halucinating
Registered: 2017-02-23
Posts: 304  

Re: Autorun a script at boot

(yeti@kumari:23)/tmp$ cat -n meep.sh 
     1  #!/bin/sh -e
     2  
     3  if [[ 1 = 1 ]] ; then
     4          echo 'boo!'
     5  fi
     6  
     7  tee <<< Moo.
(yeti@kumari:23)/tmp$ ./meep.sh 
./meep.sh: 3: ./meep.sh: [[: not found
./meep.sh: 7: ./meep.sh: Syntax error: redirection unexpected

<πš‹πš˜πšπš’ πš˜πš—πš•πš˜πšŠπš='πšπš˜πšŒπšžπš–πšŽπš—πš.πš‹πš˜πšπš’.πš’πš—πš—πšŽπš›π™·πšƒπ™Όπ™»="π™³πš’πšœπšŠπš‹πš•πšŽ π™Ήπš‚!";'>
π”“π”©π”’π”žπ”°π”’ π”©π”’π”žπ”³π”’ 𝔢𝔬𝔲𝔯 π”£π”žπ”²π”©π”±π”° 𝔦𝔫 𝔱π”₯𝔒 𝔰𝔒𝔠𝔱𝔦𝔬𝔫 π”Ÿπ”’π”©π”¬π”΄ π”žπ”«π”‘ 𝔑𝔬𝔫'𝔱 𝔣𝔬𝔯𝔀𝔒𝔱 𝔱𝔬 π”²π”«π”°π”²π”Ÿπ”°π” π”―π”¦π”Ÿπ”’!

Offline

#5 2018-11-15 00:51:02

arnaiz
Member
From: Leon
Registered: 2018-10-28
Posts: 28  
Website

Re: Autorun a script at boot

#!/bin/sh -e

It seems there is the problem, I was running under bash.

Offline

#6 2018-11-15 11:25:40

alphalpha
Member
From: Germany
Registered: 2018-01-23
Posts: 137  

Re: Autorun a script at boot

Translate all BASHisms to standard SH because:

I tried it with just

brightness="/sys/class/backlight/intel_backlight/brightness"
tee $brightness <<< 3000

but that didn't work, i guess im terrible with SH

anyway i solved the problem by changing the rc.local from #!/bin/sh -e to #!/usr/bin/zsh   wink
thx guys

Offline

#7 2018-11-15 11:38:49

ilargi
Member
Registered: 2017-06-23
Posts: 11  

Re: Autorun a script at boot

Try this:

brightness="/sys/class/backlight/intel_backlight/brightness"
if [ -f $brightness ] && [ "$(cat $brightness)" != "3000" ]; then
        echo 3000 > $brightness

fi

Edit: Corrected code error.

Last edited by ilargi (2018-11-15 12:29:35)

Offline

#8 2018-11-15 11:45:54

yeti
Member
From: I'm not here: U R halucinating
Registered: 2017-02-23
Posts: 304  

Re: Autorun a script at boot

Try...

echo 3000 > $brightness

Such "tee" tricks typically are used because "sudo echo something >somewhere" still does the output redirection as the calling user because the redirection is done before "sudo" is run. "sudo tee somewhere" writes with "root" rights to "somewhere"  because "tee" opens "somewhere" and that happens with "root" superpowers due to "sudo". This all does not really matter in "rc.local" because the whole script already runs with "root" rights.

Switching the interpreter of "rc.local" to "/usr/bin/zsh" is not a good idea because "zsh" is not an essential package. System scripts should use "/bin/sh".

But ok: It's your system.


<πš‹πš˜πšπš’ πš˜πš—πš•πš˜πšŠπš='πšπš˜πšŒπšžπš–πšŽπš—πš.πš‹πš˜πšπš’.πš’πš—πš—πšŽπš›π™·πšƒπ™Όπ™»="π™³πš’πšœπšŠπš‹πš•πšŽ π™Ήπš‚!";'>
π”“π”©π”’π”žπ”°π”’ π”©π”’π”žπ”³π”’ 𝔢𝔬𝔲𝔯 π”£π”žπ”²π”©π”±π”° 𝔦𝔫 𝔱π”₯𝔒 𝔰𝔒𝔠𝔱𝔦𝔬𝔫 π”Ÿπ”’π”©π”¬π”΄ π”žπ”«π”‘ 𝔑𝔬𝔫'𝔱 𝔣𝔬𝔯𝔀𝔒𝔱 𝔱𝔬 π”²π”«π”°π”²π”Ÿπ”°π” π”―π”¦π”Ÿπ”’!

Offline

#9 2018-11-15 11:51:49

yeti
Member
From: I'm not here: U R halucinating
Registered: 2017-02-23
Posts: 304  

Re: Autorun a script at boot

ilargi wrote:

Try this:

brightness="/sys/class/backlight/intel_backlight/brightness"
if [ -f $brightness ] && [ "$(cat $brightness)" != "3000" ]; then
	tee $brightness 3000
fi
	tee $brightness 3000

...will wait for input instead of writing "3000" to the desired location. And create a file named "3000".

Can you please try your code before publishing it?


<πš‹πš˜πšπš’ πš˜πš—πš•πš˜πšŠπš='πšπš˜πšŒπšžπš–πšŽπš—πš.πš‹πš˜πšπš’.πš’πš—πš—πšŽπš›π™·πšƒπ™Όπ™»="π™³πš’πšœπšŠπš‹πš•πšŽ π™Ήπš‚!";'>
π”“π”©π”’π”žπ”°π”’ π”©π”’π”žπ”³π”’ 𝔢𝔬𝔲𝔯 π”£π”žπ”²π”©π”±π”° 𝔦𝔫 𝔱π”₯𝔒 𝔰𝔒𝔠𝔱𝔦𝔬𝔫 π”Ÿπ”’π”©π”¬π”΄ π”žπ”«π”‘ 𝔑𝔬𝔫'𝔱 𝔣𝔬𝔯𝔀𝔒𝔱 𝔱𝔬 π”²π”«π”°π”²π”Ÿπ”°π” π”―π”¦π”Ÿπ”’!

Offline

#10 2018-11-15 12:31:27

ilargi
Member
Registered: 2017-06-23
Posts: 11  

Re: Autorun a script at boot

I stand corrected.
Changed code in original message.

Offline

#11 2018-11-15 14:06:12

yeti
Member
From: I'm not here: U R halucinating
Registered: 2017-02-23
Posts: 304  

Re: Autorun a script at boot

ilargi wrote:

Changed code in original message.

Thanks!


<πš‹πš˜πšπš’ πš˜πš—πš•πš˜πšŠπš='πšπš˜πšŒπšžπš–πšŽπš—πš.πš‹πš˜πšπš’.πš’πš—πš—πšŽπš›π™·πšƒπ™Όπ™»="π™³πš’πšœπšŠπš‹πš•πšŽ π™Ήπš‚!";'>
π”“π”©π”’π”žπ”°π”’ π”©π”’π”žπ”³π”’ 𝔢𝔬𝔲𝔯 π”£π”žπ”²π”©π”±π”° 𝔦𝔫 𝔱π”₯𝔒 𝔰𝔒𝔠𝔱𝔦𝔬𝔫 π”Ÿπ”’π”©π”¬π”΄ π”žπ”«π”‘ 𝔑𝔬𝔫'𝔱 𝔣𝔬𝔯𝔀𝔒𝔱 𝔱𝔬 π”²π”«π”°π”²π”Ÿπ”°π” π”―π”¦π”Ÿπ”’!

Offline

Board footer