(Solved) CronTab -e VS SUDO

Forum rules
Before you post please read how to get help
opale7000
Level 2
Level 2
Posts: 90
Joined: Fri May 19, 2017 9:04 am

(Solved) CronTab -e VS SUDO

Postby opale7000 » Fri Jun 09, 2017 6:54 pm

Hello minty friends.

Code: Select all

#0 1 * * *  mail -s "Daily reminder"
Here is a partial sample command in my crontab

Can I :?: add

Code: Select all

sudo shutdown -h 23:00
on a new line in crontab :?: my concern is with the sudo command.

Thanks
Last edited by opale7000 on Sat Jun 10, 2017 6:56 pm, edited 1 time in total.

FreedomTruth
Level 4
Level 4
Posts: 326
Joined: Fri Sep 23, 2016 10:19 am

Re: CronTab -e VS SUDO

Postby FreedomTruth » Fri Jun 09, 2017 9:00 pm

I don't know the answer (I'd have to try it and find out, I guess) .. but may I recommend instead to add this to /etc/crontab if it requires sudo? It's the same basic format as your user crontab, with the added field of "user", so the line would probably be as follows

Code: Select all

0 23 * * * root shutdown now
If you abide in My word, you are My disciples indeed. And you shall know the truth, and the truth shall make you free... Most assuredly, I say to you, whoever commits sin is a slave of sin... Therefore if the Son makes you free, you shall be free indeed.

lmuserx4849
Level 4
Level 4
Posts: 489
Joined: Wed Dec 17, 2014 2:55 am

Re: CronTab -e VS SUDO

Postby lmuserx4849 » Sat Jun 10, 2017 1:51 am

Edit the system crontab (notice the extra userid field) or /etc/cron.daily (checkout the other /etc/cron* files). No sudo required here. Or point your crontab to a script with the command.
See: man 8 cron & man crontab

Shutdown also has a timer:
sudo shutdown -h 22:00 &
sudo shutdown -c # cancel

I don't know what systemd offers (>LM 17.3) for timer units.

Habitual
Level 13
Level 13
Posts: 4866
Joined: Sun Nov 21, 2010 8:31 pm
Location: 0.0.0.0

Re: CronTab -e VS SUDO

Postby Habitual » Sat Jun 10, 2017 9:28 am

Sudo: you're doing it wrong - PDF @ 171 pages.
Sudo: you're doing it wrong - YouTubeVid @ 1h:11m

Get Some!

opale7000
Level 2
Level 2
Posts: 90
Joined: Fri May 19, 2017 9:04 am

Re: CronTab -e VS SUDO

Postby opale7000 » Sat Jun 10, 2017 6:55 pm

Good stuff. Thanks


Return to “Scripts & Bash”