tg-archive icon indicating copy to clipboard operation
tg-archive copied to clipboard

Why running with crontab showing sqlite3.OperationalError: near "(": syntax error

Open babynew opened this issue 2 years ago • 13 comments

The script works well with command line . But while running with cron it shows the follwing error.

2022-05-08 19:40:02,089: cryptg detected, it will be used for encryption 2022-05-08 19:40:02,596: starting Telegram sync (batch_size=4000, limit=0, wait=5, mode=standard) 2022-05-08 19:40:02,601: Connecting to 91.108.56.108:443/TcpFull... 2022-05-08 19:40:02,606: Connection to 91.108.56.108:443/TcpFull complete! 2022-05-08 19:40:02,688: fetching from last message id=2102 (2022-05-07 00:00:00) 2022-05-08 19:40:02,875: finished. fetched 0 messages. last message = 2022-05-07 00:00:00 2022-05-08 19:40:28,689: building site Traceback (most recent call last): File "/usr/local/bin/tg-archive", line 11, in load_entry_point('tg-archive==0.5.4', 'console_scripts', 'tg-archive')() File "/usr/local/lib/python3.6/site-packages/tgarchive/init.py", line 150, in main b.build() File "/usr/local/lib/python3.6/site-packages/tgarchive/build.py", line 58, in build for d in self.db.get_dayline(month.date.year, month.date.month, self.config["per_page"]): File "/usr/local/lib/python3.6/site-packages/tgarchive/db.py", line 128, in get_dayline """, (limit, "{}{:02d}".format(year, month))) sqlite3.OperationalError: near "(": syntax error

babynew avatar May 08 '22 14:05 babynew

Possibly related:

  • https://stackoverflow.com/questions/18053707/python-code-don-t-work-when-launched-by-cron/18053780
  • https://serverfault.com/questions/1080369/script-backups-sqlite-database-when-ran-as-a-cron-the-db-and-names-are-mangled

Please share your crontab entry.

knadh avatar May 08 '22 14:05 knadh

Thank you for your quick response ... Here is the cron

#!/bin/bash cd /home/user/public_html/tg/ /usr/local/bin/tg-archive --sync echo 'sync' sleep 25 /usr/local/bin/tg-archive --build echo 'build' exec bash

babynew avatar May 08 '22 14:05 babynew

hm, the script looks fine. Please check the links I shared above. Maybe you'll have to execute the cron with the appropriate user. Not sure why it's throwing a syntax error though.

knadh avatar May 08 '22 14:05 knadh

Ok i am checking with above links. The script is running with user root

babynew avatar May 08 '22 14:05 babynew

How can i declare local db full path in cron?

babynew avatar May 08 '22 14:05 babynew

/usr/local/bin/tg-archive --data=/home/your-path/data.sqlite --sync

knadh avatar May 08 '22 14:05 knadh

Tried everything not working . Any one have working script for cron.

babynew avatar May 19 '22 16:05 babynew

Hey,

got following working in Debain 10. As I don't have added tg-archive to user paths, I need to set the path to the binary in the script to make it working from cron.

You have to add the paths to the directories containing the tg-archive data in the script. So this script can sync all of your channels with one cron entry.

However there is a bug with downloading media files, which the script does not yet cover. I'm currently testing the solution on my maschine, unfortunately the channel contains very big files and so it needs some time. If it works I will paste it in issue #52

Btw. python logging posts everything to stderr, if you want a logfile you need to configure the crontab entry like following:

0       6       *       *       *       /some/path/poll_telegram_channels.sh >> /some/path/cron_tg_archiver.log 2>&1
#!/bin/bash

# Setting up absolute path as cron can't find program ...
tg_archiver_bin='/usr/local/bin/tg-archive'

# Declaring empty array and adding values one by one for better readability.
tg_archive_paths=()

# Add paths one by one. Don't use ~ as this doesn't work in script!
tg_archive_paths+=("/home/tg-archive/first_channel")
tg_archive_paths+=("/home/tg-archive/second_channel")

# Iterate over each directory, poll new messages and build new html pages
for tg_archive_path in ${tg_archive_paths[@]}
do
        echo "Updating directory '$tg_archive_path' ..."

        # Switching to directory as tg-archive doesn't work well with parameterized call ...
        cd "$tg_archive_path"
        if [[ $? -ne 0 ]]
        then
                echo -e "ERROR: Directory does not exist, skipping this one!\n"
                continue
        fi

        # Getting new messages
        $tg_archiver_bin --sync

        if [[ $? -ne 0 ]]
        then
                echo -e "ERROR: Telegram sync on '$tg_archive_path' failed!\n"
                continue
        fi

        # Building HTML content
        $tg_archiver_bin --build
        if [[ $? -ne 0 ]]
        then
                echo -e "ERROR: Page build on '$tg_archive_path' failed!\n"
                continue
        fi

        echo -e "Updated directory '$tg_archive_path'.\n"
done

exactoph avatar May 20 '22 10:05 exactoph

Thanks for your response ..

Unfortunately it is not working .It shows the following

Updating directory '/home/directory/ch' ... 2022-05-21 22:29:02,281: cryptg detected, it will be used for encryption 2022-05-21 22:29:02,671: starting Telegram sync (batch_size=2000, limit=0, wait=5, mode=standard) 2022-05-21 22:29:02,674: Connecting to 91.108.56.108:443/TcpFull... 2022-05-21 22:29:02,677: Connection to 91.108.56.108:443/TcpFull complete! 2022-05-21 22:29:02,723: fetching from last message id=2159 (2022-05-21 00:00:00) 2022-05-21 22:29:03,048: finished. fetched 0 messages. last message = 2022-05-21 00:00:00 2022-05-21 22:29:03,740: building site Traceback (most recent call last): File "/usr/local/bin/tg-archive", line 11, in load_entry_point('tg-archive==0.5.4', 'console_scripts', 'tg-archive')() File "/usr/local/lib/python3.6/site-packages/tgarchive/init.py", line 150, in main b.build() File "/usr/local/lib/python3.6/site-packages/tgarchive/build.py", line 58, in build for d in self.db.get_dayline(month.date.year, month.date.month, self.config["per_page"]): File "/usr/local/lib/python3.6/site-packages/tgarchive/db.py", line 128, in get_dayline """, (limit, "{}{:02d}".format(year, month))) sqlite3.OperationalError: near "(": syntax error ERROR: Page build on '/home/directory/ch' failed!

babynew avatar May 21 '22 17:05 babynew

Tested with Centos 7

babynew avatar May 21 '22 17:05 babynew

Does your sync work if you start it outside of cron?

exactoph avatar May 23 '22 08:05 exactoph

Yes. The original comment said:

The script works well with command line . But while running with cron it shows the follwing error.

knadh avatar May 23 '22 12:05 knadh

I had some issues when I've installed the application via pip. After cloning the repository from git and installing it, it worked fine for me. Maybe you want to give this a try?

exactoph avatar May 27 '22 07:05 exactoph

Still.... Any solution?

On Fri, 26 Aug, 2022, 10:50 am Kailash Nadh, @.***> wrote:

Closed #58 https://github.com/knadh/tg-archive/issues/58 as completed.

— Reply to this email directly, view it on GitHub https://github.com/knadh/tg-archive/issues/58#event-7264662615, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOIAY65FQCZFYLNPJ2RBO5LV3BHYBANCNFSM5VL7WFEA . You are receiving this because you authored the thread.Message ID: @.***>

babynew avatar Aug 26 '22 18:08 babynew