(Solved) CronTab -e VS SUDO

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
opale7000

(Solved) CronTab -e VS SUDO

Post by opale7000 »

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 LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
FreedomTruth
Level 4
Level 4
Posts: 443
Joined: Fri Sep 23, 2016 10:19 am

Re: CronTab -e VS SUDO

Post by FreedomTruth »

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
lmuserx4849

Re: CronTab -e VS SUDO

Post by lmuserx4849 »

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

Re: CronTab -e VS SUDO

Post by Habitual »

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

Get Some!
opale7000

Re: CronTab -e VS SUDO

Post by opale7000 »

Good stuff. Thanks
Locked

Return to “Scripts & Bash”