Friday, April 27, 2018

Shell Script 'action' Command

'action' is defined inside a library called functions. You have to source your script first with this library in order to use it. This library is a distro distribution dependent and none of these distro libraries are compatible with the others. In Ubuntu is /lib/lsb/init-functions, SuSE has /etc/rc.status and in Centos is /etc/rc.d/init.d/functions. Some distributions don't use it at all.

Example of 'action':
# Source function library.
. /etc/rc.d/init.d/functions

# Now you can use action:
action $"Perform an action:" /bin/true

In Centos 7, 'action' definition inside /etc/rc.d/init.d/functions is as the following:
# Run some action. Log its output.
action() {
    local STRING rc

    STRING=$1
    echo -n "$STRING "
    shift
    "$@" && success $"$STRING" || failure $"$STRING"
    rc=$?
    echo
    return $rc
}

Wednesday, April 25, 2018

Set or Change System Hostname

This will return the current hostname
$ hostname
MyHostame
To set hostname immediately:
$ hostname [MY_HOSTNAME]
This will change the hostname of your system immediately, but the original hostname will be restored upon next reboot. To set hostname to be permant follow the instructions below. For systemd based distributions(newer version of different Linux distributions such as latest Ubuntu, Debian, CentOS, Fedora, RedHat, etc. ) use the hostnamectl command:
$ sudo hostnamectl set-hostname [MY_HOSTNAME]
For sysvinit(in short init) based distributions(older linux distributions) edit /etc/hostname:
# vim /etc/hostname
Add a new line for the hostname in /etc/hosts:
# vim /etc/hosts
127.0.0.1 [MY_HOSTNAME]
And run:
# /etc/init.d/hostname restart
For RHEL/CentOS based systems that use init, edit /etc/sysconfig/network:
# vi /etc/sysconfig/network
/etc/sysconfig/network
NETWORKING=yes
HOSTNAME="[MY_HOSTNAME]"
GATEWAY="192.168.0.1"
GATEWAYDEV="eth0"
FORWARD_IPV4="yes"

Popular Posts

Recent Posts

Unordered List

Text Widget

Pages

Search This Blog

Powered by Blogger.