2021/9/10

system service : report ip to another server

啟動後,等 remote server up,然後把 自己的 ip 送過去..
先把自己的 public key 送過去 (user charles-chang)。設定好 ssh 免 password.
準備 service file:
xeontitan:/etc/systemd/system# cat reportip.service 
[Unit]
Description=send my ip address file to rdsuper
Afteter=network-online.target

[Service]
User=charles-chang
WorkingDirectory=/home/charles-chang
ExecStart=/home/charles-chang/reportip.sh

[Install]
WantedBy=multi-user.target
charles-chang 自己的 shell script:
cat /home/charles-chang/reportip.sh 
#!/bin/bash
while true
do
	ping -c 1 rdsuper
	if [ $? -eq 0 ]
	then
		break
	fi
	sleep 10
done
ip addr > $HOSTNAME-ip
scp $HOSTNAME-ip rdsuper:~/
enable & start
systemctl daemon-reload
systemctl enable reportip.service
systemctl start reportip.service

沒有留言:

張貼留言