Closed TheFrostyboss closed 10 months ago
I've run into the same issue on Debian 11 (bullseye). I'm currently running the commands through PowerShell (pwsh) and they work when called manually, but always get an empty result in cron.
@TheFrostyboss did you ever find a solution?
You can try to run it with output in JSON (--format json
) or CSV (--format csv
) format. I think it should work in this case.
I was using --format json
for part of my script, and it looks like that part is working. I initially had some code to grab the pretty print table and include it in a file, but after flipping it to just use the json object everything appears to be working.
Here is a snippet of my powershell that I ended up using to get a formatted table:
$stalledTorrents = qbt torrent list --filter stalledDownloading --format json | ConvertFrom-Json
$stalledTorrentsTable = $stalledTorrents | Sort-Object -Property added_on | Format-Table state,name,@{Label="progress"; Expression={$_.progress.tostring("P2")}}
$stalledTorrentsTable | Out-File ...
Thanks for the tip.
I'm having trouble getting this to run with cron on Debian Buster on my Raspberry Pi. Running
/usr/bin/qbt torrent list
works fine as user/sudo, and I'm able to redirect the output to a log with no problem. But when I add it tocrontab -e
:* * * * * /usr/bin/qbt torrent list >> /home/pi/LOG.log 2>&1
The log file is created, but the output of the command does not log. I've tried copying the cron environment and running the command manually. With
crontab -e
, I added:* * * * * env > ~/cronenv
Then run:
env - `cat ~/cronenv` /bin/sh
/usr/bin/qbt torrent list
It runs fine and outputs as expected, but when I try to redirect the output to a log, log is created but empty:
/usr/bin/qbt torrent list >> LOG.log
If I prepend with an
unbuffer
in this environment, the log is populated appropriately:/usr/bin/unbuffer /usr/bin/qbt torrent list >> LOG.log
But even with the unbuffer, it's still not working in crontab. I've also tried
bash -l -c -x '/usr/bin/qbt torrent list'
, changing the cron shell (SHELL=/bin/bash), adding my path to cron, etc. but nothing works. I even have a Python script that calls qbt; the Python script works fine when I run it normally, the script runs fine in cron (and logging the output works fine), but the call from the script always returnsoutput=b""
anderror=None
:When I try to run this command through a single SSH command, it works (e.g.
ssh pi@pi2.lan
-t '/usr/bin/qbt torrent list'`), but not when I attempt to launch the SSH command through that system's cron (though other SSH commands through cron work fine).What am I missing?