[SOLVED] Adding commands in system crontab file to be executed at start up
DebianThis forum is for the discussion of Debian Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Adding commands in system crontab file to be executed at start up
Code:
# non-commented content of /etc/crontab file (Debian 11)
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
# added for testing
@reboot user date >> $HOME/starts.log
@reboot user /usr/bin/firefox-esr
@reboot user $HOME/MyApplication
The added commands work fine if run from the terminal but only the first one will be executed at start up, the processes "firefox-esr" and "MyApplication" don't show up.
At first, cron has its own environment. Especially cron has no any idea about your GUI (and works independently from that). So firefox and MyApp will not find DISPLAY.
Next, crontab will be started before X, so probably firefox and MyApp were started too early.
Finally you need to collect the logs/output of those commands to see what's going on.
If I understand correctly, there is no point in trying to launch a graphic "anything" with "cron" since it was not designed for that. So, after a little learning, I created a "MyApplication.desktop" file in the $HOME/.local/share/appplications" folder and with the "Tweaks" utility added "MyApplication" as a startup application. Easy enough.
also if you were going to do this, with command which would execute, you need to make sure "user" is in the cron group
? where is it coming from ? see man crontab:
Quote:
A crontab file contains instructions to the cron(8) daemon of the general form: ``run this command at this time on this
date''. Each user has their own crontab, and commands in any given crontab will be executed as the user who owns the
crontab.
Mistaken on group I've added myself to group crontab It's easier (maybe not correct) to find and add to cron.d (or /etc/crontab) than crontab -e unless/until you set up an editor...
I can point and click via GUI and use a text editor I'm accustomed with to create files in cron.d (owned by root) generally avoid /etc/crontab as "user" so whatever files are created by "user" and interaction isn't don't by root.
users crontab are deeply buried /var/spool/crontabs/user
Yes each user has their own, in the above example they are using system crontab. Not only the variables won't expand, a user needs to be in the crontab group to even have command executed. The errors should be in cron.log or which ever logging facility is capturing it.
man cron notes Debian specifics "SGID crontab(1) instead of SUID root" and your crontab page notes files are only " This is enforced by having the directory writable only by the crontab group and configuring crontab command with the setgid bid set for that specific group."
It's likely not best practices, it's just my single user system --- it's relative to the OP example even if they had correct commands - user can't run unless they are in group crontab
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.