- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
I managed to /message/381193# 381193 run a python script at startup. Is the same possible when powering off?
- Tags:
- Python
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Hello BrechtW,
I have never tried to do something like this, however I believe it's possible since I found a few possible answers for this question in:
http://unix.stackexchange.com/questions/48973/execute-a-command-before-shutdown http://unix.stackexchange.com/questions/48973/execute-a-command-before-shutdown
http://ubuntuforums.org/showthread.php?t=185261 http://ubuntuforums.org/showthread.php?t=185261
http://stackoverflow.com/questions/18891312/how-to-run-a-shell-script-before-shutdown-on-centos http://stackoverflow.com/questions/18891312/how-to-run-a-shell-script-before-shutdown-on-centos
http://askubuntu.com/questions/416299/execute-command-before-shutdown-reboot http://askubuntu.com/questions/416299/execute-command-before-shutdown-reboot
Nevertheless, I have another idea. You could create your own command that executes the script you would like to run and then shuts down the Edison. This is actually very simple, just create a file in /usr/bin with a structure similar to the following:
# !/usr/bin/python
from subprocess import call
import time
call(["RUN YOUR SCRIPT IN HERE"])
time.sleep(0.2)
call(["poweroff"])
As you can see the command code is written in Python, it has a system call so you can run the script you would lie to run before powering off and when it finishes it shuts down the board. Once you've written the command, give it executable right with chmod +x YOUR_COMMAND and then you should be able to run this command any time.
In case you don't know how a system call works on Python, you can check the following link to learn more about it:
https://docs.python.org/2/library/subprocess.html https://docs.python.org/2/library/subprocess.html
Peter.
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Hello BrechtW,
I have never tried to do something like this, however I believe it's possible since I found a few possible answers for this question in:
http://unix.stackexchange.com/questions/48973/execute-a-command-before-shutdown http://unix.stackexchange.com/questions/48973/execute-a-command-before-shutdown
http://ubuntuforums.org/showthread.php?t=185261 http://ubuntuforums.org/showthread.php?t=185261
http://stackoverflow.com/questions/18891312/how-to-run-a-shell-script-before-shutdown-on-centos http://stackoverflow.com/questions/18891312/how-to-run-a-shell-script-before-shutdown-on-centos
http://askubuntu.com/questions/416299/execute-command-before-shutdown-reboot http://askubuntu.com/questions/416299/execute-command-before-shutdown-reboot
Nevertheless, I have another idea. You could create your own command that executes the script you would like to run and then shuts down the Edison. This is actually very simple, just create a file in /usr/bin with a structure similar to the following:
# !/usr/bin/python
from subprocess import call
import time
call(["RUN YOUR SCRIPT IN HERE"])
time.sleep(0.2)
call(["poweroff"])
As you can see the command code is written in Python, it has a system call so you can run the script you would lie to run before powering off and when it finishes it shuts down the board. Once you've written the command, give it executable right with chmod +x YOUR_COMMAND and then you should be able to run this command any time.
In case you don't know how a system call works on Python, you can check the following link to learn more about it:
https://docs.python.org/2/library/subprocess.html https://docs.python.org/2/library/subprocess.html
Peter.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page