Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

414
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda