Skip to content

Commit

Permalink
inspect: only get the first grep results
Browse files Browse the repository at this point in the history
To avoid getting multiple results breaking the inspect data file, limit
the grep results from rhn.conf to one result.
  • Loading branch information
cbosdo committed Nov 12, 2024
1 parent 2a5d00b commit 3683d4f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions shared/utils/serverinspector.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ func NewServerInspector(scriptDir string) ServerInspector {
"sed 's/.*(\\([0-9.]\\+\\).*/\\1/g' /etc/susemanager-release || true"),
types.NewInspectData(
"fqdn",
"cat /etc/rhn/rhn.conf 2>/dev/null | grep 'java.hostname' | cut -d' ' -f3 || true"),
"cat /etc/rhn/rhn.conf 2>/dev/null | grep -m1 '^java.hostname' | cut -d' ' -f3 || true"),
types.NewInspectData(
"image_pg_version",
"rpm -qa --qf '%{VERSION}\\n' 'name=postgresql[0-8][0-9]-server' | cut -d. -f1 | sort -n | tail -1 || true"),
types.NewInspectData("current_pg_version",
"(test -e /var/lib/pgsql/data/PG_VERSION && cat /var/lib/pgsql/data/PG_VERSION) || true"),
types.NewInspectData("db_user",
"cat /etc/rhn/rhn.conf 2>/dev/null | grep '^db_user' | cut -d' ' -f3 || true"),
"cat /etc/rhn/rhn.conf 2>/dev/null | grep -m1 '^db_user' | cut -d' ' -f3 || true"),
types.NewInspectData("db_password",
"cat /etc/rhn/rhn.conf 2>/dev/null | grep '^db_password' | cut -d' ' -f3 || true"),
"cat /etc/rhn/rhn.conf 2>/dev/null | grep -m1 '^db_password' | cut -d' ' -f3 || true"),
types.NewInspectData("db_name",
"cat /etc/rhn/rhn.conf 2>/dev/null | grep '^db_name' | cut -d' ' -f3 || true"),
"cat /etc/rhn/rhn.conf 2>/dev/null | grep -m1 '^db_name' | cut -d' ' -f3 || true"),
types.NewInspectData("db_port",
"cat /etc/rhn/rhn.conf 2>/dev/null | grep '^db_port' | cut -d' ' -f3 || true"),
"cat /etc/rhn/rhn.conf 2>/dev/null | grep -m1 '^db_port' | cut -d' ' -f3 || true"),
},
ScriptDir: scriptDir,
DataPath: path.Join(InspectContainerDirectory, inspectDataFile),
Expand Down
10 changes: 5 additions & 5 deletions shared/utils/serverinspector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ func TestServerInspectorGenerate(t *testing.T) {
# inspect.sh, generated by mgradm
echo "uyuni_release=$(cat /etc/*release | grep 'Uyuni release' | cut -d ' ' -f3 || true)" >> ` + dataPath + `
echo "suse_manager_release=$(sed 's/.*(\([0-9.]\+\).*/\1/g' /etc/susemanager-release || true)" >> ` + dataPath + `
echo "fqdn=$(cat /etc/rhn/rhn.conf 2>/dev/null | grep 'java.hostname' | cut -d' ' -f3 || true)" >> ` + dataPath + `
echo "fqdn=$(cat /etc/rhn/rhn.conf 2>/dev/null | grep -m1 '^java.hostname' | cut -d' ' -f3 || true)" >> ` + dataPath + `
echo "image_pg_version=$(rpm -qa --qf '%{VERSION}\n' 'name=postgresql[0-8][0-9]-server' | cut -d. -f1 | sort -n | tail -1 || true)" >> ` + dataPath + `
echo "current_pg_version=$((test -e /var/lib/pgsql/data/PG_VERSION && cat /var/lib/pgsql/data/PG_VERSION) || true)" >> ` + dataPath + `
echo "db_user=$(cat /etc/rhn/rhn.conf 2>/dev/null | grep '^db_user' | cut -d' ' -f3 || true)" >> ` + dataPath + `
echo "db_password=$(cat /etc/rhn/rhn.conf 2>/dev/null | grep '^db_password' | cut -d' ' -f3 || true)" >> ` + dataPath + `
echo "db_name=$(cat /etc/rhn/rhn.conf 2>/dev/null | grep '^db_name' | cut -d' ' -f3 || true)" >> ` + dataPath + `
echo "db_port=$(cat /etc/rhn/rhn.conf 2>/dev/null | grep '^db_port' | cut -d' ' -f3 || true)" >> ` + dataPath + `
echo "db_user=$(cat /etc/rhn/rhn.conf 2>/dev/null | grep -m1 '^db_user' | cut -d' ' -f3 || true)" >> ` + dataPath + `
echo "db_password=$(cat /etc/rhn/rhn.conf 2>/dev/null | grep -m1 '^db_password' | cut -d' ' -f3 || true)" >> ` + dataPath + `
echo "db_name=$(cat /etc/rhn/rhn.conf 2>/dev/null | grep -m1 '^db_name' | cut -d' ' -f3 || true)" >> ` + dataPath + `
echo "db_port=$(cat /etc/rhn/rhn.conf 2>/dev/null | grep -m1 '^db_port' | cut -d' ' -f3 || true)" >> ` + dataPath + `
exit 0
`

Expand Down

0 comments on commit 3683d4f

Please sign in to comment.