DebianThis forum is for the discussion of Debian Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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...)
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.