Solved [xbmcbuntu] crontab as root help needed
#1
Hi guys,

I am totally new to linux, my only experience is my xbmcbunt machine...

I manged to pu together small python script to shutdown my system, when
I execute it from ssh terminal it works fine.

I tried adding it to my crontab, it fires up (i see log entries)
but it does not shutdown my system.

I guess i shoud add it as root.

Ttried adding it to crontab as root with
Code:
crontab -u root -e

but that does not work.

Can somebody pls help

If you need some more info just tell me what you need

Thanks
Reply
#2
OK so I made a little progress

entered following:

Code:
sudo env EDITOR=nano crontab -e

I edited crontab for root so it looks like this

Code:
50 13 * * *  /usr/bin/python /home/sinisa/shut.py

now if I look at crontab log and my script log script is up and running.
But for some reason it does not put my system to sleep, but when I
run it manually it works.

Commands I use to run manually

Code:
sudo python /home/sinisa/shut.py

I thought if I put it in crontab as root I will execute without need to enter root pwd.

Any advice is welcomed.

Thanks
Reply
#3
(2012-10-22, 10:58)Burke Wrote: Tried adding it to crontab as root with
Code:
crontab -u root -e

but that does not work.

Note for the future: Simply 'does not work' most of the time doesn't bring you any solution. Give more detailed information, error description, output etc.

Have you tried
Code:
sudo crontab -u root -e

Btw, why phyton script for just shutting down? If you just want your htpc to simply shutdown at a given time, take a look at this post: http://ubuntuforums.org/showpost.php?p=7...ostcount=9
Reply
#4

Code:
sudo env EDITOR=nano crontab -e

I use dthis to edit crontab, now script si starting but it is not putting my pc to sleep.

Script is "watching" my sabnzbd+ over night.
If queue is empty, adnd sab is not repairing, post processing, checking, or unpacking any files it
sends computer to sleep.

Reply
#5
here is my crontab log

Code:
Oct 22 15:27:51 Xbmc cron[1002]: (CRON) INFO (Running @reboot jobs)
Oct 22 15:30:01 Xbmc CRON[2392]: (root) CMD (/usr/bin/python /home/sinisa/shut.py)
Oct 22 15:43:43 Xbmc cron[1003]: (CRON) INFO (pidfile fd = 3)

so script is executed with no problems.

The problem is, well this is my best guess that I need to be able to shutdown my pc without password.
This is described here.

But file '/etc/sudoers/ ' in xbmcbuntu looks a bit different and I am afraid not to mess something up.

pls advise


Reply
#6
What does the sudoers file look like? And you should be editing /etc/sudoers.
Reply
#7
Dont't knoe if this helps, but crontab needs a newline after each command.

From 'man crontab'

Quote:cron requires that each entry in a crontab end in a newline character. If the last
entry in a crontab is missing the newline, cron will consider the crontab (at least
partially) broken and refuse to install it.

Jerry
Reply
#8
(2012-10-22, 17:48)Burke Wrote: But file '/etc/sudoers/ ' in xbmcbuntu looks a bit different and I am afraid not to mess something up.

Just a note of caution: Do not use a regular text editor to update sudoers; instead, use the visudo command:
Code:
sudo visudo

Reply
#9
Thank you guys for all your replays.

I am new to linux and most of this things ara new to me, so your help
is greatly appreciated

(2012-10-22, 21:42)teeedubb Wrote: What does the sudoers file look like? And you should be editing /etc/sudoers.
It has some extra entries - in the end mine needed to be added at bottom of file Tongue

(2012-10-22, 21:47)jawilljr Wrote: Dont't knoe if this helps, but crontab needs a newline after each command.

From 'man crontab'

Quote:cron requires that each entry in a crontab end in a newline character. If the last
entry in a crontab is missing the newline, cron will consider the crontab (at least
partially) broken and refuse to install it.

Jerry
Thank you - good to know Smile

(2012-10-22, 22:09)artrafael Wrote:
(2012-10-22, 17:48)Burke Wrote: But file '/etc/sudoers/ ' in xbmcbuntu looks a bit different and I am afraid not to mess something up.

Just a note of caution: Do not use a regular text editor to update sudoers; instead, use the visudo command:
Code:
sudo visudo
Figured out that one the hard way. Confused

This is what i figured.

No mater what i do i will fall on my phaton script, it needs to be run directly as sudo
(as far as I can tell).

I have removed need to enter pass for suspend command, and my script is executed
under root user in crontab but it does not put my system to sleep.

Workaround for this can be executing sh script with crontab and using that script to enter
pass and call py script.

Code:
#!/bin/bash
echo my_awesome_password | sudo -S python awesome_script.py

This was the only way I found to suspend system using my script, but not calling
it directly form terminal. Nod

Thank you!

Burke



Reply
#10
(2012-10-22, 22:09)artrafael Wrote:
(2012-10-22, 17:48)Burke Wrote: But file '/etc/sudoers/ ' in xbmcbuntu looks a bit different and I am afraid not to mess something up.

Just a note of caution: Do not use a regular text editor to update sudoers; instead, use the visudo command:
Code:
sudo visudo

Damn I forgot about that, thanks for clarifying.
Reply

Logout Mark Read Team Forum Stats Members Help
[xbmcbuntu] crontab as root help needed 0