ubuntuusers.de

hostname per sh-skript ändern

Status: Ungelöst | Ubuntu-Version: Ubuntu 14.04 (Trusty Tahr)
Antworten |

elektronenblitz63

Avatar von elektronenblitz63

Anmeldungsdatum:
16. Januar 2007

Beiträge: 29307

Wohnort: NRW

Nun, der Fehler steht doch da:

hostnamectl: Unbekannte Option »--set-hostname«

Die Befehlssyntax ist falsch.

man hostnamectl

rklm Team-Icon

Projektleitung

Anmeldungsdatum:
16. Oktober 2011

Beiträge: 13177

TrofiLi schrieb:

... vielen Dank für den Code. Ich teste ihn "rauf und runter", aber leider ohne erfolg. Welche Namen würden denn funktionieren? Ich bekomme immer - egal was ich eingebe - Fehlermeldungen

Lies doch mal die Fehlermeldung! Etwas mehr Eigeninitiative, bitte. Man kann auch selbst mal auf die Manpage schauen.

Thomas_Do Team-Icon

Moderator
Avatar von Thomas_Do

Anmeldungsdatum:
24. November 2009

Beiträge: 8808

"set-hostname" ist offenbar keine Option (die mit "–" eingeleitet wird), sondern ein Kommando (ohne "–"). Das geht aus der Manpage hervor. Ich habe das Wichtige mal gelb unterlegt.

$man hostnamectl
HOSTNAMECTL(1)                    hostnamectl                   HOSTNAMECTL(1)

NAME
       hostnamectl - Control the system hostname

SYNOPSIS
       hostnamectl [OPTIONS...] {COMMAND}

DESCRIPTION
       hostnamectl may be used to query and change the system hostname and
       related settings.

       This tool distinguishes three different hostnames: the high-level
       "pretty" hostname which might include all kinds of special characters
       (e.g. "Lennart's Laptop"), the static hostname which is used to
       initialize the kernel hostname at boot (e.g. "lennarts-laptop"), and
       the transient hostname which is a default received from network
       configuration. If a static hostname is set, and is valid (something
       other than localhost), then the transient hostname is not used.

       Note that the pretty hostname has little restrictions on the characters
       used, while the static and transient hostnames are limited to the
       usually accepted characters of Internet domain names.

       The static hostname is stored in /etc/hostname, see hostname(5) for
       more information. The pretty hostname, chassis type, and icon name are
       stored in /etc/machine-info, see machine-info(5).

       Use systemd-firstboot(1) to initialize the system host name for mounted
       (but not booted) system images.

OPTIONS
       The following options are understood:

       --no-ask-password
           Do not query the user for authentication for privileged operations.

       --static, --transient, --pretty
           If status is used (or no explicit command is given) and one of
           those fields is given, hostnamectl will print out just this
           selected hostname.

           If used with set-hostname, only the selected hostname(s) will be
           updated. When more than one of those options is used, all the
           specified hostnames will be updated.

       -H, --host=
           Execute the operation remotely. Specify a hostname, or a username
           and hostname separated by "@", to connect to. The hostname may
           optionally be suffixed by a container name, separated by ":", which
           connects directly to a specific container on the specified host.
           This will use SSH to talk to the remote machine manager instance.
           Container names may be enumerated with machinectl -H HOST.

       -M, --machine=
           Execute operation on a local container. Specify a container name to
           connect to.

       -h, --help
           Print a short help text and exit.

       --version
           Print a short version string and exit.

       The following commands are understood:

       status
           Show current system hostname and related information.

       set-hostname NAME
           Set the system hostname to NAME. By default, this will alter the
           pretty, the static, and the transient hostname alike; however, if
           one or more of --static, --transient, --pretty are used, only the
           selected hostnames are changed. If the pretty hostname is being
           set, and static or transient are being set as well, the specified
           hostname will be simplified in regards to the character set used
           before the latter are updated. This is done by replacing spaces
           with "-" and removing special characters. This ensures that the
           pretty and the static hostname are always closely related while
           still following the validity rules of the specific name. This
           simplification of the hostname string is not done if only the
           transient and/or static host names are set, and the pretty host
           name is left untouched.

           Pass the empty string "" as the hostname to reset the selected
           hostnames to their default (usually "localhost").

       set-icon-name NAME
           Set the system icon name to NAME. The icon name is used by some
           graphical applications to visualize this host. The icon name should
           follow the Icon Naming Specification[1].

           Pass an empty string to reset the icon name to the default value,
           which is determined from chassis type (see below) and possibly
           other parameters.

       set-chassis TYPE
           Set the chassis type to TYPE. The chassis type is used by some
           graphical applications to visualize the host or alter user
           interaction. Currently, the following chassis types are defined:
           "desktop", "laptop", "server", "tablet", "handset", "watch",
           "embedded", as well as the special chassis types "vm" and
           "container" for virtualized systems that lack an immediate physical
           chassis.

           Pass an empty string to reset the chassis type to the default value
           which is determined from the firmware and possibly other
           parameters.

       set-deployment ENVIRONMENT
           Set the deployment environment description.  ENVIRONMENT must be a
           single word without any control characters. One of the following is
           suggested: "development", "integration", "staging", "production".

           Pass an empty string to reset to the default empty value.

       set-location LOCATION
           Set the location string for the system, if it is known.  LOCATION
           should be a human-friendly, free-form string describing the
           physical location of the system, if it is known and applicable.
           This may be as generic as "Berlin, Germany" or as specific as "Left
           Rack, 2nd Shelf".

           Pass an empty string to reset to the default empty value.

EXIT STATUS
       On success, 0 is returned, a non-zero failure code otherwise.

SEE ALSO
       systemd(1), hostname(1), hostname(5), machine-info(5), systemctl(1),
       systemd-hostnamed.service(8), systemd-firstboot(1)

NOTES
        1. Icon Naming Specification
           http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html

systemd 228                                                     HOSTNAMECTL(1)

track

Avatar von track

Anmeldungsdatum:
26. Juni 2008

Beiträge: 7174

Wohnort: Wolfen (S-A)

Hast Du denn mal unter man hostnamectl nachgesehen, oder nur blind den Code von Robert ausgeführt ? 😲

Du solltest Dich schon mal schlau machen, was Du da überhaupt tust. Guck Dir einfach die Optionen an, dann wirst Du den Fehler schnell selber finden.

LG,

track

p.s.: Selber mitzudenken ist auch deshalb entscheidend wichtig, damit man überhaupt kapiert, was man da tat. Sonst kann man einem ja sonstwas unterjubeln !

TrofiLi

(Themenstarter)

Anmeldungsdatum:
17. Dezember 2010

Beiträge: 130

Ja, stimmt schon, Ihr habt natürlich recht. Fertige Lösungen zu erwarten ist bequem und gefährlich. Das löst zwar das Problem auf die Schnelle, bringt einen (in dem Fall mich) aber nicht weiter. In aller Regel habe ich schon den Ehrgeiz selbst hinter den Dreh zu kommen, der letztendlich zu einer zufriedenstellenden Funktion führt, doch im Moment stehe ich beruflich etwas unter Druck, komme nur punktuell zur Bearbeitung dieses Problems und hatte (wenn ich ehrlich bin) auf einen fertigen Lösungsvorschlag gehofft. Aber ich kümmere mich selber drum, sobald ich etwas Luft habe und danke Euch schonmal für die offenen, ehrlichen und hilfreichen Antworten. Ich schätze die ein oder andere Frage wird sich beim Entwickeln des passenden Codes schon noch ergeben, so ist jedenfalls mein Eindruck nach dem Diagonallesen der markierten Man-Page (Danke Thomas_Do).

Ich melde mich. LG TrofiLi

P.S.: Ein kurze Frage grundsätzlicher Art hab ich noch: Wenn ich da richtig geschnallt habe, dann ist Debian die Basis von Ubuntu. Funktionieren Shell-Skripte dann auch 1:1 unter Debian? Ohne mich je in die tiefen Ebenen der Kernelprogrammierung begeben zu haben, intuitiv würde ich drauf tippen, dass dem so ist ...

rklm Team-Icon

Projektleitung

Anmeldungsdatum:
16. Oktober 2011

Beiträge: 13177

TrofiLi schrieb:

P.S.: Ein kurze Frage grundsätzlicher Art hab ich noch: Wenn ich da richtig geschnallt habe, dann ist Debian die Basis von Ubuntu. Funktionieren Shell-Skripte dann auch 1:1 unter Debian? Ohne mich je in die tiefen Ebenen der Kernelprogrammierung begeben zu haben, intuitiv würde ich drauf tippen, dass dem so ist ...

Das kann man in der Allgemeinheit nicht beantworten. Es hängt vom einzelnen Skript ab und welche Kommandos es benutzt. Wenn die passenden Pakete installiert sind, kann es auch unter Fedora laufen etc.

Antworten |