Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

How can i start a python script.py after a reboot as user xy in Debian Squeeze automatically?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

Put an entry in rc.local with something similar to the following:

su user_xy -c "script.py" 

to execute the program as that user:

su - user_xy -c "script.py"
share|improve this answer
    
you can add sudo too ... sudo su - user_xy -c "script.py" –  Daniel t. Mar 11 '13 at 16:50
1  
@Danielt. I would strongly advise against using sudo in rc startup scripts (mainly because those scripts are already running as root). –  voretaq7 Mar 11 '13 at 17:01
    
But how can i run it as user_xy, so the process is owned by user_xy? –  Ulfric Storm Mar 11 '13 at 20:16
    
su - user_xy -c "script.py" note the dash. updated answer, accept it if you don't have additional questions –  tristan Mar 11 '13 at 20:32

You can use @reboot entry in crontab of user root or user xy. Debian cron supports such entries.

man -S5 crontab

string         meaning
------         -------
@reboot        Run once, at startup.
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.