#!/bin/sh
##########################################################
-# Copyright (c) 2006-2022 VMware, Inc. All rights reserved.
+# Copyright (c) 2006-2024 Broadcom. All Rights Reserved.
+# The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published
}
+# Get the log files mentioned in the logging section of tools.conf. Get the log
+# archive file names
+# The archive logic for these logs files seems to be this. Below is one example:
+# if vmtoolsd.data = vmtoolsd.log
+# then the file is backed up as vmtoolsd.1.log vmtoolsd.2.log etc
+# if vmtoolsd.data = vmtoolsdlog
+# then the file is backed up as vmtoolsdlog.1 vmtoolsdlog.2 etc
+# if vmtoolsd.data = vmtoolsdlog.a
+# then the file is backed up as vmtoolsdlog.1.a vmtoolsdlog.2.a etc
+addLogFiles()
+{
+ IFS=""
+ vmware-toolbox-cmd config get logging | grep "\.data =" | cut -d"=" -f2 | while read -r logFile; do
+ logFile=`eval echo "$logFile"`
+ if [ -z "$logFile" ]; then
+ continue
+ fi
+
+ # trim the leading spaces
+ logFile=`echo $logFile | sed 's/^ *//'`
+ dirName=`dirname $logFile`
+ fileName=`basename $logFile`
+
+ #find and add the current logs
+ find "$dirName" -maxdepth 1 -name "$fileName" -print | while read -r logFile; do
+ addfile "$logFile"
+ done
+
+ # File prefix is the part that is before the last '.' in the file name
+ fileNamePrefix=`echo $fileName | rev | cut -d"." -f2- | rev`
+
+ # File suffix is the part that is after the last '.' in the file name
+ fileNameSuffix=`echo $fileName | rev | cut -s -d"." -f1 | rev`
+ # Add numbers after the prefix to get all the backed up file names
+ # Also add the .suffix if suffix exists
+ if [ -z "$fileNameSuffix" ]; then
+ fileName="${fileNamePrefix}.*[0-9]"
+ else
+ fileName="${fileNamePrefix}.*[0-9].${fileNameSuffix}"
+ fi
+
+ find "$dirName" -maxdepth 1 -name "$fileName" -print | while read -r logFile; do
+ addfile "$logFile"
+ done
+ done
+}
+
+
# runcmd($out, $cmd): executes the command redirected to a file
runcmd()
{
runcmd "/tmp/apt-list.txt" apt list
fi
runcmd "/tmp/free.txt" free
+
+ addLogFiles
}
export PATH=/bin:/sbin:/usr/bin:/usr/sbin
TARFILE=vm-`date +%Y-%m-%d`.$$.tar.gz
-VER=0.95
+VER=0.96
# Parse args
for option in $@
##########################################################
-# Copyright (c) 2010-2017,2020-2021 VMware, Inc. All rights reserved.
+# Copyright (c) 2010-2024 Broadcom. All Rights Reserved.
+# The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published
error.unknown = "%1$s: Unknown %2$s '%3$s'\n"
-help.config = "%1$s: modify Tools configuration\nUsage: %2$s %3$s <subcommand>\n\nSubcommands:\n get <section> <key>: display current value for <key>\n NOTE: If the <key> is not present in tools.conf, its\n value from the global configuration is returned if present\n set <section> <key> <value>: set <key> to <value>\n\n remove <section> <key>: remove <key>\n\n<section> can be any supported section, such as logging, guestoperations or guestinfo.\n<key> can be any configuration key.\n<value> can be any value.\n"
+help.config = "%1$s: modify Tools configuration\nUsage: %2$s %3$s <subcommand>\n\nSubcommands:\n get <section> : display all the key values in the <section>\n get <section> <key>: display current value for <key>\n NOTE: If the <key> is not present in tools.conf, its\n value from the global configuration is returned if present\n set <section> <key> <value>: set <key> to <value>\n\n remove <section> <key>: remove <key>\n\n<section> can be any supported section, such as logging, guestoperations or guestinfo.\n<key> can be any configuration key.\n<value> can be any value.\n"
help.device = "%1$s: functions related to the virtual machine's hardware devices\nUsage: %2$s %3$s <subcommand> [args]\ndev is the name of the device.\n\nSubcommands:\n enable <dev>: enable the device dev\n disable <dev>: disable the device dev\n list: list all available devices\n status <dev>: print the status of a device\n"
/*********************************************************
- * Copyright (c) 2016,2020-2021 VMware, Inc. All rights reserved.
+ * Copyright (c) 2016-2024 Broadcom. All Rights Reserved.
+ * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
#include "vmware/tools/i18n.h"
#include "vmware/tools/utils.h"
#include "vmware/tools/log.h"
+#include "vm_assert.h"
/*
{
GKeyFile *confDict = NULL;
int ret = EXIT_SUCCESS;
- gchar *value = NULL;
VMTools_LoadConfig(NULL,
G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS,
if (confDict) {
TOOLBOXCMD_LOAD_GLOBALCONFIG(confDict)
- value = g_key_file_get_string(confDict, section,
- key, NULL);
- } else {
- ret = EX_UNAVAILABLE;
- }
- if (value) {
- g_print("[%s] %s = %s\n", section, key, value);
+ // If there is no key, get all the key value pairs in the section
+ if (key == NULL) {
+ gchar **keys;
+ gsize numKeys;
+ GError *err = NULL;
+ int index;
+
+ keys = g_key_file_get_keys(confDict, section, &numKeys, &err);
+ if (err) {
+ g_print("[%s] UNSET\n", section);
+ } else {
+ g_print("[%s]\n", section);
+ for (index = 0; index < numKeys; index++) {
+ gchar *value = g_key_file_get_string(confDict,
+ section, keys[index], NULL);
+ ASSERT(value != NULL);
+ if (value) {
+ g_print("%s = %s\n", keys[index], value);
+ }
+ g_free(value);
+ }
+ }
+ g_strfreev(keys);
+ } else {
+ gchar *value = g_key_file_get_string(confDict, section, key, NULL);
+ if (value) {
+ g_print("[%s] %s = %s\n", section, key, value);
+ } else {
+ g_print("[%s] %s UNSET\n", section, key);
+ }
+ g_free(value);
+ }
} else {
- g_print("[%s] %s UNSET\n", section, key);
+ ret = EX_UNAVAILABLE;
}
g_key_file_free(confDict);
- g_free(value);
return ret;
}
SU_(arg.config.operation, "config operation"));
return EX_USAGE;
}
+ op = argv[optind];
if ((optind + 1) >= argc) {
ToolsCmd_MissingEntityError(argv[0],
SU_(arg.config.section, "config section"));
return EX_USAGE;
}
+ section = argv[optind + 1];
if ((optind + 2) >= argc) {
- ToolsCmd_MissingEntityError(argv[0],
+ /*
+ * For 'get' operation, key is optional
+ * With no key, 'get' operation prints all key-value pairs in that section
+ */
+ if (toolbox_strcmp(op, "get") != 0) {
+ ToolsCmd_MissingEntityError(argv[0],
SU_(arg.config.key, "config key"));
- return EX_USAGE;
+ return EX_USAGE;
+ }
+ key = NULL;
+ } else {
+ key = argv[optind + 2];
}
- op = argv[optind];
- section = argv[optind + 1];
- key = argv[optind + 2];
-
if (toolbox_strcmp(op, "set") == 0) {
const char *value;
"%s: modify Tools configuration\n"
"Usage: %s %s <subcommand>\n\n"
"Subcommands:\n"
+ " get <section> : display all the key values in the <section>\n"
" get <section> <key>: display current value for <key>\n"
" NOTE: If the <key> is not present in tools.conf, its\n"
" value from the global configuration is returned if present\n"