LinuxQuestions.org
Help answer threads with 0 replies.
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 11-10-2007, 07:07 PM   #1
props666999
Member
 
Registered: Oct 2003
Location: Greece
Posts: 260

Rep: Reputation: 30
cron apt-get sudo


Hi

i want to create a cron job for updating my Debian system

the steps i have undertaken are:

1) create in /etc/cron.hourly the file update which contains the following lines:
/usr/bin/apt-get update
/usr/bin/apt-get upgrade

2) i have added the following cronjob

47 * * * * /etc/cron.hourly/update


3) and finally i have added in sudoers the line:
Cmnd_Alias APT = /usr/bin/apt-get, /usr/bin/dpkg
me ALL = NOPASSWD: APT


Now when the cronjob is executed i get the error


E: Could not open lock file /var/lib/apt/lists/lock - open (13 Permission denied)
E: Unable to lock the list directory
E: Could not open lock file /var/lib/dpkg/lock - open (13 Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?


Even manually by /etc/cron.hourly/update gives the same error

Now do i need in the suoders to add /etc/cron.hourly/update to permit me the execution or there is a simpler way


many thanks
 
Old 11-10-2007, 07:53 PM   #2
Telemachos
Member
 
Registered: May 2007
Distribution: Debian
Posts: 754

Rep: Reputation: 60
Automatic apt-get updates seems like a bad idea to me. That said, the root user can have its own cronjobs. If you really want to do this, log in as 'su' and enter the cronjobs as root. (You should also look into the -y flag for "apt-get upgrade" since if apt-get asks you for input during a cronjob, you won't be there to answer. Of course, I don't like -y any more than I like automatic updates for apt-get, but what do I know...)
 
Old 11-11-2007, 03:39 AM   #3
props666999
Member
 
Registered: Oct 2003
Location: Greece
Posts: 260

Original Poster
Rep: Reputation: 30
i want specifically to employ the sudo function.

I want me as a normal user to run a cron job to update Debian and not as a super user


many thanks
 
Old 11-11-2007, 07:05 AM   #4
Telemachos
Member
 
Registered: May 2007
Distribution: Debian
Posts: 754

Rep: Reputation: 60
Quote:
Originally Posted by props666999 View Post
i want specifically to employ the sudo function.

I want me as a normal user to run a cron job to update Debian and not as a super user
Why? That is, if this is a household computer, then very likely your normal user is you and the super user is you too. (If you are editing the sudoers file, you must have root privileges in some way already.) At this point, I'm just being a pain since it's your system and you can and should do whatever you want. Still, I don't get why it matters to you. Either way, I don't know enough about the sudoers syntax to help. I know that you should edit it using the command "visudo" (entered as root) rather than by manually editing the file directly, and I know that you can check if your sudoers file has valid syntax by using "visudo -c" (also as root), but beyond that my advice is to read the man page for sudoers carefully (man sudoers).

One other thing: even on a Sid system, you really should not need to update hourly.
 
Old 11-12-2007, 12:23 PM   #5
oxleyk
Member
 
Registered: Nov 2003
Distribution: Ubuntu
Posts: 309

Rep: Reputation: 30
You could install apticron and get email notification of updates then decide which to install. You're not going to have hourly, or even daily, updates in most cases.

Kent
 
Old 11-13-2007, 09:53 AM   #6
LeLutin
LQ Newbie
 
Registered: Sep 2007
Distribution: Debian, Ubuntu
Posts: 5

Rep: Reputation: 0
anyways automatically updating is a bad idea as sometimes config files get rewritten/moved, and sometimes due to dependency problems, some package gets dropped for no reason. by automatically doing the update, you'll end up wondering why package X is broken or why package Y is missing, and having to check the logs to see where the problem showed up.

IMHO, updating should really be done by hand by a human.

but, hey, you're free to experiment what you like on your computer
if you want to run a cron job with your user, I recommend not putting the script in /etc/cron.whatever as all scripts within those directories get executed automatically by the root cron jobs. put the script in something like ~/cron.daily and with your user, add a cron job with "crontab -e" that points to this script.
 
  


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
LXer: The Ultimate Sudo FAQ — To Sudo Or Not To Sudo? LXer Syndicated Linux News 13 04-13-2013 01:36 AM
Sudo apt-get treotan Ubuntu 11 10-05-2007 06:56 PM
My cron doesn't work but 'sudo -u john foo.sh' does guarriman Linux - Software 2 01-19-2007 02:51 PM
apt-proxy and cron-apt - download once for the whole LAN Abject Debian 1 06-20-2004 01:53 PM
running apt-get in cron firefly2442 Debian 2 04-29-2004 10:50 PM

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

All times are GMT -5. The time now is 03:32 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