How to get a shell script to execute correctly on reboot

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












0















I have a shell script that gets updates from github and then runs the code that it retrieved. it is located at /home/me/Desktop/refreshCode.sh



-- refreshCode.sh --

#!/bin/bash

cd /home/me/src/ProductionMonitor
sudo /usr/bin git -C /home/me/src/ProductionMonitor pull
sudo cp /home/me/src/ProductionMonitor/* /home/me/Desktop/Production
cd /home/me/Desktop/Production
sudo /usr/bin/python3 prodmain.py >> logfile.data


I know that the shell can launch and runs as expected manually. It opens up the tkinter window and I can interact with the screen.



However I cannot seem to get anything to launch correctly.



I have tried setting up a crontab for @reboot and was not successful.
It never showed the ui



I set up a Systemd service as such.



-- prodmon.service --

[Unit]
Description=Service to run production monitor
After=multi-user.target

[Service]
Type=forking
ExecStart=/home/me/Desktop/refreshCode.sh
User=caleb
Group=caleb
WorkingDirectory=/home/me/Desktop/Production/
PIDFile=/var/run/prodmon.pid

[Install]
WantedBy=multi-user.target


Checking the status of the service after boot, it says that it is running.
however the tkinter UI never shows up.










share|improve this question



















  • 3





    Instead of sudo /usr/bin git... you probably mean sudo /usr/bin/git... What do you mean with "It never showed the ui"? A program run by cron should never show a UI. It should do some work and write messages to a logfile or to syslog. If you want to run a program with a graphical UI, see askubuntu.com/q/37957

    – Bodo
    Mar 5 at 17:52






  • 4





    Why on Earth do you require superuser access to write files into your own home directory?

    – JdeBP
    Mar 5 at 17:53











  • @JdeBP most of the reason you see an overuse of the sudo command is because I am pretty new to Linux. I don't want to sit and fight permissions right now so I sudo everything I can. I know its terrible practice and Ive been warned by many linux users that I need to correct it

    – caleb baker
    Mar 5 at 19:16











  • The thing is that using sudo without thinking twice is the reason why you have to "fight permissions". It leads to all kinds of files being owned by root when they shouldn't be, requiring another sudo to access them and so on. Better chown everything in your home back to your user and stop using sudo unless absolutely necessary.

    – TooTea
    Mar 5 at 19:21















0















I have a shell script that gets updates from github and then runs the code that it retrieved. it is located at /home/me/Desktop/refreshCode.sh



-- refreshCode.sh --

#!/bin/bash

cd /home/me/src/ProductionMonitor
sudo /usr/bin git -C /home/me/src/ProductionMonitor pull
sudo cp /home/me/src/ProductionMonitor/* /home/me/Desktop/Production
cd /home/me/Desktop/Production
sudo /usr/bin/python3 prodmain.py >> logfile.data


I know that the shell can launch and runs as expected manually. It opens up the tkinter window and I can interact with the screen.



However I cannot seem to get anything to launch correctly.



I have tried setting up a crontab for @reboot and was not successful.
It never showed the ui



I set up a Systemd service as such.



-- prodmon.service --

[Unit]
Description=Service to run production monitor
After=multi-user.target

[Service]
Type=forking
ExecStart=/home/me/Desktop/refreshCode.sh
User=caleb
Group=caleb
WorkingDirectory=/home/me/Desktop/Production/
PIDFile=/var/run/prodmon.pid

[Install]
WantedBy=multi-user.target


Checking the status of the service after boot, it says that it is running.
however the tkinter UI never shows up.










share|improve this question



















  • 3





    Instead of sudo /usr/bin git... you probably mean sudo /usr/bin/git... What do you mean with "It never showed the ui"? A program run by cron should never show a UI. It should do some work and write messages to a logfile or to syslog. If you want to run a program with a graphical UI, see askubuntu.com/q/37957

    – Bodo
    Mar 5 at 17:52






  • 4





    Why on Earth do you require superuser access to write files into your own home directory?

    – JdeBP
    Mar 5 at 17:53











  • @JdeBP most of the reason you see an overuse of the sudo command is because I am pretty new to Linux. I don't want to sit and fight permissions right now so I sudo everything I can. I know its terrible practice and Ive been warned by many linux users that I need to correct it

    – caleb baker
    Mar 5 at 19:16











  • The thing is that using sudo without thinking twice is the reason why you have to "fight permissions". It leads to all kinds of files being owned by root when they shouldn't be, requiring another sudo to access them and so on. Better chown everything in your home back to your user and stop using sudo unless absolutely necessary.

    – TooTea
    Mar 5 at 19:21













0












0








0








I have a shell script that gets updates from github and then runs the code that it retrieved. it is located at /home/me/Desktop/refreshCode.sh



-- refreshCode.sh --

#!/bin/bash

cd /home/me/src/ProductionMonitor
sudo /usr/bin git -C /home/me/src/ProductionMonitor pull
sudo cp /home/me/src/ProductionMonitor/* /home/me/Desktop/Production
cd /home/me/Desktop/Production
sudo /usr/bin/python3 prodmain.py >> logfile.data


I know that the shell can launch and runs as expected manually. It opens up the tkinter window and I can interact with the screen.



However I cannot seem to get anything to launch correctly.



I have tried setting up a crontab for @reboot and was not successful.
It never showed the ui



I set up a Systemd service as such.



-- prodmon.service --

[Unit]
Description=Service to run production monitor
After=multi-user.target

[Service]
Type=forking
ExecStart=/home/me/Desktop/refreshCode.sh
User=caleb
Group=caleb
WorkingDirectory=/home/me/Desktop/Production/
PIDFile=/var/run/prodmon.pid

[Install]
WantedBy=multi-user.target


Checking the status of the service after boot, it says that it is running.
however the tkinter UI never shows up.










share|improve this question
















I have a shell script that gets updates from github and then runs the code that it retrieved. it is located at /home/me/Desktop/refreshCode.sh



-- refreshCode.sh --

#!/bin/bash

cd /home/me/src/ProductionMonitor
sudo /usr/bin git -C /home/me/src/ProductionMonitor pull
sudo cp /home/me/src/ProductionMonitor/* /home/me/Desktop/Production
cd /home/me/Desktop/Production
sudo /usr/bin/python3 prodmain.py >> logfile.data


I know that the shell can launch and runs as expected manually. It opens up the tkinter window and I can interact with the screen.



However I cannot seem to get anything to launch correctly.



I have tried setting up a crontab for @reboot and was not successful.
It never showed the ui



I set up a Systemd service as such.



-- prodmon.service --

[Unit]
Description=Service to run production monitor
After=multi-user.target

[Service]
Type=forking
ExecStart=/home/me/Desktop/refreshCode.sh
User=caleb
Group=caleb
WorkingDirectory=/home/me/Desktop/Production/
PIDFile=/var/run/prodmon.pid

[Install]
WantedBy=multi-user.target


Checking the status of the service after boot, it says that it is running.
however the tkinter UI never shows up.







ubuntu systemd cron






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 5 at 19:45









Rui F Ribeiro

41.8k1483142




41.8k1483142










asked Mar 5 at 17:40









caleb bakercaleb baker

31




31







  • 3





    Instead of sudo /usr/bin git... you probably mean sudo /usr/bin/git... What do you mean with "It never showed the ui"? A program run by cron should never show a UI. It should do some work and write messages to a logfile or to syslog. If you want to run a program with a graphical UI, see askubuntu.com/q/37957

    – Bodo
    Mar 5 at 17:52






  • 4





    Why on Earth do you require superuser access to write files into your own home directory?

    – JdeBP
    Mar 5 at 17:53











  • @JdeBP most of the reason you see an overuse of the sudo command is because I am pretty new to Linux. I don't want to sit and fight permissions right now so I sudo everything I can. I know its terrible practice and Ive been warned by many linux users that I need to correct it

    – caleb baker
    Mar 5 at 19:16











  • The thing is that using sudo without thinking twice is the reason why you have to "fight permissions". It leads to all kinds of files being owned by root when they shouldn't be, requiring another sudo to access them and so on. Better chown everything in your home back to your user and stop using sudo unless absolutely necessary.

    – TooTea
    Mar 5 at 19:21












  • 3





    Instead of sudo /usr/bin git... you probably mean sudo /usr/bin/git... What do you mean with "It never showed the ui"? A program run by cron should never show a UI. It should do some work and write messages to a logfile or to syslog. If you want to run a program with a graphical UI, see askubuntu.com/q/37957

    – Bodo
    Mar 5 at 17:52






  • 4





    Why on Earth do you require superuser access to write files into your own home directory?

    – JdeBP
    Mar 5 at 17:53











  • @JdeBP most of the reason you see an overuse of the sudo command is because I am pretty new to Linux. I don't want to sit and fight permissions right now so I sudo everything I can. I know its terrible practice and Ive been warned by many linux users that I need to correct it

    – caleb baker
    Mar 5 at 19:16











  • The thing is that using sudo without thinking twice is the reason why you have to "fight permissions". It leads to all kinds of files being owned by root when they shouldn't be, requiring another sudo to access them and so on. Better chown everything in your home back to your user and stop using sudo unless absolutely necessary.

    – TooTea
    Mar 5 at 19:21







3




3





Instead of sudo /usr/bin git... you probably mean sudo /usr/bin/git... What do you mean with "It never showed the ui"? A program run by cron should never show a UI. It should do some work and write messages to a logfile or to syslog. If you want to run a program with a graphical UI, see askubuntu.com/q/37957

– Bodo
Mar 5 at 17:52





Instead of sudo /usr/bin git... you probably mean sudo /usr/bin/git... What do you mean with "It never showed the ui"? A program run by cron should never show a UI. It should do some work and write messages to a logfile or to syslog. If you want to run a program with a graphical UI, see askubuntu.com/q/37957

– Bodo
Mar 5 at 17:52




4




4





Why on Earth do you require superuser access to write files into your own home directory?

– JdeBP
Mar 5 at 17:53





Why on Earth do you require superuser access to write files into your own home directory?

– JdeBP
Mar 5 at 17:53













@JdeBP most of the reason you see an overuse of the sudo command is because I am pretty new to Linux. I don't want to sit and fight permissions right now so I sudo everything I can. I know its terrible practice and Ive been warned by many linux users that I need to correct it

– caleb baker
Mar 5 at 19:16





@JdeBP most of the reason you see an overuse of the sudo command is because I am pretty new to Linux. I don't want to sit and fight permissions right now so I sudo everything I can. I know its terrible practice and Ive been warned by many linux users that I need to correct it

– caleb baker
Mar 5 at 19:16













The thing is that using sudo without thinking twice is the reason why you have to "fight permissions". It leads to all kinds of files being owned by root when they shouldn't be, requiring another sudo to access them and so on. Better chown everything in your home back to your user and stop using sudo unless absolutely necessary.

– TooTea
Mar 5 at 19:21





The thing is that using sudo without thinking twice is the reason why you have to "fight permissions". It leads to all kinds of files being owned by root when they shouldn't be, requiring another sudo to access them and so on. Better chown everything in your home back to your user and stop using sudo unless absolutely necessary.

– TooTea
Mar 5 at 19:21










1 Answer
1






active

oldest

votes


















1














You should probably not sudo all the stuff; all things are under your own directory.



The main point of your question is, that your script does not know where to display the window. Try adding



echo "DISPLAY=$DISPLAY" >> logfile.data


You will probably see



DISPLAY=


in `logfile.data. Furthermore, if you use:



/usr/bin/python3 prodmain.py >> logfile.data 2>/tmp/errorfile


you will probably see a /tmp/errorfile with something like:



prodmain: Xt error: Can't open display: 
prodmain: DISPLAY is not set


So, that is the reason why it does not display at boot.



Now how to solve it: that depends a lot on what you want.You can start the program from ~/.xinitrc when you log-in to the graphical environment. You can cut the job into two parts: doing the git and cp at boot, and the prodmain from the .xinitrc.






share|improve this answer























  • I am unfamiliar with ~/.xinitrc Is there something that I need to get or do I simply create the file. Ps you are correct about the display part

    – caleb baker
    Mar 5 at 19:19












  • .xinitrc runs commands when an X11 session (graphical interface for most Linuces) starts. Do a cat ~/.xinitrc to see what is done there.

    – Ljm Dullaart
    Mar 6 at 13:16











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',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
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%2f504552%2fhow-to-get-a-shell-script-to-execute-correctly-on-reboot%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














You should probably not sudo all the stuff; all things are under your own directory.



The main point of your question is, that your script does not know where to display the window. Try adding



echo "DISPLAY=$DISPLAY" >> logfile.data


You will probably see



DISPLAY=


in `logfile.data. Furthermore, if you use:



/usr/bin/python3 prodmain.py >> logfile.data 2>/tmp/errorfile


you will probably see a /tmp/errorfile with something like:



prodmain: Xt error: Can't open display: 
prodmain: DISPLAY is not set


So, that is the reason why it does not display at boot.



Now how to solve it: that depends a lot on what you want.You can start the program from ~/.xinitrc when you log-in to the graphical environment. You can cut the job into two parts: doing the git and cp at boot, and the prodmain from the .xinitrc.






share|improve this answer























  • I am unfamiliar with ~/.xinitrc Is there something that I need to get or do I simply create the file. Ps you are correct about the display part

    – caleb baker
    Mar 5 at 19:19












  • .xinitrc runs commands when an X11 session (graphical interface for most Linuces) starts. Do a cat ~/.xinitrc to see what is done there.

    – Ljm Dullaart
    Mar 6 at 13:16















1














You should probably not sudo all the stuff; all things are under your own directory.



The main point of your question is, that your script does not know where to display the window. Try adding



echo "DISPLAY=$DISPLAY" >> logfile.data


You will probably see



DISPLAY=


in `logfile.data. Furthermore, if you use:



/usr/bin/python3 prodmain.py >> logfile.data 2>/tmp/errorfile


you will probably see a /tmp/errorfile with something like:



prodmain: Xt error: Can't open display: 
prodmain: DISPLAY is not set


So, that is the reason why it does not display at boot.



Now how to solve it: that depends a lot on what you want.You can start the program from ~/.xinitrc when you log-in to the graphical environment. You can cut the job into two parts: doing the git and cp at boot, and the prodmain from the .xinitrc.






share|improve this answer























  • I am unfamiliar with ~/.xinitrc Is there something that I need to get or do I simply create the file. Ps you are correct about the display part

    – caleb baker
    Mar 5 at 19:19












  • .xinitrc runs commands when an X11 session (graphical interface for most Linuces) starts. Do a cat ~/.xinitrc to see what is done there.

    – Ljm Dullaart
    Mar 6 at 13:16













1












1








1







You should probably not sudo all the stuff; all things are under your own directory.



The main point of your question is, that your script does not know where to display the window. Try adding



echo "DISPLAY=$DISPLAY" >> logfile.data


You will probably see



DISPLAY=


in `logfile.data. Furthermore, if you use:



/usr/bin/python3 prodmain.py >> logfile.data 2>/tmp/errorfile


you will probably see a /tmp/errorfile with something like:



prodmain: Xt error: Can't open display: 
prodmain: DISPLAY is not set


So, that is the reason why it does not display at boot.



Now how to solve it: that depends a lot on what you want.You can start the program from ~/.xinitrc when you log-in to the graphical environment. You can cut the job into two parts: doing the git and cp at boot, and the prodmain from the .xinitrc.






share|improve this answer













You should probably not sudo all the stuff; all things are under your own directory.



The main point of your question is, that your script does not know where to display the window. Try adding



echo "DISPLAY=$DISPLAY" >> logfile.data


You will probably see



DISPLAY=


in `logfile.data. Furthermore, if you use:



/usr/bin/python3 prodmain.py >> logfile.data 2>/tmp/errorfile


you will probably see a /tmp/errorfile with something like:



prodmain: Xt error: Can't open display: 
prodmain: DISPLAY is not set


So, that is the reason why it does not display at boot.



Now how to solve it: that depends a lot on what you want.You can start the program from ~/.xinitrc when you log-in to the graphical environment. You can cut the job into two parts: doing the git and cp at boot, and the prodmain from the .xinitrc.







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 5 at 18:05









Ljm DullaartLjm Dullaart

749312




749312












  • I am unfamiliar with ~/.xinitrc Is there something that I need to get or do I simply create the file. Ps you are correct about the display part

    – caleb baker
    Mar 5 at 19:19












  • .xinitrc runs commands when an X11 session (graphical interface for most Linuces) starts. Do a cat ~/.xinitrc to see what is done there.

    – Ljm Dullaart
    Mar 6 at 13:16

















  • I am unfamiliar with ~/.xinitrc Is there something that I need to get or do I simply create the file. Ps you are correct about the display part

    – caleb baker
    Mar 5 at 19:19












  • .xinitrc runs commands when an X11 session (graphical interface for most Linuces) starts. Do a cat ~/.xinitrc to see what is done there.

    – Ljm Dullaart
    Mar 6 at 13:16
















I am unfamiliar with ~/.xinitrc Is there something that I need to get or do I simply create the file. Ps you are correct about the display part

– caleb baker
Mar 5 at 19:19






I am unfamiliar with ~/.xinitrc Is there something that I need to get or do I simply create the file. Ps you are correct about the display part

– caleb baker
Mar 5 at 19:19














.xinitrc runs commands when an X11 session (graphical interface for most Linuces) starts. Do a cat ~/.xinitrc to see what is done there.

– Ljm Dullaart
Mar 6 at 13:16





.xinitrc runs commands when an X11 session (graphical interface for most Linuces) starts. Do a cat ~/.xinitrc to see what is done there.

– Ljm Dullaart
Mar 6 at 13:16

















draft saved

draft discarded
















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f504552%2fhow-to-get-a-shell-script-to-execute-correctly-on-reboot%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown






Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?