summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/manpages/vtysh.rst8
-rw-r--r--vtysh/vtysh_main.c38
2 files changed, 37 insertions, 9 deletions
diff --git a/doc/manpages/vtysh.rst b/doc/manpages/vtysh.rst
index 3e496956c2..b930cb915d 100644
--- a/doc/manpages/vtysh.rst
+++ b/doc/manpages/vtysh.rst
@@ -53,6 +53,10 @@ OPTIONS available for the vtysh command:
When executing cli that does not invoke a vtysh shell, if an error ocurrs ignore it for purposes of return codes from vtysh.
+.. option:: -H, --histfile
+
+ Override the history file for vtysh commands. You can set ``vtysh -H /dev/null`` to turn logging of at all.
+
.. option:: -u, --user
Restrict access to configuration commands by preventing use of the "enable" command. This option provides the same limited "security" as password-protected telnet access. *This security should not be relied on in production environments.*
@@ -68,6 +72,10 @@ ENVIRONMENT VARIABLES
VTYSH_PAGER
This should be the name of the pager to use. Default is more.
+VTYSH_HISTFILE
+ Override the history file for vtysh commands. Logging can be turned off using ``VTYSH_HISTFILE=/dev/null vtysh``.
+ Environment is prefered way to override the history file path over command line argument (-H/--histfile).
+
FILES
=====
|INSTALL_PREFIX_SBIN|/vtysh
diff --git a/vtysh/vtysh_main.c b/vtysh/vtysh_main.c
index db7cc312d6..fe33bed7f6 100644
--- a/vtysh/vtysh_main.c
+++ b/vtysh/vtysh_main.c
@@ -153,8 +153,10 @@ static void usage(int status)
progname);
else
printf("Usage : %s [OPTION...]\n\n"
- "Integrated shell for FRR (version " FRR_VERSION "). \n"
- "Configured with:\n " FRR_CONFIG_ARGS "\n\n"
+ "Integrated shell for FRR (version " FRR_VERSION
+ "). \n"
+ "Configured with:\n " FRR_CONFIG_ARGS
+ "\n\n"
"-b, --boot Execute boot startup configuration\n"
"-c, --command Execute argument as command\n"
"-d, --daemon Connect only to the specified daemon\n"
@@ -167,6 +169,7 @@ static void usage(int status)
"-N --pathspace Insert prefix into config & socket paths\n"
"-u --user Run as an unprivileged user\n"
"-w, --writeconfig Write integrated config (frr.conf) and exit\n"
+ "-H, --histfile Override history file\n"
"-h, --help Display this help and exit\n\n"
"Note that multiple commands may be executed from the command\n"
"line by passing multiple -c args, or by embedding linefeed\n"
@@ -189,6 +192,7 @@ struct option longopts[] = {
{"vty_socket", required_argument, NULL, OPTION_VTYSOCK},
{"config_dir", required_argument, NULL, OPTION_CONFDIR},
{"inputfile", required_argument, NULL, 'f'},
+ {"histfile", required_argument, NULL, 'H'},
{"echo", no_argument, NULL, 'E'},
{"dryrun", no_argument, NULL, 'C'},
{"help", no_argument, NULL, 'h'},
@@ -321,6 +325,7 @@ int main(int argc, char **argv, char **env)
char sysconfdir[MAXPATHLEN];
const char *pathspace_arg = NULL;
char pathspace[MAXPATHLEN] = "";
+ const char *histfile = NULL;
/* SUID: drop down to calling user & go back up when needed */
elevuid = geteuid();
@@ -341,8 +346,8 @@ int main(int argc, char **argv, char **env)
/* Option handling. */
while (1) {
- opt = getopt_long(argc, argv, "be:c:d:nf:mEhCwN:u",
- longopts, 0);
+ opt = getopt_long(argc, argv, "be:c:d:nf:H:mEhCwN:u", longopts,
+ 0);
if (opt == EOF)
break;
@@ -409,6 +414,9 @@ int main(int argc, char **argv, char **env)
case 'h':
usage(0);
break;
+ case 'H':
+ histfile = optarg;
+ break;
default:
usage(1);
break;
@@ -569,12 +577,24 @@ int main(int argc, char **argv, char **env)
/*
* Setup history file for use by both -c and regular input
* If we can't find the home directory, then don't store
- * the history information
+ * the history information.
+ * VTYSH_HISTFILE is prefered over command line
+ * argument (-H/--histfile).
*/
- homedir = vtysh_get_home();
- if (homedir) {
- snprintf(history_file, sizeof(history_file), "%s/.history_frr",
- homedir);
+ if (getenv("VTYSH_HISTFILE")) {
+ const char *file = getenv("VTYSH_HISTFILE");
+
+ strlcpy(history_file, file, sizeof(history_file));
+ } else if (histfile) {
+ strlcpy(history_file, histfile, sizeof(history_file));
+ } else {
+ homedir = vtysh_get_home();
+ if (homedir)
+ snprintf(history_file, sizeof(history_file),
+ "%s/.history_frr", homedir);
+ }
+
+ if (strlen(history_file) > 0) {
if (read_history(history_file) != 0) {
int fp;