Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Run bash file on startup

Linux Kernel, Network, and Services configuration.
Post Reply
Message
Author
ronp20
Posts: 7
Joined: 2018-04-30 07:34

Run bash file on startup

#1 Post by ronp20 »

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

tsmith3480
Posts: 4
Joined: 2018-04-16 11:20

Re: Run bash file on startup

#2 Post by tsmith3480 »

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.

ronp20
Posts: 7
Joined: 2018-04-30 07:34

Re: Run bash file on startup

#3 Post by ronp20 »

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

tsmith3480
Posts: 4
Joined: 2018-04-16 11:20

Re: Run bash file on startup

#4 Post by tsmith3480 »

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

ronp20
Posts: 7
Joined: 2018-04-30 07:34

Re: Run bash file on startup

#5 Post by ronp20 »

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?

tsmith3480
Posts: 4
Joined: 2018-04-16 11:20

Re: Run bash file on startup

#6 Post by tsmith3480 »

Yes, you would have to follow this pattern:

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

ronp20
Posts: 7
Joined: 2018-04-30 07:34

Re: Run bash file on startup

#7 Post by ronp20 »

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

https://debian-administration.org/artic ... ith_Debian
it is not working

User avatar
None1975
df -h | participant
df -h | participant
Posts: 1398
Joined: 2015-11-29 18:23
Location: Russia, Kaliningrad
Has thanked: 46 times
Been thanked: 68 times

Re: Run bash file on startup

#8 Post by None1975 »

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.
OS: Debian 12.4 Bookworm / DE: Enlightenment
Debian Wiki | DontBreakDebian, My config files on github

reinob
Posts: 1195
Joined: 2014-06-30 11:42
Has thanked: 99 times
Been thanked: 47 times

Re: Run bash file on startup

#9 Post by reinob »

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"

User avatar
debiman
Posts: 3063
Joined: 2013-03-12 07:18

Re: Run bash file on startup

#10 Post by debiman »

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.

Post Reply