pcfreak49
Posts: 27
Joined: Wed Dec 12, 2018 11:53 am

crontab update

Sun Aug 04, 2019 1:33 pm

I have a problem I want crontab to perform an update, but that doesn't work

0 20 * * * sudo apt-get update

pcmanbob
Posts: 10119
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: crontab update

Sun Aug 04, 2019 1:44 pm

So first off if you want to run a command in cron as root then use

Code: Select all

sudo crontab -e
that way you are running the command as root and you don't need the sudo command in the line.

second how do you know its not running ?

as cron runs things in a background there will be no output to the screen.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

pcfreak49
Posts: 27
Joined: Wed Dec 12, 2018 11:53 am

Re: crontab update

Sun Aug 04, 2019 1:51 pm

Yes I know via crontab -e and then 0 16 * * * sudo apt-get update && sudo apt-get upgrade, && sudo reboot but it doesn't work

knute
Posts: 608
Joined: Thu Oct 23, 2014 12:14 am
Location: Texas
Contact: Website

Re: crontab update

Sun Aug 04, 2019 5:22 pm

pcfreak49 wrote:
Sun Aug 04, 2019 1:51 pm
Yes I know via crontab -e and then 0 16 * * * sudo apt-get update && sudo apt-get upgrade, && sudo reboot but it doesn't work
If apt-get upgrade stops and asks for input it isn't going to get any and will hang right there forever.

One of the easiest ways to know that cron has done a job for you is to have it email you the output from the command. To do that you need to install a mail system. The simplest and easiest way I think is to install sendmail and mailutils. No configuration is required except to create a fully qualified domain name in /etc/hosts/ before you install sendmail. Just change the last line to something like:

127.0.1.1 raspberrypi raspberrypi.local

When the crontab does a job and there is output it will be mailed to the crontab user. Use the mail command to read your mail. If you want to root's crontab output mailed to pi, just put this line in /etc/aliases:

root: pi

While the sudo command works from pi's crontab I agree with the other fellow that I would put the commands in root's crontab.

User avatar
DougieLawson
Posts: 40184
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: crontab update

Sun Aug 04, 2019 5:35 pm

If you want auto update there are easier ways than hacking around in root's crontab.

sudo apt install unattended-upgrades apt-listchanges
sudo dpkg-reconfigure -plow unattended-upgrades


Or manually with sudo nano /etc/apt/apt.conf.d/20-auto-upgrades

Code: Select all

APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

pcfreak49
Posts: 27
Joined: Wed Dec 12, 2018 11:53 am

Re: crontab update

Mon Aug 05, 2019 6:57 am

the pi user has been deleted for security, have created a new user crontab works via date to save a file date >> /home/tim/date.txt

the intention is to plan these assignments
first take a backup at 5am and then a full update at 6am and then do it clean at 7am and then restart the pie every day

knute wrote:
Sun Aug 04, 2019 5:22 pm
pcfreak49 wrote:
Sun Aug 04, 2019 1:51 pm
Yes I know via crontab -e and then 0 16 * * * sudo apt-get update && sudo apt-get upgrade, && sudo reboot but it doesn't work
If apt-get upgrade stops and asks for input it isn't going to get any and will hang right there forever.

One of the easiest ways to know that cron has done a job for you is to have it email you the output from the command. To do that you need to install a mail system. The simplest and easiest way I think is to install sendmail and mailutils. No configuration is required except to create a fully qualified domain name in /etc/hosts/ before you install sendmail. Just change the last line to something like:

127.0.1.1 raspberrypi raspberrypi.local

When the crontab does a job and there is output it will be mailed to the crontab user. Use the mail command to read your mail. If you want to root's crontab output mailed to pi, just put this line in /etc/aliases:

root: pi

While the sudo command works from pi's crontab I agree with the other fellow that I would put the commands in root's crontab.

pcfreak49
Posts: 27
Joined: Wed Dec 12, 2018 11:53 am

Re: crontab update

Fri Aug 09, 2019 6:57 am

I have several raspberry pi that is used for home automation therefore it must always be up to date, and another for the studies

crontab -e already looks like this
but is not working yet

#update
0 6 * * * sudo apt-get update && sudo apt-get -y upgrade && sudo rpi update && $

#clean
0 7 * * * sudo apt-get autoremove --purge -y && sudo apt-get remove --purge -y

pcmanbob
Posts: 10119
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: crontab update

Fri Aug 09, 2019 7:30 am

One thing you should not be doing is running " sudo rpi update " on an in-service system, it will load what may be an unstable updates , its only to be used to fix a specific problem if instructed and even then it may lead to a corrupt OS which you would be on your own in trying to recover.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

pcfreak49
Posts: 27
Joined: Wed Dec 12, 2018 11:53 am

Re: crontab update

Fri Aug 09, 2019 7:39 am

Okay but how can you automatically download and install the updates please

pcmanbob
Posts: 10119
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: crontab update

Fri Aug 09, 2019 7:44 am

pcfreak49 wrote:
Fri Aug 09, 2019 7:39 am
Okay but how can you automatically download and install the updates please
have you not read Dougie's post above ?
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

pcfreak49
Posts: 27
Joined: Wed Dec 12, 2018 11:53 am

Re: crontab update

Fri Aug 09, 2019 7:48 am

yes but only 0 6 * * * sudo apt-get update && sudo apt-get -y upgrade

User avatar
Cancelor
Posts: 778
Joined: Wed Aug 28, 2013 4:09 pm
Location: UK

Re: crontab update

Fri Aug 09, 2019 8:10 am

It looks like you also missed the first reply ''you don't need the sudo command in the line''
pcmanbob wrote:
Sun Aug 04, 2019 1:44 pm
So first off if you want to run a command in cron as root then use

Code: Select all

sudo crontab -e
that way you are running the command as root and you don't need the sudo command in the line.

second how do you know its not running ?

as cron runs things in a background there will be no output to the screen.
Can't find the thread you want? Try googling : YourSearchHere site:raspberrypi.org

User avatar
RaTTuS
Posts: 10601
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: crontab update

Fri Aug 09, 2019 8:22 am

just do
https://www.raspberrypi.org/forums/view ... f#p1513135
everythying else is wrong on so many levels

1) don't do sudo in cron
2) don't do apt update in cron
3) apt upgrade in cron will bock as soon as it asks for anything [use -y yo get around this but not in cron]
4) never use rpi-update ever really unless you are debugging something specific , and never on a production machine
5) do read and understand useful comments
6) it's not wrong to ask questions
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

pcfreak49
Posts: 27
Joined: Wed Dec 12, 2018 11:53 am

Re: crontab update

Fri Aug 09, 2019 8:25 am

I read somewhere else that I had to do that
RaTTuS wrote:
Fri Aug 09, 2019 8:22 am
just do
https://www.raspberrypi.org/forums/view ... f#p1513135
everythying else is wrong on so many levels

1) don't do sudo in cron
2) don't do apt update in cron
3) apt upgrade in cron will bock as soon as it asks for anything [use -y yo get around this but not in cron]
4) never use rpi-update ever really unless you are debugging something specific , and never on a production machine
5) do read and understand useful comments
6) it's not wrong to ask questions

User avatar
DougieLawson
Posts: 40184
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: crontab update

Fri Aug 09, 2019 8:31 am

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

pcfreak49
Posts: 27
Joined: Wed Dec 12, 2018 11:53 am

Re: crontab update

Fri Aug 09, 2019 8:45 am

can you also bless which day and hour the update will take place please?

User avatar
DougieLawson
Posts: 40184
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: crontab update

Fri Aug 09, 2019 8:47 am

pcfreak49 wrote:
Fri Aug 09, 2019 8:45 am
can you also bless which day and hour the update will take place please?
I don't know (I wouldn't dare to use that), go and read the man page. It's driven off a system crontab.

https://wiki.debian.org/UnattendedUpgrades
Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Return to “Troubleshooting”