Forums

Trouble with scheduled task running bash script

Hi PA Team,

I have a bash script I created which pulls code from github, applies migrations, and reloads the server. It works flawlessly when I run it from a bash console; however, when I tried to create a task to do this automatically I run into some errors and can't seem to figure out why.

The command is setup like a normal bash command from the tasks page in my dashboard (/home/xDev/deploy/staging.sh) but I keep getting the following:

[1;34m3. Installing project:
Traceback (most recent call last):
  File "/home/xDev/.poetry/bin/poetry", line 17, in <module>
    from poetry.console import main
ImportError: cannot import name 'main' from 'poetry.console' (/home/xDev/.local/lib/python3.9/site-packages/poetry/console/__init__.py)

2022-12-05 04:01:26 -- Completed task, took 50.46 seconds, return code was 1.

Moreover, at the top of the script I have a set -e and on it's previous run it didn't seem to exit early.

I've updated poetry to the latest version and it's working in all other areas, just not the scheduled tasks -- any idea on why this might be?

Thank you for your time!

Make sure that when you run it in the console and in the task, you use the same python version and the same version of the package.

Hi fjl,

To debug the situation I created a sample script with the following.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#!/bin/sh

set -e

echo "Python:"
echo "\tpath: $(which python)"
echo "\tversion: $(python --version)"

echo "Poetry"
echo "\tpath: $(which poetry)"
echo "\tversion: $(poetry --version)"

I get the expected output when I run it inside of a console:

18:25 ~ $ ~/deploy/example.sh 
Python:
        path: /home/xDev/.local/bin/python
        version: Python 3.10.5
Poetry
        path: /home/xDev/.local/bin/poetry
        version: Poetry (version 1.2.2)

But when I run it using a scheduled task this is the output:

Python:
    path: /home/xDev/.local/bin/python
    version: Python 3.10.5
Poetry
    path: /home/xDev/.poetry/bin/poetry
Traceback (most recent call last):
File "/home/xDev/.poetry/bin/poetry", line 17, in <module>
    from poetry.console import main
ImportError: cannot import name 'main' from 'poetry.console' (/home/xDev/.local/lib/python3.9/site-packages/poetry/console/__init__.py)
    version:

2022-12-08 18:26:07 -- Completed task, took 3.00 seconds, return code was 0.

Forgive me but I'm not sure I follow -- how would I "use the same python version and the same version of the package"?

What is #! on /home/xDev/.poetry/bin/poetry? What python version did you install poetry for? What are default python and python3 versions? See it in your "Acccouts" page in the "System image" tab.

Got it resolved. Thanks for the hepl fjl!

Thanks for letting us know!