question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Crontab -e (Ubuntu) not working with auto update library code

See original GitHub issue

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.

Please could someone advise what I’m doing wrong?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
doob187commented, 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

#!/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
0reactions
adamgotcommented, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why crontab scripts are not working? - Ask Ubuntu
The reason is that cron does not have the same PATH environment variable as the user. Save this answer.
Read more >
Why is my crontab not working, and how can I troubleshoot it?
A frequent problem users make with crontab entries is that they forget that cron runs in a different environment than they do as...
Read more >
How To Use Cron to Automate Tasks on Ubuntu 18.04
To schedule a job, open up your crontab for editing and add a task written in the form of a cron expression. The...
Read more >
CronJob not running - Stack Overflow
Here's a checklist guide to debug not running cronjobs: ... in CRON tab and let the log file get created automatically when the...
Read more >
Make auto update cron job optional at install time Β· Issue #2932
I can of course delete the cron job, and I do. I just think it would be easier if that was an option...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found