Pretty new to systemctl, I would like to display my VM ip address on console when I boot my centos.
I created a service and enabled it :
[root@centos-3 system]# cat show-ip-on-boot.service
[Unit]
Description=Show IP of eno interface on boot
[Service]
Type=oneshot
ExecStart=/usr/bin/show-ip-on-boot.sh
[Install]
WantedBy=multi-user.target
The "show-ip-on-boot.sh" script is :
#!/bin/sh
ip a | grep "inet" | grep "eno" | awk -F/ '{print $1}' | awk '{print $2}'
When I start the service manually, I can see in the logs that it is working :
[root@centos-3 ~]# journalctl -u show-ip-on-boot
-- Logs begin at Thu 2016-10-06 13:59:38 CEST, end at Thu 2016-10-06 14:15:37 CEST. --
Oct 06 14:04:32 centos-3.localdomain systemd[1]: Starting Show IP of eno interface on boot...
Oct 06 14:04:32 centos-3.localdomain show-ip-on-boot.sh[2180]: 192.168.0.43
Oct 06 14:04:32 centos-3.localdomain systemd[1]: Started Show IP of eno interface on boot.
but how can I see it displayed on console at boot ? Should I add something to my script?
Also, when I reboot, I can see in logs that the service is started but it doesn't execute the command :
[root@centos-3 ~]# systemctl status show-ip-on-boot.service
â show-ip-on-boot.service - Show IP of eno interface on boot
Loaded: loaded (/etc/systemd/system/show-ip-on-boot.service; enabled; vendor preset: disabled)
Active: inactive (dead) since Thu 2016-10-06 13:33:55 CEST; 1min 52s ago
Process: 740 ExecStart=/usr/bin/show-ip-on-boot.sh (code=exited, status=0/SUCCESS)
Main PID: 740 (code=exited, status=0/SUCCESS)
Oct 06 13:33:54 centos-3.localdomain systemd[1]: Starting Show IP of eno interface on boot...
Oct 06 13:33:55 centos-3.localdomain systemd[1]: Started Show IP of eno interface on boot.
I probably miss something in systemd concept... Can you please give me a hint on that matter. Thanks.