LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian
User Name
Password
Debian This forum is for the discussion of Debian Linux.

Notices


Reply
  Search this Thread
Old 12-23-2021, 08:26 AM   #1
PaulExordium
Member
 
Registered: Dec 2020
Distribution: Debian, Tails, Kodachi, Mint DE
Posts: 92

Rep: Reputation: Disabled
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.

What am I missing?
 
Old 12-23-2021, 08:33 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,849

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
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.
 
1 members found this post helpful.
Old 12-23-2021, 09:21 AM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,702

Rep: Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896
pan64 is correct cron is not associated with a terminal or the desktop. To run from cron you need to specify the display i.e.

DISPLAY=:0.0 /usr/bin/firefox-esr

A better solution would be to have your programs run as a startup application i.e. when you log in.
 
1 members found this post helpful.
Old 12-24-2021, 05:03 AM   #4
PaulExordium
Member
 
Registered: Dec 2020
Distribution: Debian, Tails, Kodachi, Mint DE
Posts: 92

Original Poster
Rep: Reputation: Disabled
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.

Thank you pan64,
thank you michaelk.
 
Old 12-24-2021, 06:12 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,849

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
Great! If your problem is solved please mark the thread solved. Also if you want to say thanks just click on yes.
 
Old 12-31-2021, 09:12 AM   #6
djk44883
Member
 
Registered: Aug 2008
Location: Ohio
Distribution: debian
Posts: 141

Rep: Reputation: 29
also if you were going to do this, with command which would execute, you need to make sure "user" is in the cron group
 
Old 12-31-2021, 09:56 AM   #7
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,849

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
Quote:
Originally Posted by djk44883 View Post
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.
 
Old 12-31-2021, 11:29 AM   #8
djk44883
Member
 
Registered: Aug 2008
Location: Ohio
Distribution: debian
Posts: 141

Rep: Reputation: 29
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do i mute STDOUT of the bash script executed by the crontab file? postcd Linux - General 6 07-04-2017 11:13 AM
[SOLVED] Problem with crontab:: command not executed properly via crontab Ankush Seth Linux - Newbie 11 11-11-2013 06:25 AM
ShellScript executed from command prmpt but not executed from crontab or at command BMMadhav Linux - Newbie 1 11-16-2012 07:20 PM
[SOLVED] Configured Cron job executed every hour is instead executed every minute for 10m markings Linux - Software 4 05-13-2012 05:43 PM
[SOLVED] Xwindow's program will not run when executed on boot or when executed remotely richman1234 Programming 2 10-08-2010 01:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian

All times are GMT -5. The time now is 05:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration