Run bash file on startup

Kernels & Hardware, configuring network, installing services

Run bash file on startup

Postby ronp20 » 2018-04-30 09:55

Hello.
I put some file with .sh suffix in /etc/init.d folder.
how do i run this file on startup?
ronp20
 
Posts: 7
Joined: 2018-04-30 07:34

Re: Run bash file on startup

Postby tsmith3480 » 2018-04-30 11:15

I find the easiest way to run a script at startup is to add an entry into crontab.

Run:
Code: Select all
crontab -e

Then add a line at the end:
@reboot /etc/init.d/yourscript.sh

Side note, depending on what this script does, I wouldn't put it in the init.d folder. This is typically used for scripts that start/stop or display the status of services running on your system. Generally speaking, I put scripts in /usr/bin.
tsmith3480
 
Posts: 4
Joined: 2018-04-16 11:20

Re: Run bash file on startup

Postby ronp20 » 2018-04-30 11:19

tsmith3480 wrote:I find the easiest way to run a script at startup is to add an entry into crontab.

Run:
Code: Select all
crontab -e

Then add a line at the end:
@reboot /etc/init.d/yourscript.sh

Side note, depending on what this script does, I wouldn't put it in the init.d folder. This is typically used for scripts that start/stop or display the status of services running on your system. Generally speaking, I put scripts in /usr/bin.


i cant use crontab
-sh: crontab: command not found
ronp20
 
Posts: 7
Joined: 2018-04-30 07:34

Re: Run bash file on startup

Postby tsmith3480 » 2018-04-30 11:43

Does...
Code: Select all
which crontab
or
Code: Select all
ps -ef | grep cron
give any results?

If not, you might have to install cron
Code: Select all
sudo apt-get install cron
tsmith3480
 
Posts: 4
Joined: 2018-04-16 11:20

Re: Run bash file on startup

Postby ronp20 » 2018-04-30 11:53

tsmith3480 wrote:Does...
Code: Select all
which crontab
or
Code: Select all
ps -ef | grep cron
give any results?

If not, you might have to install cron
Code: Select all
sudo apt-get install cron


i am running it on embedded software. is there any other way to run the bash without install anything new?
ronp20
 
Posts: 7
Joined: 2018-04-30 07:34

Re: Run bash file on startup

Postby tsmith3480 » 2018-04-30 12:38

Yes, you would have to follow this pattern:

https://debian-administration.org/artic ... ith_Debian
tsmith3480
 
Posts: 4
Joined: 2018-04-16 11:20

Re: Run bash file on startup

Postby ronp20 » 2018-04-30 13:53

tsmith3480 wrote:Yes, you would have to follow this pattern:

https://debian-administration.org/artic ... ith_Debian


it is not working
ronp20
 
Posts: 7
Joined: 2018-04-30 07:34

Re: Run bash file on startup

Postby None1975 » 2018-04-30 14:35

ronp20 wrote:it is not working

Because this is a very old manual. Currently Debian uses systemd as init system. Please, check this and this. Good luck.
User avatar
None1975
 
Posts: 429
Joined: 2015-11-29 18:23
Location: Lithuania, Vilnius

Re: Run bash file on startup

Postby reinob » 2018-04-30 19:07

ronp20 wrote:Hello.
I put some file with .sh suffix in /etc/init.d folder.
how do i run this file on startup?


Easiest is to put your command in /etc/rc.local
If you're using systemd, makesure you run "systemctl enable rc-local".

If your program is not critical for startup make sure rc.local ends with "exit 0"
reinob
 
Posts: 539
Joined: 2014-06-30 11:42

Re: Run bash file on startup

Postby debiman » 2018-05-01 15:28

ronp20 wrote:i am running it on embedded software. is there any other way to run the bash without install anything new?

ronp20 wrote:it is not working

both these statements require a lot of additional information.
please provide it.
we can only see what you tell us.
User avatar
debiman
 
Posts: 2209
Joined: 2013-03-12 07:18


Return to System configuration

Who is online

Users browsing this forum: No registered users and 7 guests

fashionable