LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices


Reply
  Search this Thread
Old 09-13-2016, 04:41 PM   #1
Fixit7
Senior Member
 
Registered: Mar 2014
Location: El Lago, Texas
Distribution: Ubuntu_Mate 16.04
Posts: 1,374

Rep: Reputation: 169Reputation: 169
Run script once a week


I want to run a script once a week.

In the crontab examples I have seen, you have to specify a time.

However I do not know whether my computer will on at a particular time.

For example.

I want one to run every Monday at whatever time my computer gets turned on.
 
Old 09-13-2016, 05:30 PM   #2
Dave Lerner
Member
 
Registered: May 2005
Location: Florida, USA
Distribution: Pop_OS, Xubuntu
Posts: 152

Rep: Reputation: 44
Install anacron.

Then place the script in the directory /etc/cron.weekly. Or you could put the script in /etc/cron.daily and add some logic in the script that exits unless it's Monday.
 
Old 09-13-2016, 05:30 PM   #3
Emerson
LQ Sage
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~amd64
Posts: 7,661

Rep: Reputation: Disabled
http://anacron.sourceforge.net/
 
Old 09-13-2016, 05:52 PM   #4
Fixit7
Senior Member
 
Registered: Mar 2014
Location: El Lago, Texas
Distribution: Ubuntu_Mate 16.04
Posts: 1,374

Original Poster
Rep: Reputation: 169Reputation: 169
Will this run outside of a console ?

Quote:
echo xxxx | sudo apt-get update
 
Old 09-13-2016, 06:07 PM   #5
Dave Lerner
Member
 
Registered: May 2005
Location: Florida, USA
Distribution: Pop_OS, Xubuntu
Posts: 152

Rep: Reputation: 44
Running that in a script would problematic, because sudo will ask for a password. It should be run it as root, so that sudo is not needed.

But "apt-get update" should already run daily if anacron is installed, using the script /etc/cron.daily/apt.
 
Old 09-13-2016, 06:27 PM   #6
Fixit7
Senior Member
 
Registered: Mar 2014
Location: El Lago, Texas
Distribution: Ubuntu_Mate 16.04
Posts: 1,374

Original Poster
Rep: Reputation: 169Reputation: 169
There is no apt in /etc/cron.daily.

Quote:
echo xxxx | sudo apt-get update supplies the password. (xxxx is not my real password)
 
Old 09-13-2016, 06:33 PM   #7
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,702

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
You can configure automatic updates.

https://help.ubuntu.com/lts/servergu...c-updates.html
 
Old 09-13-2016, 06:40 PM   #8
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by Fixit7 View Post
I want to run a script once a week.
In the crontab examples I have seen, you have to specify a time. However I do not know whether my computer will on at a particular time.

For example. I want one to run every Monday at whatever time my computer gets turned on.
So, you want it to run at system start time?, or every Monday, whichever comes first? Easy...write your script to check the day-of-the-week, and put it in cron, and ALSO put it in your system startup routine. If your system boots on a Friday, it'll check day of week, and not execute. If it boots on Monday...it runs. If your system is ALREADY up on Monday, cron will execute it anyway.

Why make it hard? Otherwise, you do realize that cron can be VERY granular right? And can take regex'es?
http://www.linuxquestions.org/questi...2/#post4654486
 
Old 09-13-2016, 07:01 PM   #9
Fixit7
Senior Member
 
Registered: Mar 2014
Location: El Lago, Texas
Distribution: Ubuntu_Mate 16.04
Posts: 1,374

Original Poster
Rep: Reputation: 169Reputation: 169
I found this in /etc/apt/apt.conf.d

10periodic

Quote:
APT::Periodic::Update-Package-Lists "7";
APT::Periodic:ownload-Upgradeable-Packages "0";
APT::Periodic::AutocleanInterval "0";
I think it is already updating.

I was wanting to make sure that the software depositories are always current.
 
Old 09-13-2016, 07:12 PM   #10
Dave Lerner
Member
 
Registered: May 2005
Location: Florida, USA
Distribution: Pop_OS, Xubuntu
Posts: 152

Rep: Reputation: 44
This will show you when "apt-get update" last ran:

Code:
ll -h /var/cache/apt
 
Old 09-13-2016, 07:32 PM   #11
Fixit7
Senior Member
 
Registered: Mar 2014
Location: El Lago, Texas
Distribution: Ubuntu_Mate 16.04
Posts: 1,374

Original Poster
Rep: Reputation: 169Reputation: 169
thanks.

It ran today.
 
  


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
Run Script When Any Key Pressed, Run 2nd Script After Any Pause jakfish Linux - General 2 08-25-2016 06:47 AM
How to set up a Cron Job to run every other week or every three months etc. kckabobus Linux - Newbie 3 04-03-2008 01:36 PM
LXer: Silverlight To Run On Linux This Week LXer Syndicated Linux News 0 06-21-2007 05:03 AM
on Network Up Script run? On Battery power run script? v2-ncl Linux - General 0 12-08-2003 09:34 AM
squid fail to run after one week on smooth running on rh 8.0 server xnet_online Linux - Networking 5 12-23-2002 04:14 AM

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

All times are GMT -5. The time now is 10:23 PM.

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