tg-archive
tg-archive copied to clipboard
Why running with crontab showing sqlite3.OperationalError: near "(": syntax error
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
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.
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
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.
Ok i am checking with above links. The script is running with user root
How can i declare local db full path in cron?
/usr/local/bin/tg-archive --data=/home/your-path/data.sqlite --sync
Tried everything not working . Any one have working script for cron.
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
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
Tested with Centos 7
Does your sync work if you start it outside of cron?
Yes. The original comment said:
The script works well with command line . But while running with cron it shows the follwing error.
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?
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: @.***>