Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to run a python script at boot as a particular user.

The script is a server (listens on a socket, serves requests, etc) and should be run in the background, with any output preferably piped to a log file.

My current approach is to add an entry at the end of rc.local like this:

su -l usr -c ' arg1 arg2 &> logfile.log &'

The problem: In the script i have several print statements in the script. They never show up in the log file. I've tried

su -l usr -c ' arg1 arg2 &> logfile.log &'

su -l usr -c ' arg arg &> logfile.log &' &> secondLogfile.log &

su -l usr -c ' arg arg &> logfile.log &'

su usr -c ' arg arg &> logfile.log &'

I have the feeling i'm missing something basic. Maybe i'm going about it in totally the wrong way.

System is Fedora 15, script is Python3 and runs fine from the command line as the user. User has write permissions to the folder i want the output redirected to. (I ruled it out by making the folder 777).

I tried having the python script run as a Systemd service, but i was having issues with my script being able to grab a socket to listen on. (throwing an OS error about socket in use if i enabled the systemd service at boot, whereas if i ran systemctl start script.service after boot things worked fine).

How can i launch a python script as a user at boot that grabs a socket?

share|improve this question
can you not just use a @reboot line in a /etc/cron.d/ file ? – Sirex Aug 23 '12 at 2:01

This works for me:

su -l usr -c "python arg1 arg2 > logfile.txt &"

I believe the previous & is pushing "python" into the background prematurely.

share|improve this answer
up vote 0 down vote accepted

The @Reboot line worked like a charm in crontab. Freetx's answer didn't work for me ( i tried something exactly like it and no dice :-(

share|improve this answer

Your Answer


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.