You are not logged in.
Hi everyone,
I would like to create a cronjob.
I've found a "tutorial" online --> https://linuxhandbook.com/crontab/#the-cron-daemon
But it's start already weirdly...
on his example
christopher@pop-os:~$ ps ux | grep crond
christo+ 8942 0.0 0.0 18612 840 pts/0 S+ 02:16 0:00 grep --color=auto crond
I can see that the daemon is running for my user account.
for me it's look like that we see the grep process ! not the crond !? Am I right?
anyway I've tried on my Devuan(Chimaera) and I don't see a crond running.. is that normal ?
Thanks.
Linux noob, plz be kind
Offline
it's look like that we see the grep process ! not the crond !? Am I right?
Correct (I got the exact same result). Cron is NOT running in your system (you have grepped for 'crond', and therefore in the ps listing it shows the full command-line, which includes 'crond'). If Cron *was* running there would be at least 2 ps lines containing 'crond', one for the daemon & one for grep.
Offline
my 2 cents to it:
andre@kyoto:~$ ps -aef | grep cron
root 2403 1 0 09:45 ? 00:00:00 /usr/sbin/cron
andre 11016 10606 0 12:45 pts/0 00:00:00 grep --color=auto cron
andre@kyoto:~$
The daemon is called cron:
andre@kyoto:~$ ls -l /etc/init.d/cron*
-rwxr-xr-x 1 root root 3059 Oct 11 2019 /etc/init.d/cron
andre@kyoto:~$
Devuan 4, Chimaera, up-to-date.
Offline
I blame forgetfulness (aka old age):
$ ps aux | grep cron
root 1516 0.0 0.0 8684 3460 ? Ss Jul01 0:01 /usr/sbin/cron
alexk 8432 0.0 0.0 6372 712 pts/0 S+ 14:52 0:00 grep --color=auto cron
Offline
On the unasked adjacent question, the common solution to grep appearing in ps|grep output is to alter the pattern so it doesn't match itself, e.g. ps aux | grep 'cro[n]'
Another solution is pgrep.
3.1415P265E589T932E846R64338
Offline
Thank you all for your reply !
Thank you that have confirmed my thinking. I'm shocked that some people can post "tutorial" without mastering a bit the topic.... Internet peoples..
@boughtonp, oh great indeed I will use also a regex expression in grep to avoid to have the grep itself in the results.
ps aux | grep 'cron$'
Last edited by SpongeBOB (2023-07-07 05:28:49)
Linux noob, plz be kind
Offline
Thank you all for your reply !
Thank you that have confirmed my thinking. I'm shocked that some people can post "tutorial" without mastering a bit the topic.... Internet peoples..
@boughtonp, oh great indeed I will use also a regex expression in grep to avoid to have the grep itself in the results.
ps aux | grep 'cron$'
Another way to avoid the unwanted expression might be using the syntax grep -v "unwanted_regex_expression". Therefore, you can avoid the grep itself as follows:
ps aux | grep "cron" | grep -v " grep "
If you work systematically, things will come by itself (Lev D. Landau)
Offline
SpongeBOB wrote:Thank you all for your reply !
Thank you that have confirmed my thinking. I'm shocked that some people can post "tutorial" without mastering a bit the topic.... Internet peoples..
@boughtonp, oh great indeed I will use also a regex expression in grep to avoid to have the grep itself in the results.
ps aux | grep 'cron$'
Another way to avoid the unwanted expression might be using the syntax grep -v "unwanted_regex_expression". Therefore, you can avoid the grep itself as follows:
ps aux | grep "cron" | grep -v " grep "
The line containing the grep command itself is supposed to be printed at the end due to its higher pid -and then it'll be ignored thanks to the use of the regex 'cron$'-, but who knows...
If you work systematically, things will come by itself (Lev D. Landau)
Offline
Neither appending an end-of-line anchor nor doing a second negative grep are guaranteed "lossless" solutions - they both have potential to exclude valid lines. (Might not be very likely with the latter, but is still possible.)
Wrapping one of the characters in a character class will never exclude anything except the specific unwanted grep line, and is only two extra key presses.
And again, an even better solution is to ensure procps is installed, and use pgrep, which never includes itself in its output and defaults to just the pid; if one needs the extra detail ps provides, ps u $(pgrep cron) will do that.
3.1415P265E589T932E846R64338
Offline
Thank you all for your additional inputs !
I've tried pgrep = ♥
Linux noob, plz be kind
Offline