Shell script to autostart script

Clash 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?
shell-script debian python raspberry-pi crash
 |Â
show 4 more comments
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?
shell-script debian python raspberry-pi crash
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. Usingwhich pythonreturns:/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 inemacsthen save the scripts again!
â Goro
Sep 16 at 14:04
1
I'll try the emacs method shortly
â Craver2000
Sep 16 at 14:17
 |Â
show 4 more comments
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?
shell-script debian python raspberry-pi crash
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
shell-script debian python raspberry-pi crash
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. Usingwhich pythonreturns:/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 inemacsthen save the scripts again!
â Goro
Sep 16 at 14:04
1
I'll try the emacs method shortly
â Craver2000
Sep 16 at 14:17
 |Â
show 4 more comments
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. Usingwhich pythonreturns:/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 inemacsthen 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
 |Â
show 4 more comments
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 &)
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
Thepythonrerror is caused by your Windows line endings. And where in all your information is a hint aboutenvbeing used?
â RalfFriedl
Sep 17 at 16:59
add a comment |Â
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.
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 withsudo apt-get updatefirst and thensudo 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
add a comment |Â
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 &)
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
Thepythonrerror is caused by your Windows line endings. And where in all your information is a hint aboutenvbeing used?
â RalfFriedl
Sep 17 at 16:59
add a comment |Â
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 &)
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
Thepythonrerror is caused by your Windows line endings. And where in all your information is a hint aboutenvbeing used?
â RalfFriedl
Sep 17 at 16:59
add a comment |Â
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 &)
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 &)
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
Thepythonrerror is caused by your Windows line endings. And where in all your information is a hint aboutenvbeing used?
â RalfFriedl
Sep 17 at 16:59
add a comment |Â
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
Thepythonrerror is caused by your Windows line endings. And where in all your information is a hint aboutenvbeing 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
add a comment |Â
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.
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 withsudo apt-get updatefirst and thensudo 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
add a comment |Â
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.
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 withsudo apt-get updatefirst and thensudo 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
add a comment |Â
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.
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.
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 withsudo apt-get updatefirst and thensudo 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
add a comment |Â
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 withsudo apt-get updatefirst and thensudo 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
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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 pythonreturns:/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 inemacsthen save the scripts again!â Goro
Sep 16 at 14:04
1
I'll try the emacs method shortly
â Craver2000
Sep 16 at 14:17