You are not logged in.

#1 2012-10-09 09:20:26

wdirksen
Member
From: New Zealand
Registered: 2012-02-23
Posts: 105

Bash script won't run "sudo reboot" under cron, but perfect manually

Hi Archers,

I've got a weird problem with a bash script I use to run pacman and mythtv updates once a week via cron which also reboots itself so that new mythtv and kernels packages become active. This script works likes a charm when I run it manually as user from the command line. But when cron runs it (also as user) it executes everything EXCEPT the last "sudo reboot" command at the end. Sudoers seems to be setup right as it works fine from the command line. I could run this particular script with cron as root but I'd prefer not to update under root with the --asroot command.

Any ideas? It seems like the permissions running manually and with cron are different somehow.

Many thanks!

Last edited by wdirksen (2012-10-09 13:07:28)


Research | Trial | Make Mistakes | Ask questions | Learn | Repeat

Offline

#2 2012-10-09 09:30:16

DSpider
Member
From: Romania
Registered: 2009-08-23
Posts: 2,273

Re: Bash script won't run "sudo reboot" under cron, but perfect manually

Post your /etc/sudoers file.


"How to Succeed with Linux"

I have made a personal commitment not to reply in topics that start with a lowercase letter. Proper grammar and punctuation is a sign of respect, and if you do not show any, you will NOT receive any help (at least not from me).

Offline

#3 2012-10-09 10:54:29

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: Bash script won't run "sudo reboot" under cron, but perfect manually

Why would you use sudo in a cron job? Why not just add "reboot" to root's crontab?

Offline

#4 2012-10-09 13:05:04

wdirksen
Member
From: New Zealand
Registered: 2012-02-23
Posts: 105

Re: Bash script won't run "sudo reboot" under cron, but perfect manually

Thanks DSpider and falconindy for your replies

I will post the script and sudoers when I get home

falconindy wrote:

Why would you use sudo in a cron job? Why not just add "reboot" to root's crontab?

The intention is for the machine to care of itself by performing a series of updates in the night once a week and rebooting itself. The "sudo pacman -Uf . . . " commands work fine and seems to make the most sense to me to give the reboot command at the end of the script when the updates are completed. Are you suggesting to schedule a separate reboot root cron job to run a few hours after the other user script runs?


Research | Trial | Make Mistakes | Ask questions | Learn | Repeat

Offline

#5 2012-10-09 13:42:37

WorMzy
Forum Moderator
From: Scotland
Registered: 2010-06-16
Posts: 11,835
Website

Re: Bash script won't run "sudo reboot" under cron, but perfect manually

wdirksen wrote:

The intention is for the machine to care of itself by performing a series of updates in the night once a week and rebooting itself. The "sudo pacman -Uf . . . " commands work fine and seems to make the most sense to me to give the reboot command at the end of the script when the updates are completed.

That sounds like fun. Skipping key checks, forcing everything, and then rebooting to top it off.

You're going to have a nasty surprise waiting for you one morning if you keep doing that. Arch is not a hands-free distro, don't automate your updates.


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#6 2012-10-09 15:21:15

wdirksen
Member
From: New Zealand
Registered: 2012-02-23
Posts: 105

Re: Bash script won't run "sudo reboot" under cron, but perfect manually

WorMzy wrote:

That sounds like fun. Skipping key checks, forcing everything, and then rebooting to top it off.

You're going to have a nasty surprise waiting for you one morning if you keep doing that. Arch is not a hands-free distro, don't automate your updates.

Humm, food for thought. I did consider this but felt that up until now there has been nothing disasterous that couldn't be sorted manually later. But you are right, weird stuff does happen when initscripts, /usr/lib, are changed etc. I misquoted myself earlier. I don't -Uf  mythtv. I have to do that occaisionally for something else.

Last edited by wdirksen (2012-10-09 15:26:42)


Research | Trial | Make Mistakes | Ask questions | Learn | Repeat

Offline

#7 2012-10-09 15:35:44

2ManyDogs
Forum Fellow
Registered: 2012-01-15
Posts: 4,645

Re: Bash script won't run "sudo reboot" under cron, but perfect manually

I have to agree with WorMzy. This sounds like a really bad idea. Even putting reboot in a cron job sounds strange to me, but automating updates with a reboot at the end just sounds crazy. If you update every day it doesn't take long to watch it happen.

Last edited by 2ManyDogs (2012-10-09 15:36:01)


How to post. A sincere effort to use modest and proper language and grammar is a sign of respect toward the community.

Offline

#8 2012-10-09 16:04:36

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: Bash script won't run "sudo reboot" under cron, but perfect manually

A while back, I found something... can't find it at the moment... that would check the news, and then update while ignoring anything that was mentioned.  This might be safer, but I still would prefer to do it manually.

Offline

#9 2012-10-09 18:16:34

wdirksen
Member
From: New Zealand
Registered: 2012-02-23
Posts: 105

Re: Bash script won't run "sudo reboot" under cron, but perfect manually

OK, I'm going to reconsider this based on all your advices, but I'm still curious about why the command doesn't execute with cron. Related to this, I also find it strange that some root commands work fine with sudo, while others only work within a true root environment

DSpider wrote:

Post your /etc/sudoers file.

So here's my sudoers file:

## User privilege specification
##
root   ALL=(ALL) NOPASSWD: ALL
mythtv ALL=(ALL) NOPASSWD: ALL

. . . and this is the script:

#!/bin/bash
#
sudo pacman -Syyu --noconfirm
#
/usr/share/mythtv/optimize_mythdb.pl
/usr/share/mythtv/mythconverg_backup.pl --rotate 20
#
mythtvname="mythtv-git-$(date +%Y%m%d)-1-x86_64.pkg.tar.xz"
#
cd /home/mythtv/AUR/mythtv-git
makepkg
sudo pacman -U $mythtvname --noconfirm
#
sudo reboot

Anything stick out here?

Last edited by wdirksen (2012-10-09 19:32:52)


Research | Trial | Make Mistakes | Ask questions | Learn | Repeat

Offline

#10 2012-10-09 18:32:12

2ManyDogs
Forum Fellow
Registered: 2012-01-15
Posts: 4,645

Re: Bash script won't run "sudo reboot" under cron, but perfect manually

Try "sudo shutdown -r now" instead of "sudo reboot"

Last edited by 2ManyDogs (2012-10-09 18:35:03)


How to post. A sincere effort to use modest and proper language and grammar is a sign of respect toward the community.

Offline

#11 2012-10-09 19:29:47

Awebb
Member
Registered: 2010-05-06
Posts: 6,282

Re: Bash script won't run "sudo reboot" under cron, but perfect manually

(0. Switch to systemd)
1. Create a polkit rule for "systemctl reboot" or just "reboot"
2. Let the script reboot
3. Be happy.

Offline

#12 2012-10-10 22:37:40

teateawhy
Member
From: GER
Registered: 2012-03-05
Posts: 1,138
Website

Re: Bash script won't run "sudo reboot" under cron, but perfect manually

You void your warranty for forum help if you choose to do unattended upgrades.

Wormzy wrote:

You're going to have a nasty surprise waiting for you one morning if you keep doing that. Arch is not a hands-free distro, don't automate your updates.

You should rather update less often if you do not have the time for attending the upgrade.

You use mythtv , is your real problem not having physical access to the machine using the keyboard?
I recommend you to use an ssh login for updating instead of automatic updating.

Offline

#13 2012-10-11 07:00:44

DSpider
Member
From: Romania
Registered: 2009-08-23
Posts: 2,273

Re: Bash script won't run "sudo reboot" under cron, but perfect manually

wdirksen wrote:
DSpider wrote:

Post your /etc/sudoers file.

So here's my sudoers file:

## User privilege specification
##
root   ALL=(ALL) NOPASSWD: ALL
mythtv ALL=(ALL) NOPASSWD: ALL

You shouldn't run everything as root.

Just posted this yesterday: https://bbs.archlinux.org/viewtopic.php … 0#p1173450


"How to Succeed with Linux"

I have made a personal commitment not to reply in topics that start with a lowercase letter. Proper grammar and punctuation is a sign of respect, and if you do not show any, you will NOT receive any help (at least not from me).

Offline

Board footer

Powered by FluxBB