Cron job in jail not executing correctly

TmT

Cadet
Joined
Apr 28, 2020
Messages
2
Hello,

I am trying to make an offline copy of my google photo's. Now did i find a post on how to do that and it works fine when i run the .sh scrip in a shell. However if i try to run it as an cron job is fails to run correctly.

the .sh file contains the following,

Code:
cd /root/gphotos-sync
pipenv-3.7 run /root/gphotos-sync/gphotos-sync --db-path=/mnt/photo/_db --logfile=/mnt/photo/_db/gphotos.log --photos-path= /mnt/photo/user/ > /root/photo-user.txt


the cron job looks as follow,

1588075896929.png


The error message when running the cron job is is the following,
Code:
Traceback (most recent call last):
  File "/root/gphotos-sync/gphotos/authorize.py", line 44, in __init__
    with secrets_file.open("r") as stream:
  File "/usr/local/lib/python3.7/pathlib.py", line 1203, in open
    opener=self._opener)
  File "/usr/local/lib/python3.7/pathlib.py", line 1058, in _opener
    return self._accessor.open(self, flags, mode)
FileNotFoundError: [Errno 2] No such file or directory: '/.config/gphotos-sync/client_secret.json'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/root/gphotos-sync/gphotos/Main.py", line 417, in main
    self.setup(args, db_path)
  File "/root/gphotos-sync/gphotos/Main.py", line 282, in setup
    scope, credentials_file, secret_file, int(args.max_retries)
  File "/root/gphotos-sync/gphotos/authorize.py", line 58, in __init__
    exit(1)
  File "/.local/share/virtualenvs/gphotos-sync-wbnW4jFe/lib/python3.7/site.py", line 397, in __call__
    raise SystemExit(code)
SystemExit: 1
04-28 12:09:00 gphotos.Main WARNING  Done.
04-28 12:09:00 gphotos.Main INFO     Elapsed time = 0:00:00.014519


I see that in the line "No such file or directory: '/.config/gphotos-sync/client_secret.json" the is an "/" in front of .config. I think that is incorrect but i can't figure out what is causing that and why it runs fine from within the shell.

does anyone have an idea what is wrong and how i can fix it?

I am running FreeNAS-11.3-U2.1

Thx.
 

proto

Patron
Joined
Sep 28, 2015
Messages
269
umm!
I don't use gphotos-sync... so I cannot help here. Maybe you have to specify --secret path.

I usually run crontab inside the same jail. But I tried to run a simple python script in a pipenv from FreeNAS crontab:

iocage exec -U ale certz /bin/sh /home/ale/script.sh

script.sh:

Code:
#/bin/sh
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/home/ale/bin
export LOG='logger -p local7.notice -t script'

script_all () {
    cd /home/ale/script
    pipenv run python /home/ale/script/script.py
}

script_all | $LOG
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
Using jexec like that may be part of your problem as the jail ID can change any time you restart the jail.

Better to use the jail name and iocage exec as suggested by proto.
 

proto

Patron
Joined
Sep 28, 2015
Messages
269
Using jexec like that may be part of your problem

sure! : - )

then here is a second issue to investigate if you have a similar error:

Code:
sh run_script.sh
Error: the command /home/ale/script/script.py could not be found within PATH or Pipfile's [scripts].


Pipenv need a PATH, so you should run:
pipenv run python script.py

~ OR ~

You can add an hidden script section in Pipfile as suggested in pipenv wiki: https://github.com/pypa/pipenv/wiki

Code:
cat covidgram/Pipfile
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
requests = "*"

[requires]
python_version = "3.7"

[scripts]
start = "python script.py"



and change the shell script accordingly:

Code:
#/bin/sh
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/root/bin
export LOG='logger -p local7.notice -t script'

new_all () {
    cd /home/ale/script
    pipenv run start
}

new_all | $LOG
 

TmT

Cadet
Joined
Apr 28, 2020
Messages
2
Changing from "jexec" to "iocage exec" did the trick!

I can't believe it was that simple.... Thanks!
 
Top