Shell script to autostart script

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
3
down vote

favorite












I would like to refer to my previous post here: Autostarting a python script whenever it crashes to restart two python scripts on my raspberry pi (Stretch OS) if they crash.



The code of the shell script called constantrun.sh is as follows:



#!/bin/sh

PYTHONPATH=/home/pi/.local/lib/python2.7/site-packages
COMMAND1=python /home/pi/project/script1.py
COMMAND2=python /home/pi/project/script2.py

rm -f COMMAND1_failed; ("$COMMAND1[@]"; touch COMMAND1_failed)&
rm -f COMMAND2_failed; ("$COMMAND2[@]"; touch COMMAND2_failed)&

while true
do
if [ -e COMMAND1_failed ]
then
# Restart Command1
rm -f COMMAND1_failed; ("$COMMAND1[@]"; touch COMMAND1_failed)&
fi
if [ -e COMMAND2_failed ]
then
# Restart Command2
rm -f COMMAND2_failed; ("$COMMAND2[@]"; touch COMMAND2_failed)&
fi

sleep 60
done


I ran the following commands in terminal:



sudo chmod +x constantrun.sh # to make the script executable


I then gave permission to my python scripts e.g. chmod +x /home/pi/project/script1.py



Next, to initialise the script, I used:



sudo sh constantrun.sh 


However, I got the following error messages:



/usr/bin/env: ‘pythonr’: No such file or directory
/usr/bin/env: ‘pythonr’: No such file or directory
constantrun.sh: 7: constantrun.sh: Bad substitution
constantrun.sh: 8: constantrun.sh: Bad substitution


How can I resolve these errors?










share|improve this question























  • Thanks Goro. I have another error when I provide permission to my script: /usr/bin/env: ‘pythonr’: No such file or directory /usr/bin/env: ‘pythonr’: No such file or directory constantrun.sh: 7: constantrun.sh: Bad substitution constantrun.sh: 8: constantrun.sh: Bad substitution
    – Craver2000
    Sep 16 at 13:49











  • Yes, I have python installed. Using which python returns: /usr/bin/python
    – Craver2000
    Sep 16 at 13:54











  • It returns: ln: failed to create symbolic link '/usr/bin/python': File exists
    – Craver2000
    Sep 16 at 13:57






  • 1




    Ah! probably your scripts contains CR characters., or dos_breaks. You can try ` vi +':wq ++ff=unix' script1.py; vi +':wq ++ff=unix' script2.py` or open the scripts in emacs then save the scripts again!
    – Goro
    Sep 16 at 14:04







  • 1




    I'll try the emacs method shortly
    – Craver2000
    Sep 16 at 14:17














up vote
3
down vote

favorite












I would like to refer to my previous post here: Autostarting a python script whenever it crashes to restart two python scripts on my raspberry pi (Stretch OS) if they crash.



The code of the shell script called constantrun.sh is as follows:



#!/bin/sh

PYTHONPATH=/home/pi/.local/lib/python2.7/site-packages
COMMAND1=python /home/pi/project/script1.py
COMMAND2=python /home/pi/project/script2.py

rm -f COMMAND1_failed; ("$COMMAND1[@]"; touch COMMAND1_failed)&
rm -f COMMAND2_failed; ("$COMMAND2[@]"; touch COMMAND2_failed)&

while true
do
if [ -e COMMAND1_failed ]
then
# Restart Command1
rm -f COMMAND1_failed; ("$COMMAND1[@]"; touch COMMAND1_failed)&
fi
if [ -e COMMAND2_failed ]
then
# Restart Command2
rm -f COMMAND2_failed; ("$COMMAND2[@]"; touch COMMAND2_failed)&
fi

sleep 60
done


I ran the following commands in terminal:



sudo chmod +x constantrun.sh # to make the script executable


I then gave permission to my python scripts e.g. chmod +x /home/pi/project/script1.py



Next, to initialise the script, I used:



sudo sh constantrun.sh 


However, I got the following error messages:



/usr/bin/env: ‘pythonr’: No such file or directory
/usr/bin/env: ‘pythonr’: No such file or directory
constantrun.sh: 7: constantrun.sh: Bad substitution
constantrun.sh: 8: constantrun.sh: Bad substitution


How can I resolve these errors?










share|improve this question























  • Thanks Goro. I have another error when I provide permission to my script: /usr/bin/env: ‘pythonr’: No such file or directory /usr/bin/env: ‘pythonr’: No such file or directory constantrun.sh: 7: constantrun.sh: Bad substitution constantrun.sh: 8: constantrun.sh: Bad substitution
    – Craver2000
    Sep 16 at 13:49











  • Yes, I have python installed. Using which python returns: /usr/bin/python
    – Craver2000
    Sep 16 at 13:54











  • It returns: ln: failed to create symbolic link '/usr/bin/python': File exists
    – Craver2000
    Sep 16 at 13:57






  • 1




    Ah! probably your scripts contains CR characters., or dos_breaks. You can try ` vi +':wq ++ff=unix' script1.py; vi +':wq ++ff=unix' script2.py` or open the scripts in emacs then save the scripts again!
    – Goro
    Sep 16 at 14:04







  • 1




    I'll try the emacs method shortly
    – Craver2000
    Sep 16 at 14:17












up vote
3
down vote

favorite









up vote
3
down vote

favorite











I would like to refer to my previous post here: Autostarting a python script whenever it crashes to restart two python scripts on my raspberry pi (Stretch OS) if they crash.



The code of the shell script called constantrun.sh is as follows:



#!/bin/sh

PYTHONPATH=/home/pi/.local/lib/python2.7/site-packages
COMMAND1=python /home/pi/project/script1.py
COMMAND2=python /home/pi/project/script2.py

rm -f COMMAND1_failed; ("$COMMAND1[@]"; touch COMMAND1_failed)&
rm -f COMMAND2_failed; ("$COMMAND2[@]"; touch COMMAND2_failed)&

while true
do
if [ -e COMMAND1_failed ]
then
# Restart Command1
rm -f COMMAND1_failed; ("$COMMAND1[@]"; touch COMMAND1_failed)&
fi
if [ -e COMMAND2_failed ]
then
# Restart Command2
rm -f COMMAND2_failed; ("$COMMAND2[@]"; touch COMMAND2_failed)&
fi

sleep 60
done


I ran the following commands in terminal:



sudo chmod +x constantrun.sh # to make the script executable


I then gave permission to my python scripts e.g. chmod +x /home/pi/project/script1.py



Next, to initialise the script, I used:



sudo sh constantrun.sh 


However, I got the following error messages:



/usr/bin/env: ‘pythonr’: No such file or directory
/usr/bin/env: ‘pythonr’: No such file or directory
constantrun.sh: 7: constantrun.sh: Bad substitution
constantrun.sh: 8: constantrun.sh: Bad substitution


How can I resolve these errors?










share|improve this question















I would like to refer to my previous post here: Autostarting a python script whenever it crashes to restart two python scripts on my raspberry pi (Stretch OS) if they crash.



The code of the shell script called constantrun.sh is as follows:



#!/bin/sh

PYTHONPATH=/home/pi/.local/lib/python2.7/site-packages
COMMAND1=python /home/pi/project/script1.py
COMMAND2=python /home/pi/project/script2.py

rm -f COMMAND1_failed; ("$COMMAND1[@]"; touch COMMAND1_failed)&
rm -f COMMAND2_failed; ("$COMMAND2[@]"; touch COMMAND2_failed)&

while true
do
if [ -e COMMAND1_failed ]
then
# Restart Command1
rm -f COMMAND1_failed; ("$COMMAND1[@]"; touch COMMAND1_failed)&
fi
if [ -e COMMAND2_failed ]
then
# Restart Command2
rm -f COMMAND2_failed; ("$COMMAND2[@]"; touch COMMAND2_failed)&
fi

sleep 60
done


I ran the following commands in terminal:



sudo chmod +x constantrun.sh # to make the script executable


I then gave permission to my python scripts e.g. chmod +x /home/pi/project/script1.py



Next, to initialise the script, I used:



sudo sh constantrun.sh 


However, I got the following error messages:



/usr/bin/env: ‘pythonr’: No such file or directory
/usr/bin/env: ‘pythonr’: No such file or directory
constantrun.sh: 7: constantrun.sh: Bad substitution
constantrun.sh: 8: constantrun.sh: Bad substitution


How can I resolve these errors?







shell-script debian python raspberry-pi crash






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 16 at 13:50

























asked Sep 16 at 13:40









Craver2000

316




316











  • Thanks Goro. I have another error when I provide permission to my script: /usr/bin/env: ‘pythonr’: No such file or directory /usr/bin/env: ‘pythonr’: No such file or directory constantrun.sh: 7: constantrun.sh: Bad substitution constantrun.sh: 8: constantrun.sh: Bad substitution
    – Craver2000
    Sep 16 at 13:49











  • Yes, I have python installed. Using which python returns: /usr/bin/python
    – Craver2000
    Sep 16 at 13:54











  • It returns: ln: failed to create symbolic link '/usr/bin/python': File exists
    – Craver2000
    Sep 16 at 13:57






  • 1




    Ah! probably your scripts contains CR characters., or dos_breaks. You can try ` vi +':wq ++ff=unix' script1.py; vi +':wq ++ff=unix' script2.py` or open the scripts in emacs then save the scripts again!
    – Goro
    Sep 16 at 14:04







  • 1




    I'll try the emacs method shortly
    – Craver2000
    Sep 16 at 14:17
















  • Thanks Goro. I have another error when I provide permission to my script: /usr/bin/env: ‘pythonr’: No such file or directory /usr/bin/env: ‘pythonr’: No such file or directory constantrun.sh: 7: constantrun.sh: Bad substitution constantrun.sh: 8: constantrun.sh: Bad substitution
    – Craver2000
    Sep 16 at 13:49











  • Yes, I have python installed. Using which python returns: /usr/bin/python
    – Craver2000
    Sep 16 at 13:54











  • It returns: ln: failed to create symbolic link '/usr/bin/python': File exists
    – Craver2000
    Sep 16 at 13:57






  • 1




    Ah! probably your scripts contains CR characters., or dos_breaks. You can try ` vi +':wq ++ff=unix' script1.py; vi +':wq ++ff=unix' script2.py` or open the scripts in emacs then save the scripts again!
    – Goro
    Sep 16 at 14:04







  • 1




    I'll try the emacs method shortly
    – Craver2000
    Sep 16 at 14:17















Thanks Goro. I have another error when I provide permission to my script: /usr/bin/env: ‘pythonr’: No such file or directory /usr/bin/env: ‘pythonr’: No such file or directory constantrun.sh: 7: constantrun.sh: Bad substitution constantrun.sh: 8: constantrun.sh: Bad substitution
– Craver2000
Sep 16 at 13:49





Thanks Goro. I have another error when I provide permission to my script: /usr/bin/env: ‘pythonr’: No such file or directory /usr/bin/env: ‘pythonr’: No such file or directory constantrun.sh: 7: constantrun.sh: Bad substitution constantrun.sh: 8: constantrun.sh: Bad substitution
– Craver2000
Sep 16 at 13:49













Yes, I have python installed. Using which python returns: /usr/bin/python
– Craver2000
Sep 16 at 13:54





Yes, I have python installed. Using which python returns: /usr/bin/python
– Craver2000
Sep 16 at 13:54













It returns: ln: failed to create symbolic link '/usr/bin/python': File exists
– Craver2000
Sep 16 at 13:57




It returns: ln: failed to create symbolic link '/usr/bin/python': File exists
– Craver2000
Sep 16 at 13:57




1




1




Ah! probably your scripts contains CR characters., or dos_breaks. You can try ` vi +':wq ++ff=unix' script1.py; vi +':wq ++ff=unix' script2.py` or open the scripts in emacs then save the scripts again!
– Goro
Sep 16 at 14:04





Ah! probably your scripts contains CR characters., or dos_breaks. You can try ` vi +':wq ++ff=unix' script1.py; vi +':wq ++ff=unix' script2.py` or open the scripts in emacs then save the scripts again!
– Goro
Sep 16 at 14:04





1




1




I'll try the emacs method shortly
– Craver2000
Sep 16 at 14:17




I'll try the emacs method shortly
– Craver2000
Sep 16 at 14:17










2 Answers
2






active

oldest

votes

















up vote
4
down vote













Problems with r are usually caused by using a Windows editor. Check your python scripts. The assignments to the command variables contain space. You use array syntax to refer to them, but don't define them as arrays. For PYTHONPATH to be useful, it must be exported.



There is a much simpler solution for this:



#!/bin/sh

export PYTHONPATH=/home/pi/.local/lib/python2.7/site-packages
COMMAND1="python /home/pi/project/script1.py"
COMMAND2="python /home/pi/project/script2.py"

(while true; do $COMMAND1; done &)
(while true; do $COMMAND2; done &)





share|improve this answer




















  • I've changed my script to the code as suggested above but I still get the error: /usr/bin/env: ‘pythonr’: No such file or directory /usr/bin/env: ‘pythonr’: No such file or directory constantrun.sh: 7: constantrun.sh: Bad substitution constantrun.sh: 8: constantrun.sh: Bad substitution
    – Craver2000
    Sep 17 at 12:59










  • The pythonr error is caused by your Windows line endings. And where in all your information is a hint about env being used?
    – RalfFriedl
    Sep 17 at 16:59

















up vote
4
down vote













I think there are two important issues here:



First: You have to differentiate between the location of your python executable, and the location of the lib site-packages.



Your python site-packages are here:



/home/pi/.local/lib/python2.7/site-packages


But your executables are here:



/usr/bin



When you ran the command which python it told you that the executables are in /usr/bin



Your $PATH environment variable should contain paths that have executable files i.e.



$ echo $PATH /usr/bin:/usr/local/bin:/home/User/bin


If your executable is in another location other than your path, and you don't want to necessarily add that location to your path, then you can just create symbolic link. For example:



ln -s /path/to/executable /usr/bin/executable


Second: You had created your pythons in Windows, then you moved the scripts to Linux environment, probably your scripts contains CR characters, or dos breaks. You can clean the scripts from the CR characters as follows:



vi +':wq ++ff=unix' script1.py
vi +':wq ++ff=unix' script2.py


Or simply, open the scripts "script1.py", and "script2.py" in emacs and then save them again. This will remove the CR characters automatically.






share|improve this answer






















  • I've just tried to save those scripts with emacs but I still get the error /usr/bin/env: ‘pythonr’: No such file or directory /usr/bin/env: ‘pythonr’: No such file or directory constantrun.sh: 7: constantrun.sh: Bad substitution constantrun.sh: 8: constantrun.sh: Bad substitution
    – Craver2000
    Sep 17 at 12:54











  • Yes I did update python first with sudo apt-get update first and then sudo apt install --reinstall python python-apt python2.7-minimal. I also noticed that when I run these scripts individually with (ie. python script.py) on terminal, they worked. However, running them via shellscript produced the aforementioned error. `
    – Craver2000
    Sep 17 at 13:31











Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f469391%2fshell-script-to-autostart-script%23new-answer', 'question_page');

);

Post as a guest






























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
4
down vote













Problems with r are usually caused by using a Windows editor. Check your python scripts. The assignments to the command variables contain space. You use array syntax to refer to them, but don't define them as arrays. For PYTHONPATH to be useful, it must be exported.



There is a much simpler solution for this:



#!/bin/sh

export PYTHONPATH=/home/pi/.local/lib/python2.7/site-packages
COMMAND1="python /home/pi/project/script1.py"
COMMAND2="python /home/pi/project/script2.py"

(while true; do $COMMAND1; done &)
(while true; do $COMMAND2; done &)





share|improve this answer




















  • I've changed my script to the code as suggested above but I still get the error: /usr/bin/env: ‘pythonr’: No such file or directory /usr/bin/env: ‘pythonr’: No such file or directory constantrun.sh: 7: constantrun.sh: Bad substitution constantrun.sh: 8: constantrun.sh: Bad substitution
    – Craver2000
    Sep 17 at 12:59










  • The pythonr error is caused by your Windows line endings. And where in all your information is a hint about env being used?
    – RalfFriedl
    Sep 17 at 16:59














up vote
4
down vote













Problems with r are usually caused by using a Windows editor. Check your python scripts. The assignments to the command variables contain space. You use array syntax to refer to them, but don't define them as arrays. For PYTHONPATH to be useful, it must be exported.



There is a much simpler solution for this:



#!/bin/sh

export PYTHONPATH=/home/pi/.local/lib/python2.7/site-packages
COMMAND1="python /home/pi/project/script1.py"
COMMAND2="python /home/pi/project/script2.py"

(while true; do $COMMAND1; done &)
(while true; do $COMMAND2; done &)





share|improve this answer




















  • I've changed my script to the code as suggested above but I still get the error: /usr/bin/env: ‘pythonr’: No such file or directory /usr/bin/env: ‘pythonr’: No such file or directory constantrun.sh: 7: constantrun.sh: Bad substitution constantrun.sh: 8: constantrun.sh: Bad substitution
    – Craver2000
    Sep 17 at 12:59










  • The pythonr error is caused by your Windows line endings. And where in all your information is a hint about env being used?
    – RalfFriedl
    Sep 17 at 16:59












up vote
4
down vote










up vote
4
down vote









Problems with r are usually caused by using a Windows editor. Check your python scripts. The assignments to the command variables contain space. You use array syntax to refer to them, but don't define them as arrays. For PYTHONPATH to be useful, it must be exported.



There is a much simpler solution for this:



#!/bin/sh

export PYTHONPATH=/home/pi/.local/lib/python2.7/site-packages
COMMAND1="python /home/pi/project/script1.py"
COMMAND2="python /home/pi/project/script2.py"

(while true; do $COMMAND1; done &)
(while true; do $COMMAND2; done &)





share|improve this answer












Problems with r are usually caused by using a Windows editor. Check your python scripts. The assignments to the command variables contain space. You use array syntax to refer to them, but don't define them as arrays. For PYTHONPATH to be useful, it must be exported.



There is a much simpler solution for this:



#!/bin/sh

export PYTHONPATH=/home/pi/.local/lib/python2.7/site-packages
COMMAND1="python /home/pi/project/script1.py"
COMMAND2="python /home/pi/project/script2.py"

(while true; do $COMMAND1; done &)
(while true; do $COMMAND2; done &)






share|improve this answer












share|improve this answer



share|improve this answer










answered Sep 16 at 14:20









RalfFriedl

4,1251725




4,1251725











  • I've changed my script to the code as suggested above but I still get the error: /usr/bin/env: ‘pythonr’: No such file or directory /usr/bin/env: ‘pythonr’: No such file or directory constantrun.sh: 7: constantrun.sh: Bad substitution constantrun.sh: 8: constantrun.sh: Bad substitution
    – Craver2000
    Sep 17 at 12:59










  • The pythonr error is caused by your Windows line endings. And where in all your information is a hint about env being used?
    – RalfFriedl
    Sep 17 at 16:59
















  • I've changed my script to the code as suggested above but I still get the error: /usr/bin/env: ‘pythonr’: No such file or directory /usr/bin/env: ‘pythonr’: No such file or directory constantrun.sh: 7: constantrun.sh: Bad substitution constantrun.sh: 8: constantrun.sh: Bad substitution
    – Craver2000
    Sep 17 at 12:59










  • The pythonr error is caused by your Windows line endings. And where in all your information is a hint about env being used?
    – RalfFriedl
    Sep 17 at 16:59















I've changed my script to the code as suggested above but I still get the error: /usr/bin/env: ‘pythonr’: No such file or directory /usr/bin/env: ‘pythonr’: No such file or directory constantrun.sh: 7: constantrun.sh: Bad substitution constantrun.sh: 8: constantrun.sh: Bad substitution
– Craver2000
Sep 17 at 12:59




I've changed my script to the code as suggested above but I still get the error: /usr/bin/env: ‘pythonr’: No such file or directory /usr/bin/env: ‘pythonr’: No such file or directory constantrun.sh: 7: constantrun.sh: Bad substitution constantrun.sh: 8: constantrun.sh: Bad substitution
– Craver2000
Sep 17 at 12:59












The pythonr error is caused by your Windows line endings. And where in all your information is a hint about env being used?
– RalfFriedl
Sep 17 at 16:59




The pythonr error is caused by your Windows line endings. And where in all your information is a hint about env being used?
– RalfFriedl
Sep 17 at 16:59












up vote
4
down vote













I think there are two important issues here:



First: You have to differentiate between the location of your python executable, and the location of the lib site-packages.



Your python site-packages are here:



/home/pi/.local/lib/python2.7/site-packages


But your executables are here:



/usr/bin



When you ran the command which python it told you that the executables are in /usr/bin



Your $PATH environment variable should contain paths that have executable files i.e.



$ echo $PATH /usr/bin:/usr/local/bin:/home/User/bin


If your executable is in another location other than your path, and you don't want to necessarily add that location to your path, then you can just create symbolic link. For example:



ln -s /path/to/executable /usr/bin/executable


Second: You had created your pythons in Windows, then you moved the scripts to Linux environment, probably your scripts contains CR characters, or dos breaks. You can clean the scripts from the CR characters as follows:



vi +':wq ++ff=unix' script1.py
vi +':wq ++ff=unix' script2.py


Or simply, open the scripts "script1.py", and "script2.py" in emacs and then save them again. This will remove the CR characters automatically.






share|improve this answer






















  • I've just tried to save those scripts with emacs but I still get the error /usr/bin/env: ‘pythonr’: No such file or directory /usr/bin/env: ‘pythonr’: No such file or directory constantrun.sh: 7: constantrun.sh: Bad substitution constantrun.sh: 8: constantrun.sh: Bad substitution
    – Craver2000
    Sep 17 at 12:54











  • Yes I did update python first with sudo apt-get update first and then sudo apt install --reinstall python python-apt python2.7-minimal. I also noticed that when I run these scripts individually with (ie. python script.py) on terminal, they worked. However, running them via shellscript produced the aforementioned error. `
    – Craver2000
    Sep 17 at 13:31















up vote
4
down vote













I think there are two important issues here:



First: You have to differentiate between the location of your python executable, and the location of the lib site-packages.



Your python site-packages are here:



/home/pi/.local/lib/python2.7/site-packages


But your executables are here:



/usr/bin



When you ran the command which python it told you that the executables are in /usr/bin



Your $PATH environment variable should contain paths that have executable files i.e.



$ echo $PATH /usr/bin:/usr/local/bin:/home/User/bin


If your executable is in another location other than your path, and you don't want to necessarily add that location to your path, then you can just create symbolic link. For example:



ln -s /path/to/executable /usr/bin/executable


Second: You had created your pythons in Windows, then you moved the scripts to Linux environment, probably your scripts contains CR characters, or dos breaks. You can clean the scripts from the CR characters as follows:



vi +':wq ++ff=unix' script1.py
vi +':wq ++ff=unix' script2.py


Or simply, open the scripts "script1.py", and "script2.py" in emacs and then save them again. This will remove the CR characters automatically.






share|improve this answer






















  • I've just tried to save those scripts with emacs but I still get the error /usr/bin/env: ‘pythonr’: No such file or directory /usr/bin/env: ‘pythonr’: No such file or directory constantrun.sh: 7: constantrun.sh: Bad substitution constantrun.sh: 8: constantrun.sh: Bad substitution
    – Craver2000
    Sep 17 at 12:54











  • Yes I did update python first with sudo apt-get update first and then sudo apt install --reinstall python python-apt python2.7-minimal. I also noticed that when I run these scripts individually with (ie. python script.py) on terminal, they worked. However, running them via shellscript produced the aforementioned error. `
    – Craver2000
    Sep 17 at 13:31













up vote
4
down vote










up vote
4
down vote









I think there are two important issues here:



First: You have to differentiate between the location of your python executable, and the location of the lib site-packages.



Your python site-packages are here:



/home/pi/.local/lib/python2.7/site-packages


But your executables are here:



/usr/bin



When you ran the command which python it told you that the executables are in /usr/bin



Your $PATH environment variable should contain paths that have executable files i.e.



$ echo $PATH /usr/bin:/usr/local/bin:/home/User/bin


If your executable is in another location other than your path, and you don't want to necessarily add that location to your path, then you can just create symbolic link. For example:



ln -s /path/to/executable /usr/bin/executable


Second: You had created your pythons in Windows, then you moved the scripts to Linux environment, probably your scripts contains CR characters, or dos breaks. You can clean the scripts from the CR characters as follows:



vi +':wq ++ff=unix' script1.py
vi +':wq ++ff=unix' script2.py


Or simply, open the scripts "script1.py", and "script2.py" in emacs and then save them again. This will remove the CR characters automatically.






share|improve this answer














I think there are two important issues here:



First: You have to differentiate between the location of your python executable, and the location of the lib site-packages.



Your python site-packages are here:



/home/pi/.local/lib/python2.7/site-packages


But your executables are here:



/usr/bin



When you ran the command which python it told you that the executables are in /usr/bin



Your $PATH environment variable should contain paths that have executable files i.e.



$ echo $PATH /usr/bin:/usr/local/bin:/home/User/bin


If your executable is in another location other than your path, and you don't want to necessarily add that location to your path, then you can just create symbolic link. For example:



ln -s /path/to/executable /usr/bin/executable


Second: You had created your pythons in Windows, then you moved the scripts to Linux environment, probably your scripts contains CR characters, or dos breaks. You can clean the scripts from the CR characters as follows:



vi +':wq ++ff=unix' script1.py
vi +':wq ++ff=unix' script2.py


Or simply, open the scripts "script1.py", and "script2.py" in emacs and then save them again. This will remove the CR characters automatically.







share|improve this answer














share|improve this answer



share|improve this answer








edited Sep 16 at 14:40

























answered Sep 16 at 14:21









Goro

5,79052662




5,79052662











  • I've just tried to save those scripts with emacs but I still get the error /usr/bin/env: ‘pythonr’: No such file or directory /usr/bin/env: ‘pythonr’: No such file or directory constantrun.sh: 7: constantrun.sh: Bad substitution constantrun.sh: 8: constantrun.sh: Bad substitution
    – Craver2000
    Sep 17 at 12:54











  • Yes I did update python first with sudo apt-get update first and then sudo apt install --reinstall python python-apt python2.7-minimal. I also noticed that when I run these scripts individually with (ie. python script.py) on terminal, they worked. However, running them via shellscript produced the aforementioned error. `
    – Craver2000
    Sep 17 at 13:31

















  • I've just tried to save those scripts with emacs but I still get the error /usr/bin/env: ‘pythonr’: No such file or directory /usr/bin/env: ‘pythonr’: No such file or directory constantrun.sh: 7: constantrun.sh: Bad substitution constantrun.sh: 8: constantrun.sh: Bad substitution
    – Craver2000
    Sep 17 at 12:54











  • Yes I did update python first with sudo apt-get update first and then sudo apt install --reinstall python python-apt python2.7-minimal. I also noticed that when I run these scripts individually with (ie. python script.py) on terminal, they worked. However, running them via shellscript produced the aforementioned error. `
    – Craver2000
    Sep 17 at 13:31
















I've just tried to save those scripts with emacs but I still get the error /usr/bin/env: ‘pythonr’: No such file or directory /usr/bin/env: ‘pythonr’: No such file or directory constantrun.sh: 7: constantrun.sh: Bad substitution constantrun.sh: 8: constantrun.sh: Bad substitution
– Craver2000
Sep 17 at 12:54





I've just tried to save those scripts with emacs but I still get the error /usr/bin/env: ‘pythonr’: No such file or directory /usr/bin/env: ‘pythonr’: No such file or directory constantrun.sh: 7: constantrun.sh: Bad substitution constantrun.sh: 8: constantrun.sh: Bad substitution
– Craver2000
Sep 17 at 12:54













Yes I did update python first with sudo apt-get update first and then sudo apt install --reinstall python python-apt python2.7-minimal. I also noticed that when I run these scripts individually with (ie. python script.py) on terminal, they worked. However, running them via shellscript produced the aforementioned error. `
– Craver2000
Sep 17 at 13:31





Yes I did update python first with sudo apt-get update first and then sudo apt install --reinstall python python-apt python2.7-minimal. I also noticed that when I run these scripts individually with (ie. python script.py) on terminal, they worked. However, running them via shellscript produced the aforementioned error. `
– Craver2000
Sep 17 at 13:31


















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f469391%2fshell-script-to-autostart-script%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

Peggy Mitchell

Palaiologos

The Forum (Inglewood, California)