Creating Python Cron Job On Synology: Difference between revisions

From Littledamien Wiki
Jump to navigation Jump to search
No edit summary
Line 15: Line 15:


<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
$ sudo curl -k https://bootstrap.pypa.io/get-pip.py | python3
$ wget https://bootstrap.pypa.io/get-pip.py  
$ sudo python3 get-pip.py
</syntaxhighlight>
</syntaxhighlight>



Revision as of 09:31, 1 April 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

$ wget https://bootstrap.pypa.io/get-pip.py 
$ sudo python3 get-pip.py

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-get to install xclip. apt-get is not available on Synology. [1] xclip is being installed to copy the contents of the ssh key file from the command line, however xclip doesn't seem to be readily available for Synology, so open up the key file and manually copy its contents instead.

Notes