Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

406
Views
Run python script from rc.local does not execute

I want to run a python script on boot of ubuntu 14.04LTS.

My rc.local file is as follows:

sudo /home/hduser/morey/zookeeper-3.3.6/bin/zkServer.sh start

echo "test" > /home/hduser/test3

sudo /home/hduser/morey/kafka/bin/kafka-server-start.sh /home/hduser/morey/kafka/config/server.properties &

echo "test" > /home/hduser/test1

/usr/bin/python /home/hduser/morey/kafka/automate.py &

echo "test" > /home/hduser/test2

exit 0

everything except my python script is working fine even the echo statement after running the python script, but the python script doesnt seem to run. My python script is as follows

import sys
from subprocess import Popen, PIPE, STDOUT

cmd = ["sudo", "./sbt", "project java-examples", "run"]
proc = Popen(cmd, shell=False, stdout=PIPE, stdin=PIPE, stderr=STDOUT)
proc.communicate(input='1\n')
proc.stdin.close()

which works perfectly fine if executed individually.

I went through the following questions , link

I did a lot of research but couldn't find a solution

Edit : echo statements are for testing purpose only, and the second actual command (not considering the echo statements) is starting a server which keeps on running, and even the python script starts a listener which runs on an infinite loop, if this is any help

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

The Python script tries to launch ./sbt. Are you sure of what if the current directory when rc.local runs? The rule is always use absolute paths in system scripts

over 4 years ago · Santiago Trujillo Report

0

Do not run the Python script in background, run it in foreground. Do not exit from its parent script. Better call another script from "rc.local" that does all the job of "echo" and script launching.

Run that script from "rc.local"; not in background (no &).

You do not need "sudo" as "rc.local" is run as root.

over 4 years ago · Santiago Trujillo Report

0

If you want to run python script at system boot there is an alternate solution which i have used.

1:Create sh file like sample.sh and copy paste following content

#!/bin/bash
clear


python yourscript.py

2:Now add a cron job at reboot.If you are using linux you can use as following

a:Run crontab -e(Install sudo apt-get install cron)
b:@reboot /full path to sh file > /home/path/error.log 2>&1

And restart your device

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!