Jump to content

I made a .sh file and put it under init.d but it doesnt execute. I suspect it is because it needs sudo access but i thought it would just ask me for the password. How can I run this script on startup?

I know it might not be secure, yeah vibecoding is cool but we shouldnt do smt unless we understand it and etc. thx but these disclaimers get old quick. maybe we shall be reminded frequently for we are stupid but i dont work at a nuclear powerplant.

Link to comment
https://linustechtips.com/topic/1601843-debian-execute-script-on-startup/
Share on other sites

Link to post
Share on other sites

/etc/crontab

@reboot root /root/sys/your_special_scrip.sh

 

script must be with at least with 700 permissions

 

/var/log/syslog shows errors if something goes wrong

 

p.s.

in this debug stage, you can try to run not after reboot, but

30 22    * * *   root   /root/sys/your_special_scrip.sh

(just after few minutes, and then inspect /var/log/syslog)

 

 

ad infinitum

Link to post
Share on other sites

9 minutes ago, ieleja said:

/etc/crontab

@reboot root /root/sys/your_special_scrip.sh

 

script must be with at least with 700 permissions

 

/var/log/syslog shows errors if something goes wrong

 

p.s.

in this debug stage, you can try to run not after reboot, but

30 22    * * *   root   /root/sys/your_special_scrip.sh

(just after few minutes, and then inspect /var/log/syslog)

 

 

well apaprently my script doesnt nee dsudo permission but when I deleted sudo it still doesnt work

 

I know it might not be secure, yeah vibecoding is cool but we shouldnt do smt unless we understand it and etc. thx but these disclaimers get old quick. maybe we shall be reminded frequently for we are stupid but i dont work at a nuclear powerplant.

Link to post
Share on other sites

17 hours ago, apoyusiken said:

and put it under init.d

Erm, stuff in /etc/init.d doesn't automatically get run, and will have to have start, stop, restart, and status (bare minimum) functions, and be started by your default runlevel. See if you have a /etc/local.d, putting your script in there as /etc/local.d/myscript.start and making sure it's executable (chmod gu+x /etc/local.d/myscript.start).

It really depends on your init system, if you are using sysvinit then just using

#!/bin/bash
start(){
/root/bin/myscript.sh &
exit 0
}
stop(){
killall myscript.sh
exit 0
}
status(){
ps -eo command|grep -q "^/root/bin/myscript.sh" && exit 0 || exit 1
}
restart(){
stop
sleep 1
start
}

Should be enough. System service files in /etc/init.d/ an /etc/systemd/ aren't really that complicated, and the "deamon supervisors" that are around do a really good job of keeping stuff that "doesn't background but needs to keep running" up and running. I think you need like 4 lines for a systemd service file to oneshot a script on boot.

Link to post
Share on other sites

5 hours ago, Ralphred said:

Erm, stuff in /etc/init.d doesn't automatically get run, and will have to have start, stop, restart, and status (bare minimum) functions, and be started by your default runlevel. See if you have a /etc/local.d, putting your script in there as /etc/local.d/myscript.start and making sure it's executable (chmod gu+x /etc/local.d/myscript.start).

It really depends on your init system, if you are using sysvinit then just using

#!/bin/bash
start(){
/root/bin/myscript.sh &
exit 0
}
stop(){
killall myscript.sh
exit 0
}
status(){
ps -eo command|grep -q "^/root/bin/myscript.sh" && exit 0 || exit 1
}
restart(){
stop
sleep 1
start
}

Should be enough. System service files in /etc/init.d/ an /etc/systemd/ aren't really that complicated, and the "deamon supervisors" that are around do a really good job of keeping stuff that "doesn't background but needs to keep running" up and running. I think you need like 4 lines for a systemd service file to oneshot a script on boot.

i just want to turn on rgb 😭

I know it might not be secure, yeah vibecoding is cool but we shouldnt do smt unless we understand it and etc. thx but these disclaimers get old quick. maybe we shall be reminded frequently for we are stupid but i dont work at a nuclear powerplant.

Link to post
Share on other sites

What do you run to "turn on rbg"?

I have debian VM, I'll run it up and "make it work" for you.

EDIT: I got bored. Cut and paste this into a terminal verbatim, as root:

echo "#/etc/systemd/system/rgb.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/root/bin/make_rgb_work.sh

[Install]
WantedBy=multi-user.target" >/etc/systemd/system/rgb.service;mkdir -p /root/bin;echo '#!/bin/bash
#insert your commands to start RGB below this line' >/root/bin/make_rgb_work.sh;chmod +x /root/bin/make_rgb_work.sh;nano /root/bin/make_rgb_work.sh;systemctl enable rgb.service;systemctl restart rgb.service

 

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×