You are not logged in.

#1 2008-07-08 15:35:29

RAH
Member
Registered: 2008-06-20
Posts: 205

Running Crons On Startup/Shutdown

Hi,

I have two seperate crons.  One needs to run on startup and the other on shutdown.  How can I do this?  Also it would be useful to make it if the first one on startup fails (eg. due to no internet connection) the second on shutdown is skipped.

Thanks.

Offline

#2 2008-07-08 16:18:44

Inxsible
Forum Fellow
From: Chicago
Registered: 2008-06-09
Posts: 9,183

Re: Running Crons On Startup/Shutdown

RAH wrote:

Hi,

I have two seperate crons.  One needs to run on startup and the other on shutdown.  How can I do this?  Also it would be useful to make it if the first one on startup fails (eg. due to no internet connection) the second on shutdown is skipped.

Thanks.

What you probably need is a startup script rather than cron. cron executes commands chronologically and so it would be impossible to initiate something on boot and shutdown using cron.

For eg. if you use Openbox, you can add the commands that you need to run on startup in the ~/.config/openbox/autostart.sh file.

You can have a shutdown script  as well, to see if "whatever you started" has executed or not and accordingly execute the shutdown script.

Last edited by Inxsible (2008-07-08 16:20:12)


Forum Rules

There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !

Offline

#3 2008-07-08 16:25:58

RAH
Member
Registered: 2008-06-20
Posts: 205

Re: Running Crons On Startup/Shutdown

How would I go about creating a startup script?  Thanks.

Offline

#4 2008-07-08 16:33:14

Inxsible
Forum Fellow
From: Chicago
Registered: 2008-06-09
Posts: 9,183

Re: Running Crons On Startup/Shutdown

RAH wrote:

How would I go about creating a startup script?  Thanks.

What WM or DE do you use?


Forum Rules

There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !

Offline

#5 2008-07-08 16:36:21

RAH
Member
Registered: 2008-06-20
Posts: 205

Re: Running Crons On Startup/Shutdown

Gnome.

Offline

#6 2008-07-08 16:55:18

moljac024
Member
From: Serbia
Registered: 2008-01-29
Posts: 2,676

Re: Running Crons On Startup/Shutdown

What exactly are you trying to do ?


The day Microsoft makes a product that doesn't suck, is the day they make a vacuum cleaner.
--------------------------------------------------------------------------------------------------------------
But if they tell you that I've lost my mind, maybe it's not gone just a little hard to find...

Offline

#7 2008-07-08 16:57:53

RAH
Member
Registered: 2008-06-20
Posts: 205

Re: Running Crons On Startup/Shutdown

moljac024 wrote:

What exactly are you trying to do ?

It's explained in my first post - running crons on startup and shutdown.  They are rsync crons.

Offline

#8 2008-07-08 16:57:55

xdeusx
Member
Registered: 2007-10-15
Posts: 168

Re: Running Crons On Startup/Shutdown

# /etc/rc.local: Local multi-user startup script.
# /etc/rc.local.shutdown: Local shutdown script.

Offline

#9 2008-07-08 16:59:49

RAH
Member
Registered: 2008-06-20
Posts: 205

Re: Running Crons On Startup/Shutdown

xdeusx wrote:

# /etc/rc.local: Local multi-user startup script.
# /etc/rc.local.shutdown: Local shutdown script.

Thanks have to figure out how to skip the shutdown script if the startiup one isn't successful.

Offline

#10 2008-07-08 18:32:53

Inxsible
Forum Fellow
From: Chicago
Registered: 2008-06-09
Posts: 9,183

Re: Running Crons On Startup/Shutdown

moljac024 wrote:

What exactly are you trying to do ?

HAHAHAHAH moljac...i like your sig....permission to quote it sometimes somewhere else?......... with due credits of course


Forum Rules

There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !

Offline

#11 2008-07-08 18:34:19

Inxsible
Forum Fellow
From: Chicago
Registered: 2008-06-09
Posts: 9,183

Re: Running Crons On Startup/Shutdown

RAH wrote:
xdeusx wrote:

# /etc/rc.local: Local multi-user startup script.
# /etc/rc.local.shutdown: Local shutdown script.

Thanks have to figure out how to skip the shutdown script if the startiup one isn't successful.

On successful startup script -- you could probably set a user-defined environment variable. Then before running the shutdown script - check for that variable and do things accordingly.

IMP NOTE: Make sure that the variable you select is unique and something that no other program developer might think of using, or you may mess up some other system variable or have problems with another program using the same environment variable.

Last edited by Inxsible (2008-07-08 18:35:37)


Forum Rules

There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !

Offline

#12 2008-07-08 18:42:03

RAH
Member
Registered: 2008-06-20
Posts: 205

Re: Running Crons On Startup/Shutdown

Thanks for the info however I have no idea how to either make these scripts or set the variables.

Offline

#13 2008-07-08 19:51:36

Inxsible
Forum Fellow
From: Chicago
Registered: 2008-06-09
Posts: 9,183

Re: Running Crons On Startup/Shutdown

RAH wrote:

Thanks for the info however I have no idea how to either make these scripts or set the variables.

Create a sh file . for eg. startupscript.sh. Use your favorite editor to add the following lines to it

#!/bin/sh
//simply add the commands that you want to be executed on boot. 
//After ALL the commands make sure you add 
export YOURUNIQUEENVVAR=SUCCESS

Now  create a shutdownscript.sh. Your shutdown script will first check for the variable you set....and if it is SUCCESS, only then will it execute its commands. Something like

#!/bin/sh
if[YOURUNIQUEENVVAR == SUCCESS] then 
 //add your shutdown commands that you need executed
fi

Give both those files executable permissions

chmod +x /path/to/startupscript
chmod +x /path/to/shutdownscript

Then add the startupscript in the sessions. I think it is System>>Preferences>>Sessions. I could be wrong, I havent used Gnome is quite some time.

You will have to modify your quit mechanism to first execute the shutdown script when you select shutdown. I dont quite rbr how to do that. Of course you can simply put it under rc.local.shutdown

NOTE : above is just a pseudo code version of what you may need. you will have to add the appropriate commands to both the files. in the shutdown script you may also have to add an else branch where you would simply continue with shutting down etc.

Last edited by Inxsible (2008-07-08 20:04:27)


Forum Rules

There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !

Offline

#14 2008-07-08 20:42:04

RAH
Member
Registered: 2008-06-20
Posts: 205

Re: Running Crons On Startup/Shutdown

Thanks very much - very helpful.

Does anyone know how to edit the quit mechanism?

Offline

#15 2008-07-08 20:45:59

moljac024
Member
From: Serbia
Registered: 2008-01-29
Posts: 2,676

Re: Running Crons On Startup/Shutdown

Inxsible wrote:
moljac024 wrote:

What exactly are you trying to do ?

HAHAHAHAH moljac...i like your sig....permission to quote it sometimes somewhere else?......... with due credits of course

Go ahead smile I didn't come up with that, I also picked it up somewhere.... think it was linuxquestions.org wink


The day Microsoft makes a product that doesn't suck, is the day they make a vacuum cleaner.
--------------------------------------------------------------------------------------------------------------
But if they tell you that I've lost my mind, maybe it's not gone just a little hard to find...

Offline

#16 2008-07-19 20:30:28

RAH
Member
Registered: 2008-06-20
Posts: 205

Re: Running Crons On Startup/Shutdown

Anyone?

Offline

#17 2008-07-19 22:20:35

DonVla
Member
From: Bonn, Germany
Registered: 2007-06-07
Posts: 997

Re: Running Crons On Startup/Shutdown

RAH wrote:

Thanks very much - very helpful.

Does anyone know how to edit the quit mechanism?

what do you mean with "quit mechanism"?
oh i got it...
you can simply edit /etc/rc.local for startup and /etc/rc.local.shutdown for shutdown.
the last will be executed when the system really shuts down.

Last edited by DonVla (2008-07-19 22:27:39)

Offline

#18 2008-07-20 07:22:30

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,224
Website

Re: Running Crons On Startup/Shutdown

RAH wrote:

I have two seperate crons.  One needs to run on startup...

As a side note for future forum searchers, on some cron daemons (Vixie Cron?) you can use the special 'time' "@reboot" to execute things when the system boots. Useful if you don't have access to the rc.local files on the host (eg, shared hosting). I use it on my shared web host to send me an e-mail when their server is restarted just for my own info...

@reboot  mail -s "Web Host Restarted" my@emailaddress.com < /dev/null

Last edited by fukawi2 (2008-07-20 07:24:31)

Offline

#19 2008-07-20 16:59:55

Daenyth
Forum Fellow
From: Boston, MA
Registered: 2008-02-24
Posts: 1,244

Re: Running Crons On Startup/Shutdown

Another option if this is an arch machine, is to make an rc.d script and add it to DAEMONS. It will be run with the start parameter at boot, and the stop parameter at shutdown. You can use the add_daemon and rm_daemon functions to keep track of whether it ran successfully or not.

Offline

Board footer

Powered by FluxBB