Jump to content

If i get a shell script to execute on startup via crontab.. will the script continue running until the next reboot? I am used to running a script for a java application in screen, which is starting to get annoying to have to re-open every restart.

 

Thanks 

!Visit my blog HERE!

Latest Post: How to give back for free this Christmas

Link to comment
https://linustechtips.com/topic/625668-shell-scripts-startup/
Share on other sites

Link to post
Share on other sites

I'm not sure for cron, but as @Nater said theres more systematic ways to execute scripts at start up. But, assuming the cron job works the same as just adding the script to the "start up list" then it will only run once per boot. It will run once and end(unless you have a loop or restart or whatever) and will then run again upon restart. 

                     .
                   _/ V\
                  / /  /
                <<    |
                ,/    ]
              ,/      ]
            ,/        |
           /    \  \ /
          /      | | |
    ______|   __/_/| |
   /_______\______}\__}  

Spoiler

[I5-12600k | 32gb DDR5 6000 | RTX5070 | 2x1tb M.2]

 

[Ryzen 5 1600 | 16gb DDR4 3200 | GTX1030 | 4x 8tb HDD] 

 

Link to comment
https://linustechtips.com/topic/625668-shell-scripts-startup/#findComment-8074951
Share on other sites

Link to post
Share on other sites

1 hour ago, RedWulf said:

I'm not sure for cron, but as @Nater said theres more systematic ways to execute scripts at start up. But, assuming the cron job works the same as just adding the script to the "start up list" then it will only run once per boot. It will run once and end(unless you have a loop or restart or whatever) and will then run again upon restart. 

One of my scripts starts a Proxy server, which i guess would continually run, and the other just starts a daemon, so i am guessing they could both be executed with cron? 

!Visit my blog HERE!

Latest Post: How to give back for free this Christmas

Link to comment
https://linustechtips.com/topic/625668-shell-scripts-startup/#findComment-8075161
Share on other sites

Link to post
Share on other sites

Here is an example of a systemd service. Ubuntu 16.04 LTS uses systemd and so does Centos 7 (RHEL7)

 

 

create .service file in this example its "/lib/systemd/system/myscript.service"

[Unit]
Description=myscript
After=network.target

[Service]
User=bill
Group=bill
ExecStart=/home/bill/myscript.sh

[Install]
WantedBy=multi-user.target

 

now to enable the new service on startup we do

systemctl enable myscript.service

 

start the service and check its running

systemctl start myscript.service
systemctl status myscript.service

 

Arch Linux Wiki is pretty good for infomation, most files and commands are the same in Ubuntu and CentOS

https://wiki.archlinux.org/index.php/systemd

 

Our Lord and Saviour Chunt!!!

Link to comment
https://linustechtips.com/topic/625668-shell-scripts-startup/#findComment-8083448
Share on other sites

Link to post
Share on other sites

14 hours ago, Jonny said:

Here is an example of a systemd service. Ubuntu 16.04 LTS uses systemd and so does Centos 7 (RHEL7)

 

 

create .service file in this example its "/lib/systemd/system/myscript.service"


[Unit]
Description=myscript
After=network.target

[Service]
User=bill
Group=bill
ExecStart=/home/bill/myscript.sh

[Install]
WantedBy=multi-user.target

 

now to enable the new service on startup we do


systemctl enable myscript.service

 

start the service and check its running


systemctl start myscript.service
systemctl status myscript.service

 

Arch Linux Wiki is pretty good for infomation, most files and commands are the same in Ubuntu and CentOS

https://wiki.archlinux.org/index.php/systemd

 

Thanks, I will try it out later!

!Visit my blog HERE!

Latest Post: How to give back for free this Christmas

Link to comment
https://linustechtips.com/topic/625668-shell-scripts-startup/#findComment-8087128
Share on other sites

Link to post
Share on other sites

If you need to run script at the startup you can use cron for that, and your application will work until the end or reboot the system.

 

But more convinient way to do that is writing the init.d script to launch your app at the system startup and stop it before the shutdown.

 

Take a look here for more related info, maybe it will help you.

Link to comment
https://linustechtips.com/topic/625668-shell-scripts-startup/#findComment-8149961
Share on other sites

Link to post
Share on other sites

  • 2 weeks later...
On 23/07/2016 at 9:01 AM, gexacor said:

If you need to run script at the startup you can use cron for that, and your application will work until the end or reboot the system.

 

But more convinient way to do that is writing the init.d script to launch your app at the system startup and stop it before the shutdown.

 

Take a look here for more related info, maybe it will help you.

You can do it that way but using a systemd service will be better. Better practice too.

Our Lord and Saviour Chunt!!!

Link to comment
https://linustechtips.com/topic/625668-shell-scripts-startup/#findComment-8205254
Share on other sites

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

×