Jul 10 2018

Virtual IP Creation with Linux Service in CentOS 7

Category: Linux & UnixFatih Acar @ 10:43

You can create virtual IP address with linux service. I designed the linux service to create a virtual IP address when operating system is rebooted.

My System Properties

Ethernet Adaptor Name : ens14025
Virtual IP : 192.168.44.55

1. Create Bash Script To Create Virtual IP Address


[root@test ~]# vi /opt/scripts/virtual_ip_up.sh

#!/bin/bash
ifconfig ens14025:1 192.168.44.55 netmask 255.255.255.0

[root@test ~]# chmod 744 /opt/scripts/virtual_ip_up.sh

2. Create Service File


[root@test ~]# vi /etc/systemd/system/virtual_ip.service

[Unit]
Description=Virtual IP
After=syslog.target
After=network.target

[Service]
Type=simple

User=root
Group=root

OOMScoreAdjust=-1000

ExecStart=/opt/scripts/virtual_ip_up.sh

TimeoutSec=300

[Install]
WantedBy=multi-user.target


[root@test ~]# chmod 644 /etc/systemd/system/virtual_ip.service

3. Start Service



[root@test ~]# systemctl daemon-reload
[root@test ~]# systemctl start virtual_ip.service
[root@test ~]# systemctl enable virtual_ip.service

4,155 total views, 5 views today

Tags: Linux, Linux Administration, System Administration


Nov 21 2011

Delete File or Directory from Linux System

Category: Linux & UnixFatih Acar @ 00:11

rm and rmdir commands uses to delete from linux system. rm command use for delete file. On the other hand, rmdir command uses for delete directory from linux system. Also, rm command can delete directory with -rf option.

Firstly, we would create a directory and files for test.

create directory and files

#> mkdir /testdirectory
#> vi testfile1.abc
#> vi testfile2.cba

delete directory and files with rm command

#> rm -rf /testdirectory
Note : This command do that delete /testdirectory and files.
#>rm -f /testdirectory/testfile1.abc
Note : This command do that delete testfile1.abc

delete directory with rmdir command

#> rmdir /testdirectory
Note : If /testdirectory do not have file, this command can delete directory. Else, can not delete. You have to use rm -rf command for delete with files.

13,305 total views, no views today

Tags: Linux, System Administration


Sep 21 2011

pg_dumpall with shell script and crontab in Linux

Category: Administration,Linux & UnixFatih Acar @ 13:18

You can take schedule backup with shell script. Firstly, You must create shell script file in operating system. After you can append to crontab.

Crontab is a UNIX command that creates a table or list of commands, each of which is to be executed by the operating system at a specified time. crontab is used to create the crontab file (the list) and later used to change the previously created crontab file.

Crontab

crontab -e Edit your crontab file, or create one if it doesn’t already exist.
crontab -l List your crontab file.
crontab -r Remove your crontab file.
crontab -v Display the last time you edited your crontab file.

Minute Hour Day of Month Month Day of Week Command
(0-59) (0-23) (1-31) (1-12 or Jan-Dec) (0-6 or Sun-Sat)
0 2 12 * 0,6 /usr/bin/shellscriptname.sh

We will take backup wirh pg_dumpall. Firstly, You must create shell script.

Example

$>cd /etc/scripts/
$>vi shellscriptname.sh
Note : We created shellscriptname.sh with vi shellscriptname.sh statement. You have to write below script.

export today=`date +%Y%m%d`

export deleteday=`/bin/date –date=”15 days ago” +%Y%m%d`

##delete old backup script
rm -f /tmp/pgalldump_$deleteday.dump.out

##create backup script
pg_dumpall > /tmp/pgalldump_$today.dump.out

Note : After write, You close editor with ” escape > :wq! > enter “. You saved.

We wrote shell script. Now, We have to append to crontab.

Example

$>crontab -e
10 1 * * * /etc/scripts/shellscriptname.sh

Note : After write, You close editor with ” escape > :wq! > enter “. You saved. This time statement mean that shell script will execute every days of week,every month, every day, at 1 hour past 10 minute.

26,367 total views, no views today

Tags: Database Administration, Linux, PostgreSQL