How to set up cron job for auto update?

I will be away from home for two weeks so I want to set up a cron job for the system to update then reboot daily at 2am. What’s the proper way of doing this? If I just enter the command in the crontab as “yay” and “reboot”, how do I pre-fill the prompt for sudo password and default “y” to all the prompt for questions? Thank you.

The proper way is to not do this at all.

Auto-updating is absolutely not safe on a Arch-based distro. You can easily end up with an unbootable machine.

Why do you want to force update and reboot your machine every day?


Why not just wait 2 weeks to update? I’ve gone almost 2 months just to see what would happen, and the answer was nothing. Nothing bad happened at all.


Normally I just run “yay” and accept all the defaults on update, then reboot when prompt. Are there any write up or video on how to fix or boot the system if the update bricks the system? Such as how to diagnose what packages break and how to solve all these? As a new Arch user, these skills are crucial…

You should really read the questions when they come up(which is only occasionally)

There is a wiki article on how to chroot into a broken system, but fundamentally it depends why it is broken.


“There is a wiki article on how to chroot into a broken system, but fundamentally it depends why it is broken.”

Exactly. How do I know which package breaks?

There is no single way to determine this. It may not even be a package problem.

Ideally, you wouldn’t blindly update and wait for it to break. You would read the prompts so it doesn’t happen in the first place.


Yes and I do try to read while learning bash script. But I don’t understand them all since I’m too new. It will take some time. “Linux is a life-long journey.”

If this is the case, learn to have fun with it rather than stress over potential problems. Keep backups of your data. Don’t worry, be happy. :sunglasses:

it helps to roughly know which packages got updated last to begin the search :wink: thats why automatic updates are not good practice - you would need to look through log files in that case to check which packages were updated.

Two weeks is nothing. Just forget about it, when you come home in two weeks update as you normally would.

Even if it is two months, there’s no problem. You might need to manually install a new keyring at worst or fix your mirrorlist, really nothing to worry about. Of course, the longer you wait without updating, the more manual intervention is typically needed, and it can get a bit tedious. But I’ve successfully updated Arch systems that haven’t been updated in a year, with minimal difficulties. It’s really not a big deal.

Listen to @dalto and do not try to automate updates. Arch is not good for that.

And advice in general: Don’t waste time solving potential problems – problems that may or may not happen in the future (unless they are of life and death importance). Instead, focus on actual problems as they arise. Don’t worry about your system breaking and don’t try to prevent it. Instead, if it breaks, focus on fixing it. You’ll learn a lot from the process and next time it will be easier. In the worst case, you can always reinstall (but that way you deprive yourself of the learning experience, so it should be a last resort).

Just make sure to have all your valuable data regularly backed up, preferably in multiple external copies, because storage failure is a certainty – it is just a matter of time. With a good backup, there is nothing to worry about.


That’s a great mindset. Yes I’m always concerned about something will break at some point. Always wanna have a solution in advance. I should train myself to ease and deal with it when it happens. I did encounter a freezing screen once and didn’t know what to do, had to do a hard force shutdown. Any good advice or article on this?

I’m not @Kresimir, but I can point you to an article written by Kresimir that is good advice: