FreshRSS/cli
berumuron 662c9fcc2f
fix: Fix check of existing usernames in cli scripts (#5667)
`preg_grep` returns an empty array if the username matches no elements
from the usernames array.

Regression introduced in 7f9594b8c7

Reference: https://github.com/FreshRSS/FreshRSS/pull/5501
2023-09-22 11:41:49 +02:00
..
i18n fix many "Only booleans are allowed in an if condition" (#5501) 2023-07-07 21:53:17 +02:00
.htaccess Patch for #2460: Run on Apache 2.4+ without mod_access_compat (#2461) 2019-07-31 13:48:06 +02:00
README.md More robust application of access permissions (#5062) 2023-02-06 15:42:53 +01:00
_cli.php A few additional PHPStan rules (#5388) 2023-05-11 13:02:04 +02:00
_update-or-create-user.php Complete PHPStan Level 6 (#5305) 2023-04-17 08:30:21 +02:00
access-permissions.sh Update Docker image Alpine 3.18 (#5383) 2023-05-10 23:54:49 +02:00
actualize-user.php Complete PHPStan Level 6 (#5305) 2023-04-17 08:30:21 +02:00
check.translation.php phpstan level 9 for check.translation.php (#5353) 2023-04-29 20:08:36 +02:00
create-user.php fix: Fix check of existing usernames in cli scripts (#5667) 2023-09-22 11:41:49 +02:00
db-optimize.php Complete PHPStan Level 6 (#5305) 2023-04-17 08:30:21 +02:00
delete-user.php fix: Fix check of existing usernames in cli scripts (#5667) 2023-09-22 11:41:49 +02:00
do-install.php A few additional PHPStan rules (#5388) 2023-05-11 13:02:04 +02:00
export-opml-for-user.php Complete PHPStan Level 6 (#5305) 2023-04-17 08:30:21 +02:00
export-sqlite-for-user.php Complete PHPStan Level 6 (#5305) 2023-04-17 08:30:21 +02:00
export-zip-for-user.php Complete PHPStan Level 6 (#5305) 2023-04-17 08:30:21 +02:00
import-for-user.php Complete PHPStan Level 6 (#5305) 2023-04-17 08:30:21 +02:00
import-sqlite-for-user.php Complete PHPStan Level 6 (#5305) 2023-04-17 08:30:21 +02:00
index.html CLI list-users and create-user 2016-10-22 12:58:06 +02:00
list-users.php Modify shebang to be more portable (#3038) 2020-06-06 19:04:21 +02:00
manipulate.translation.php A few additional PHPStan rules (#5388) 2023-05-11 13:02:04 +02:00
prepare.php PHPStan 6 for CLI (#5258) 2023-04-05 16:19:14 +02:00
reconfigure.php A few additional PHPStan rules (#5388) 2023-05-11 13:02:04 +02:00
sensitive-log.sh API avoid logging passwords (#5001) 2023-01-11 23:27:14 +01:00
translation-update.sh Use typographic quotes (#4133) 2022-01-08 21:58:55 +01:00
update-user.php Add PHPStan (#4021) 2021-12-31 17:00:51 +01:00
user-info.php A few additional PHPStan rules (#5388) 2023-05-11 13:02:04 +02:00

README.md

FreshRSS Command-Line Interface (CLI)

Note on access rights

When using the command-line interface, remember that your user might not be the same as the one used by your Web server. This might create some access right problems.

It is recommended to invoke commands using the same user as your Web server:

cd /usr/share/FreshRSS
sudo -u www-data sh -c './cli/list-users.php'

In any case, when you are done with a series of commands, you should re-apply the access rights:

cd /usr/share/FreshRSS
sudo cli/access-permissions.sh

Commands

Options in parenthesis are optional.

System

cd /usr/share/FreshRSS

./cli/prepare.php
# Ensure the needed directories in ./data/

./cli/do-install.php --default_user admin [ --auth_type form --environment production --base_url https://rss.example.net --language en --title FreshRSS --allow_anonymous --api_enabled --db-type mysql --db-host localhost:3306 --db-user freshrss --db-password dbPassword123 --db-base freshrss --db-prefix freshrss ]
# --auth_type can be: 'form' (default), 'http_auth' (using the Web server access control), 'none' (dangerous)
# --db-type can be: 'sqlite' (default), 'mysql' (MySQL or MariaDB), 'pgsql' (PostgreSQL)
# --base_url should be a public (routable) URL if possible, and is used for push (WebSub), for some API functions (e.g. favicons), and external URLs in FreshRSS.
# --environment can be: 'production' (default), 'development' (for additional log messages)
# --language can be: 'en' (default), 'fr', or one of the [supported languages](../app/i18n/)
# --db-prefix is an optional prefix in front of the names of the tables. We suggest using 'freshrss_'
# This command does not create the default user. Do that with ./cli/create-user.php

./cli/reconfigure.php
# Same parameters as for do-install.php. Used to update an existing installation.

More options for the configuration of your instance may be set in ./data/config.custom.php before the install process, or in ./data/config.php after the install process.

User

cd /usr/share/FreshRSS

./cli/create-user.php --user username [ --password 'password' --api_password 'api_password' --language en --email user@example.net --token 'longRandomString' --no_default_feeds --purge_after_months 3 --feed_min_articles_default 50 --feed_ttl_default 3600 --since_hours_posts_per_rss 168 --max_posts_per_rss 400 ]
# --language can be: 'en' (default), 'fr', or one of the [supported languages](../app/i18n/)

./cli/update-user.php --user username [ ... ]
# Same options as create-user.php, except --no_default_feeds which is only available for create-user.php

More options for the configuration of users may be set in ./data/config-user.custom.php prior to creating new users, or in ./data/users/*/config.php for existing users.

./cli/actualize-user.php --user username
# Fetch feeds for the specified user

./cli/delete-user.php --user username

./cli/list-users.php
# Return a list of users, with the default/admin user first

./cli/user-info.php [ -h --header --json --user username1 --user username2 ... ]
# -h is to use a human-readable format
# --header outputs some columns headers
# --json JSON format (disables --header and -h but uses ISO Zulu format for dates)
# --user indicates a username, and can be repeated
# Returns: 1) a * if the user is admin, 2) the name of the user,
#  3) the date/time of last user action, 4) the size occupied,
#  and the number of: 5) categories, 6) feeds, 7) read articles, 8) unread articles, 9) favourites, 10) tags,
#  11) language, 12) e-mail

./cli/import-for-user.php --user username --filename /path/to/file.ext
# The extension of the file { .json, .opml, .xml, .zip } is used to detect the type of import

./cli/export-sqlite-for-user.php --user username --filename /path/to/db.sqlite
# Export the users database to a new SQLite file.

./cli/import-sqlite-for-user.php --user username [ --force-overwrite ] --filename /path/to/db.sqlite
# Import the users database from an SQLite file.
# --force-overwrite will clear the target user database before import (import only works on an empty user database)

./cli/export-opml-for-user.php --user username > /path/to/file.opml.xml

./cli/export-zip-for-user.php --user username [ --max-feed-entries 100 ] > /path/to/file.zip

Database

cd /usr/share/FreshRSS

./cli/db-optimize.php --user username
# Optimize database (reduces the size) for a given user (perform `OPTIMIZE TABLE` in MySQL, `VACUUM` in SQLite)

Translation

cd /usr/share/FreshRSS

./cli/manipulate.translation.php  --a [-h --a --k --v --l --o]
# manipulate the i18n language files
# -h is to use a human-readable format
# --a selects the action to perform. (can be: add, delete, exist, format, and ignore.
# --k selects the key to work on.
# --v selects the value to set.
# --l selects the language to work on.
# --r revert the action (only for ignore action)
# --o selects the origin language (only for add language action)

Note about cron

Some commands display information on standard error; cron will send an email with this information every time the command will be executed (exited zero or non-zero).

To avoid cron sending email on success:

@daily /usr/local/bin/my-command > /var/log/cron-freshrss-stdout.log 2>/var/log/cron-freshrss-stderr.log || cat /var/log/cron-freshrss-stderr.log

Explanations:

  • /usr/local/bin/my-command > /var/log/cron-freshrss-stdout.log_ : redirect the standard output to a log file
  • /usr/local/bin/my-command 2> /var/log/cron-freshrss-stderr.log : redirect the standard error to a log file
  • || cat /var/log/cron-freshrss-stderr.log_ : if the exit code of _/usr/local/bin/my-command is non-zero, then it send by mail the content error file.

Now, cron will send you an email only if the exit code is non-zero and with the content of the file containing the errors.

Unix piping

It is possible to invoke a command multiple times, e.g. with different usernames, thanks to the xargs -n1 command. Example showing user information for all users which username starts with a:

./cli/list-users.php | grep '^a' | xargs -n1 ./cli/user-info.php -h --user

Example showing all users ranked by date of last activity:

./cli/user-info.php -h | sort -k2 -r

Example to get the number of feeds of a given user:

./cli/user-info.php --user alex | cut -f6
#or
./cli/user-info.php --user alex --json | jq '.[] | .feeds'

Example to get the name of the users who have not been active since a given date:

cli/user-info.php --json | jq '.[] | select(.last_user_activity < "2020-05-01") | .user'

Example to get the date and name of users who have not been active the past 24 hours (86400 seconds):

cli/user-info.php --json | jq -r '.[] | select((.last_user_activity | fromdate) < (now - 86400)) | [.last_user_activity, .user] | @csv'

Install and updates

If you want to administrate FreshRSS using git, please read our installation docs and update guidelines.