Creating Python Cron Job On Synology: Difference between revisions
Jump to navigation
Jump to search
| Line 44: | Line 44: | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
$ virtualenv -p /volume1/@appstore/py3k/usr/local/bin/python3 venv | $ virtualenv -p /volume1/@appstore/py3k/usr/local/bin/python3 venv | ||
</syntaxhighlight> | |||
=== SSH key for GitHub === | |||
* [https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/#platform-linux Generate a SSH key] | |||
* [https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/#platform-linux Add the SSH key to the GitHub acccount] | |||
** The instructions on that page say to use `apt-get` to install `xclip`. `apt-get` is not available on Synology. | |||
** Install `ipkg` instead. | |||
*** First look up the CPU of the DiskStation: '''DSM''' > '''Control Panel''' > '''System''' > '''Info Center''' > '''General''' tab > '''Basic Information''' group > '''CPU''' | |||
*** Alternatively, CPUs for all DiskStation models are listed [https://www.synology.com/en-global/knowledgebase/DSM/tutorial/General/What_kind_of_CPU_does_my_NAS_have here]. | |||
*** Download and install `ipkg` <ref>[http://howden.net.au/thowden/2014/10/synology-installation-of-ipkg-dsm-yum-or-apt-get-equivalent/ Synology installation of ipkg DSM yum or apt-get equivalent]</ref> | |||
*** E.g. on DS213: | |||
<syntaxhighlight lang="bash"> | |||
$ wget http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/cross/stable/syno-mvkw-bootstrap_1.2-7_arm.xsh | |||
$ sh syno-mvkw-bootstrap_1.2-7_arm.xsh | |||
</syntaxhighlight> | |||
On DS213 running the script generated an error: `Error: CPU not Marvell Kirkwood, probably wrong bootstrap.xsh` | |||
This error is fixed by editing `./bootstrap/bootstrap.sh` to change line 21: <ref>[https://forum.synology.com/enu/viewtopic.php?t=30764 IPKG for DS211] - Synology Forums</ref> | |||
<pre> | |||
/* from * | |||
/ | |||
if ! grep Feroceon-KW /proc/cpuinfo >/dev/null 2>&1; then | |||
/* to */ | |||
if ! grep Feroceon /proc/cpuinfo >/dev/null 2>&1; then | |||
</pre> | |||
Then running `./boostrap/bootstrap.sh` again (as `sudo`): | |||
<syntaxhighlight lang="bash"> | |||
$ sudo sh bootstrap.sh | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Revision as of 23:09, 31 March 2018
Objective
To install a python script on Synology NAS and run it as a cron job.
Prerequisites
python
Install Python3 using the Package Center app in the DSM.
pip
SSH to the DiskStation and install pip with
$ sudo curl -k https://bootstrap.pypa.io/get-pip.py | python3
This will install pip at /volume1/@appstore/py3k/usr/local/bin/, but the pip command isn't automatically available.
$ sudo ln -s /volume1/@appstore/py3k/usr/local/bin/pip /usr/local/bin/pip
This may be a viable alternative for installing pip:
$ sudo yum install python-pip $ sudo pip install --upgrade pip
virtualenv
Once pip is installed, use it to install virtualenv, and make sure the command is available from the command line:
$ sudo pip install virtualenv $ sudo ln -s /volume1/@appstore/py3k/usr/local/bin/virtualenv /usr/local/bin/virtualenv
Create a virtual environment for the python script:
$ virtualenv -p /volume1/@appstore/py3k/usr/local/bin/python3 venv
SSH key for GitHub
- Generate a SSH key
- Add the SSH key to the GitHub acccount
- The instructions on that page say to use
apt-getto installxclip.apt-getis not available on Synology. - Install
ipkginstead.
- The instructions on that page say to use
$ wget http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/cross/stable/syno-mvkw-bootstrap_1.2-7_arm.xsh $ sh syno-mvkw-bootstrap_1.2-7_arm.xsh
On DS213 running the script generated an error: Error: CPU not Marvell Kirkwood, probably wrong bootstrap.xsh
This error is fixed by editing ./bootstrap/bootstrap.sh to change line 21: [2]
/* from * / if ! grep Feroceon-KW /proc/cpuinfo >/dev/null 2>&1; then /* to */ if ! grep Feroceon /proc/cpuinfo >/dev/null 2>&1; then
Then running ./boostrap/bootstrap.sh again (as sudo):
$ sudo sh bootstrap.sh
- ↑ Synology installation of ipkg DSM yum or apt-get equivalent
- ↑ IPKG for DS211 - Synology Forums