Answer the question
In order to leave comments, you need to log in
How to copy a file with the replacement of some sections in it?
Hello. There is a configured server. And files for virtual hosts. I want to make a script that asks the user for several parameters and then copies the files for the host with the replacement of some values in it. Tell me how this can be done. In particular, the replacement within the file.
Answer the question
In order to leave comments, you need to log in
In general, I found a solution here . I am using the sed command.
It seems you need not a script. You need to master, for example, Ansible and use configuration file templates.
replacement within a file
#! /bin/bash
subst()
{
eval "cat <<EOF
`cat \"$1\"`
EOF"
}
. ./config
subst ./dhcpd.conf.in > ./dhcpd.conf
ddns-update-style interim;
ignore client-updates;
subnet ${NET}.0 netmask 255.255.255.0 {
option routers ${NET}.1;
option subnet-mask 255.255.255.0;
option domain-name-servers 192.168.248.21;
option root-path "${NET}.1:/tftpboot/tensilica/rootfs/${ROOTFS}${NFS_MOUNT_OPTIONS}";
range dynamic-bootp ${NET}.128 ${NET}.128;
default-lease-time 21600;
max-lease-time 43200;
}
NET=192.168.135
ROOTFS=cp0_latest
NFS_MOUNT_OPTIONS=${NFS_MOUNT_OPTIONS},noac
IF_CONFIG="$NET.1 up"
CONFIG=debug-kc705-cp0_latest
KERNEL_IMAGE=uImage
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question