I have a couple of executable files in different directories that I would like to run at a set time, I have already got a cron file which I have a couple of commands I run in the mornings but how do I run an executable at a set time within the same cron file?
e.g. my executable is in /dir1/dir2/dir3/ executable-file-name
If I wanted it to run at 1am daily I would I put something like '0 1 * * * ./executable-file-name /dir1/dir2/dir3
or would I have to append the user (I am using pi) somewhere within the executable line?
Never ran one from a cron or anything before other than manually using ./executable-file-name.
Thanks
-
- Posts: 164
- Joined: Fri Nov 30, 2018 2:39 pm
- Location: Wales
How to run an executable file from CRON?
Make the most of your family and friends , your children grow up too quickly and you don't notice yourself ageing, friends dissapearing, moving on. You make plans for your future, but they can all be smashed in an instant, live life and enjoy. 

Re: How to run an executable file from CRON?
The correct cron line would be:
Each user has their own crontab file that can be edited by the command "crontab -e", so you don't need to specify the username.
Code: Select all
0 1 * * * /dir1/dir2/dir3/executable-file-name
- thagrol
- Posts: 4018
- Joined: Fri Jan 13, 2012 4:41 pm
- Location: Darkest Somerset, UK
- Contact: Website
Re: How to run an executable file from CRON?
The key thing is to use the full path to everything. For a script named bar, in the foo subdirectory of the Pi with the directory /tmp/baz as its parameter you'd do something like this:doubleudee1 wrote: ↑Fri Apr 12, 2019 10:19 amI have a couple of executable files in different directories that I would like to run at a set time, I have already got a cron file which I have a couple of commands I run in the mornings but how do I run an executable at a set time within the same cron file?
e.g. my executable is in /dir1/dir2/dir3/ executable-file-name
If I wanted it to run at 1am daily I would I put something like '0 1 * * * ./executable-file-name /dir1/dir2/dir3
or would I have to append the user (I am using pi) somewhere within the executable line?
Never ran one from a cron or anything before other than manually using ./executable-file-name.
Thanks
Code: Select all
0 1 * * * /home/pi/foo/bar /tmp/baz
Code: Select all
0 1 * * * /home/pi/foo/bar /tmp/baz >/tmp/bar.log 2>&1
Arguing with strangers on the internet since 1993.
Re: How to run an executable file from CRON?
Don't think so.doubleudee1 wrote: ↑Fri Apr 12, 2019 10:19 amwould I put something like '0 1 * * * ./executable-file-name /dir1/dir2/dir3
Its something like
Code: Select all
'0 1 * * * /dir1/dir2/dir3/executable-file-name
Code: Select all
0 1 * * * /home/pi/myDirectory/myProgram
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter
Pi Interests: Home Automation, IOT, Python and Tkinter
-
- Posts: 971
- Joined: Mon Apr 09, 2018 5:26 pm
- Location: N. Finland
Re: How to run an executable file from CRON?
You would remove the dot to have an absolute path, not a relative path. That is to say, use /dir1/dir2/dir3/program
As to specifying the account name, that depends on how you set up the cron job. If you use 'crontab -e' under the account 'pi' then it should not be added. If you edit the system-wide, then you must also specify which account the script will be run as.
See "man 5 crontab" for the details.
As to specifying the account name, that depends on how you set up the cron job. If you use 'crontab -e' under the account 'pi' then it should not be added. If you edit the system-wide, then you must also specify which account the script will be run as.
See "man 5 crontab" for the details.
-
- Posts: 164
- Joined: Fri Nov 30, 2018 2:39 pm
- Location: Wales
Re: How to run an executable file from CRON?
Thanks all
Thats cleared it up for me.
WD
Thats cleared it up for me.
WD
Make the most of your family and friends , your children grow up too quickly and you don't notice yourself ageing, friends dissapearing, moving on. You make plans for your future, but they can all be smashed in an instant, live life and enjoy. 
