You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Crontab -e (Ubuntu) not working with auto update library code #80
I use the following line of code to run a library scan and update of the TV Trending library cd /opt/appdata/pydpl/&& sudo python plexlibrary tv_trending - this works perfectly.
In sudo crontab -e, I have entered: @daily cd /opt/appdata/pydpl/&& sudo python plexlibrary tv_trending - however crontab does not seem to be running this script and I am having to do this manually.
copy paste it and well done edit the name of the folder
python-plexlibrary in the script and it will works withoutany problems
#!/bin/bash
##USERSIDE EDITS !!
FOLDER="/opt/appdata"
CRONTIME="daily"
###
###dont edit below !!!
CRONTABFILE="/tmp/mycron"
PATH='/usr/bin:/bin:/usr/local/bin'
export PYTHONIOENCODING=UTF-8
sudocheck() {
if [[ $EUID -ne 0 ]]; then
tee <<-EOF
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⛔️ You Must Execute as a SUDO USER (with sudo) or as ROOT!
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
EOF
exit 0
else
owned
plexpython
fi
}
owned() {
if [[ ! -f "$CRONTABFILE" ]]; then
sudo chmod +x ${FOLDER}/python-plexlibrary/scripts/plexlibrary.sh
crontab -l > /tmp/mycron
echo "@${CRONTIME} bash ${FOLDER}/python-plexlibrary/scripts/plexlibrary.sh" >> /tmp/mycron
crontab /tmp/mycron
echo "Python-Plexlibrary ${CRONTIME} Crontab is added"
else
echo "Python-Plexlibrary ${CRONTIME} Crontab is already added"
fi
}
plexpython() {
truncate -s 0 ${FOLDER}/python-plexlibrary/plexlibrary.log
echo $(date) | tee -a ${FOLDER}/python-plexlibrary/plexlibrary.log
echo "" | tee -a ${FOLDER}/python-plexlibrary/plexlibrary.log
for file in ${FOLDER}/python-plexlibrary/recipes/*
do
if [ ! -d "${file}" ]; then
/usr/bin/python3 ${FOLDER}/python-plexlibrary/plexlibrary/plexlibrary.py $(basename "$file" .yml) | tee -a ${FOLDER}/python-plexlibrary/plexlibrary.log
echo "" | tee -a ${FOLDER}/python-plexlibrary/plexlibrary.log
fi
done
}
####### FUNCTIONS LINE
sudocheck
####### FUNCTIONS LINE
#!/bin/bash
#########################################################################
# Title: Cloudbox: Python-PlexLibrary Helper Script #
# Author(s): desimaniac #
# URL: https://github.com/cloudbox/cloudbox #
# -- #
# Part of the Cloudbox project: https://cloudbox.works #
#########################################################################
# GNU General Public License v3.0 #
#########################################################################
# CUSTOM SCRIPT WITH CRONATB AUTO ADD #
#########################################################################
##USERSIDE EDITS !!
FOLDER="/opt/appdata"
CRONTIME="daily"
###
###dont edit below !!!
CRONTABFILE="/tmp/mycron"
PATH='/usr/bin:/bin:/usr/local/bin'
export PYTHONIOENCODING=UTF-8
sudocheck() {
if [[ $EUID -ne 0 ]]; then
tee <<-EOF
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⛔️ You Must Execute as a SUDO USER (with sudo) or as ROOT!
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
EOF
exit 0
else
owned
plexpython
fi
}
owned() {
if [[ ! -f "$CRONTABFILE" ]]; then
sudo chmod +x ${FOLDER}/pydpl/scripts/plexlibrary.sh
crontab -l > /tmp/mycron
echo "@${CRONTIME} bash ${FOLDER}/pydpl/scripts/plexlibrary.sh" >> /tmp/mycron
crontab /tmp/mycron
echo "Python-Plexlibrary ${CRONTIME} Crontab is added"
else
echo "Python-Plexlibrary ${CRONTIME} Crontab is already added"
fi
}
plexpython() {
truncate -s 0 ${FOLDER}/pydpl/plexlibrary.log
echo $(date) | tee -a ${FOLDER}/pydpl/plexlibrary.log
echo "" | tee -a ${FOLDER}/pydpl/plexlibrary.log
for file in ${FOLDER}/pydpl/recipes/*
do
if [ ! -d "${file}" ]; then
/usr/bin/python3 ${FOLDER}/pydpl/plexlibrary/plexlibrary.py $(basename "$file" .yml) | tee -a ${FOLDER}/pydpl/plexlibrary.log
echo "" | tee -a ${FOLDER}/pydpl/plexlibrary.log
fi
done
}
####### FUNCTIONS LINE
sudocheck
####### FUNCTIONS LINE
with fixed apth from python-plexlibrary to pydpl
beware all recipes under python-plexlibrary/recipes
will run now on automode each day 00:00
Thanks so much, I’ll have a play this weekend.
Is it straight forward to only refresh individual recipes or are we straying into more complex waters?
Or could I just add another folder with those recipes in: for file in ${FOLDER}/pydpl/recipes/NEW FOLDER/*
Hey man, I've had a stab and I think I've failed. I've googled around over the weekend but couldn't get it to run.
In sudo crontab -e I added the following line on Friday evening: @daily cd /opt/appdata/pydpl && sudo /opt/appdata/pydpl/pydplauto.sh. That didn't work so on Saturday I then tried @daily bash /opt/appdata/pydpl/pydplauto.sh but that didn't work either. Is there another way to point to the bash file?
The bash file is located /opt/appdata/pydpl/pydplauto.sh and the recipes I want it to run are located in /opt/appdata/pydpl/recipes/auto/ and the final bash file looks like this:
sudocheck() {
if [[ $EUID -ne 0 ]]; then
tee <<-EOF
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⛔️ You Must Execute as a SUDO USER (with sudo) or as ROOT!
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
EOF
exit 0
else
owned
plexpython
fi
}
owned() {
if [[ ! -f "$CRONTABFILE" ]]; then
sudo chmod +x ${FOLDER}/pydpl/scripts/plexlibrary.sh
crontab -l > /tmp/mycron
echo "@${CRONTIME} bash ${FOLDER}/pydpl/scripts/plexlibrary.sh" >> /tmp/mycron
crontab /tmp/mycron
echo "Python-Plexlibrary ${CRONTIME} Crontab is added"
else
echo "Python-Plexlibrary ${CRONTIME} Crontab is already added"
fi
}
plexpython() {
truncate -s 0 ${FOLDER}/pydpl/plexlibrary.log
echo $(date) | tee -a ${FOLDER}/pydpl/plexlibrary.log
echo "" | tee -a ${FOLDER}/pydpl/plexlibrary.log
for file in ${FOLDER}/pydpl/recipes/auto/*
do
if [ ! -d "${file}" ]; then
/usr/bin/python3 ${FOLDER}/pydpl/plexlibrary/plexlibrary.py $(basename "$file" .yml) | tee -a ${FOLDER}/pydpl/plexlibrary.log
echo "" | tee -a ${FOLDER}/pydpl/plexlibrary.log
fi
done
}
####### FUNCTIONS LINE
sudocheck
####### FUNCTIONS LINE`
I feel like I'm missing something obvious, hence I'm hoping that you'll spot it. Sorry for the hassle!
`Traceback (most recent call last):
Running the recipe 'movies_trending'
Retrieving the trakt list: https://api.trakt.tv/movies/watched/weekly?limit=100
Getting data from TMDb to add weighted sorting...
File "/opt/appdata/pydpl/plexlibrary/plexlibrary.py", line 67, in
main()
File "/opt/appdata/pydpl/plexlibrary/plexlibrary.py", line 61, in main
r.run(args.sort_only)
File "/opt/appdata/pydpl/plexlibrary/recipe.py", line 696, in run
missing_items, list_count = self._run()
File "/opt/appdata/pydpl/plexlibrary/recipe.py", line 94, in _run
item_list = self.weighted_sorting(item_list)
File "/opt/appdata/pydpl/plexlibrary/recipe.py", line 758, in weighted_sorting
details = self.tmdb.get_details(m['tmdb_id'], self.library_type)
File "/opt/appdata/pydpl/plexlibrary/tmdb.py", line 77, in get_details
cache = shelve.open(self.cache_file)
File "/usr/lib/python3.6/shelve.py", line 243, in open
return DbfilenameShelf(filename, flag, protocol, writeback)
File "/usr/lib/python3.6/shelve.py", line 227, in init
Shelf.init(self, dbm.open(filename, flag), protocol, writeback)
File "/usr/lib/python3.6/dbm/init.py", line 88, in open
raise error[0]("db type could not be determined")
dbm.error: db type could not be determined
Running the recipe 'tv_trending'
Retrieving the trakt list: https://api.trakt.tv/shows/trending?limit=5
Retrieving the trakt list: https://api.trakt.tv/shows/watched/weekly?limit=20
Retrieving the trakt list: https://api.trakt.tv/shows/watched/monthly?limit=50
Retrieving the trakt list: https://api.trakt.tv/shows/watched/yearly?limit=100
Getting data from TMDb to add weighted sorting...
Traceback (most recent call last):
File "/opt/appdata/pydpl/plexlibrary/plexlibrary.py", line 67, in
main()
File "/opt/appdata/pydpl/plexlibrary/plexlibrary.py", line 61, in main
r.run(args.sort_only)
File "/opt/appdata/pydpl/plexlibrary/recipe.py", line 696, in run
missing_items, list_count = self._run()
File "/opt/appdata/pydpl/plexlibrary/recipe.py", line 94, in _run
item_list = self.weighted_sorting(item_list)
File "/opt/appdata/pydpl/plexlibrary/recipe.py", line 758, in weighted_sorting
details = self.tmdb.get_details(m['tmdb_id'], self.library_type)
File "/opt/appdata/pydpl/plexlibrary/tmdb.py", line 77, in get_details
cache = shelve.open(self.cache_file)
File "/usr/lib/python3.6/shelve.py", line 243, in open
return DbfilenameShelf(filename, flag, protocol, writeback)
File "/usr/lib/python3.6/shelve.py", line 227, in init
Shelf.init(self, dbm.open(filename, flag), protocol, writeback)
File "/usr/lib/python3.6/dbm/init.py", line 88, in open
raise error[0]("db type could not be determined")
dbm.error: db type could not be determined`
It would seem like the database isn't being identified correctly - yet if I run these recipes individually then they work fine...
For anyone else having this issue I downgraded the python version to 2.7.
Edit this line: /usr/bin/python3 ${FOLDER}/pydpl/plexlibrary/plexlibrary.py $(basename "$file" .yml) | tee -a ${FOLDER}/pydpl/plexlibrary.log
to become: /usr/bin/python2.7 ${FOLDER}/pydpl/plexlibrary/plexlibrary.py $(basename "$file" .yml) | tee -a ${FOLDER}/pydpl/plexlibrary.log
When moving between python2 and python3 (or rather, different versions of shelve), you have to first delete the shelve file. python2 is no longer supported, you may run into other issues in the future.
Activity
doob187 commentedon Jun 8, 2020
python3 not python
copy paste it and well done edit the name of the folder
python-plexlibrary in the script and it will works withoutany problems
doob187 commentedon Jun 8, 2020
in your case here
with fixed apth from python-plexlibrary to pydpl
beware all recipes under python-plexlibrary/recipes
will run now on automode each day 00:00
timmehtimtims commentedon Jun 9, 2020
Thanks so much, I’ll have a play this weekend.
Is it straight forward to only refresh individual recipes or are we straying into more complex waters?
Or could I just add another folder with those recipes in:
for file in ${FOLDER}/pydpl/recipes/NEW FOLDER/*doob187 commentedon Jun 10, 2020
yes its works ;-)

timmehtimtims commentedon Jun 10, 2020
Great, I’ll have a stab at that 👍
timmehtimtims commentedon Jun 29, 2020
Hey man, I've had a stab and I think I've failed. I've googled around over the weekend but couldn't get it to run.
In
sudo crontab -eI added the following line on Friday evening:@daily cd /opt/appdata/pydpl && sudo /opt/appdata/pydpl/pydplauto.sh. That didn't work so on Saturday I then tried@daily bash /opt/appdata/pydpl/pydplauto.shbut that didn't work either. Is there another way to point to the bash file?The bash file is located
/opt/appdata/pydpl/pydplauto.shand the recipes I want it to run are located in/opt/appdata/pydpl/recipes/auto/and the final bash file looks like this:`#!/bin/bash
#########################################################################
Title: Cloudbox: Python-PlexLibrary Helper Script
Author(s): desimaniac
URL: https://github.com/cloudbox/cloudbox
--
Part of the Cloudbox project: https://cloudbox.works
#########################################################################
GNU General Public License v3.0
#########################################################################
CUSTOM SCRIPT WITH CRONATB AUTO ADD
#########################################################################
##USERSIDE EDITS !!
FOLDER="/opt/appdata"
CRONTIME="daily"
###dont edit below !!!
CRONTABFILE="/tmp/mycron"
PATH='/usr/bin:/bin:/usr/local/bin'
export PYTHONIOENCODING=UTF-8
sudocheck() {
if [[ $EUID -ne 0 ]]; then
tee <<-EOF
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⛔️ You Must Execute as a SUDO USER (with sudo) or as ROOT!
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
EOF
exit 0
else
owned
plexpython
fi
}
owned() {
if [[ ! -f "$CRONTABFILE" ]]; then
sudo chmod +x ${FOLDER}/pydpl/scripts/plexlibrary.sh
crontab -l > /tmp/mycron
echo "@${CRONTIME} bash ${FOLDER}/pydpl/scripts/plexlibrary.sh" >> /tmp/mycron
crontab /tmp/mycron
echo "Python-Plexlibrary ${CRONTIME} Crontab is added"
else
echo "Python-Plexlibrary ${CRONTIME} Crontab is already added"
fi
}
plexpython() {$(date) | tee -a $ {FOLDER}/pydpl/plexlibrary.log
truncate -s 0 ${FOLDER}/pydpl/plexlibrary.log
echo
echo "" | tee -a ${FOLDER}/pydpl/plexlibrary.log
for file in ${FOLDER}/pydpl/recipes/auto/*${FOLDER}/pydpl/plexlibrary/plexlibrary.py $ (basename "$file" .yml) | tee -a ${FOLDER}/pydpl/plexlibrary.log
do
if [ ! -d "${file}" ]; then
/usr/bin/python3
echo "" | tee -a ${FOLDER}/pydpl/plexlibrary.log
fi
done
}
####### FUNCTIONS LINE
sudocheck
####### FUNCTIONS LINE`
I feel like I'm missing something obvious, hence I'm hoping that you'll spot it. Sorry for the hassle!
timmehtimtims commentedon Aug 25, 2020
The error message I'm getting is:
`Traceback (most recent call last):
Running the recipe 'movies_trending'
Retrieving the trakt list: https://api.trakt.tv/movies/watched/weekly?limit=100
Getting data from TMDb to add weighted sorting...
File "/opt/appdata/pydpl/plexlibrary/plexlibrary.py", line 67, in
main()
File "/opt/appdata/pydpl/plexlibrary/plexlibrary.py", line 61, in main
r.run(args.sort_only)
File "/opt/appdata/pydpl/plexlibrary/recipe.py", line 696, in run
missing_items, list_count = self._run()
File "/opt/appdata/pydpl/plexlibrary/recipe.py", line 94, in _run
item_list = self.weighted_sorting(item_list)
File "/opt/appdata/pydpl/plexlibrary/recipe.py", line 758, in weighted_sorting
details = self.tmdb.get_details(m['tmdb_id'], self.library_type)
File "/opt/appdata/pydpl/plexlibrary/tmdb.py", line 77, in get_details
cache = shelve.open(self.cache_file)
File "/usr/lib/python3.6/shelve.py", line 243, in open
return DbfilenameShelf(filename, flag, protocol, writeback)
File "/usr/lib/python3.6/shelve.py", line 227, in init
Shelf.init(self, dbm.open(filename, flag), protocol, writeback)
File "/usr/lib/python3.6/dbm/init.py", line 88, in open
raise error[0]("db type could not be determined")
dbm.error: db type could not be determined
Running the recipe 'tv_trending'
Retrieving the trakt list: https://api.trakt.tv/shows/trending?limit=5
Retrieving the trakt list: https://api.trakt.tv/shows/watched/weekly?limit=20
Retrieving the trakt list: https://api.trakt.tv/shows/watched/monthly?limit=50
Retrieving the trakt list: https://api.trakt.tv/shows/watched/yearly?limit=100
Getting data from TMDb to add weighted sorting...
Traceback (most recent call last):
File "/opt/appdata/pydpl/plexlibrary/plexlibrary.py", line 67, in
main()
File "/opt/appdata/pydpl/plexlibrary/plexlibrary.py", line 61, in main
r.run(args.sort_only)
File "/opt/appdata/pydpl/plexlibrary/recipe.py", line 696, in run
missing_items, list_count = self._run()
File "/opt/appdata/pydpl/plexlibrary/recipe.py", line 94, in _run
item_list = self.weighted_sorting(item_list)
File "/opt/appdata/pydpl/plexlibrary/recipe.py", line 758, in weighted_sorting
details = self.tmdb.get_details(m['tmdb_id'], self.library_type)
File "/opt/appdata/pydpl/plexlibrary/tmdb.py", line 77, in get_details
cache = shelve.open(self.cache_file)
File "/usr/lib/python3.6/shelve.py", line 243, in open
return DbfilenameShelf(filename, flag, protocol, writeback)
File "/usr/lib/python3.6/shelve.py", line 227, in init
Shelf.init(self, dbm.open(filename, flag), protocol, writeback)
File "/usr/lib/python3.6/dbm/init.py", line 88, in open
raise error[0]("db type could not be determined")
dbm.error: db type could not be determined`
It would seem like the database isn't being identified correctly - yet if I run these recipes individually then they work fine...
timmehtimtims commentedon Aug 25, 2020
Solved.
For anyone else having this issue I downgraded the python version to 2.7.
Edit this line:
/usr/bin/python3 ${FOLDER}/pydpl/plexlibrary/plexlibrary.py $(basename "$file" .yml) | tee -a ${FOLDER}/pydpl/plexlibrary.logto become:
/usr/bin/python2.7 ${FOLDER}/pydpl/plexlibrary/plexlibrary.py $(basename "$file" .yml) | tee -a ${FOLDER}/pydpl/plexlibrary.logadamgot commentedon Aug 25, 2020
When moving between python2 and python3 (or rather, different versions of shelve), you have to first delete the shelve file. python2 is no longer supported, you may run into other issues in the future.