Irina I
Irina I

Reputation: 33

Files get copied and renamed but I also get errors

I have a script that reads a text file that has all the nodes listed in there:

node1
node2
node3
.
.
.

It creates a ".conf" file for each node in the /etc/icinga2/zones.d/master/hosts/new/ directory

Copies the content of the file name linux-template into each new conf file.

Everything worked as I expected, but I also get errors for each node:

Can anyone please help?

Thanks

This is my script:

#!/bin/bash

cd /etc/icinga2/zones.d/master/hosts/new

while read f; do
   cp -v "$f" /etc/icinga2/zones.d/master/hosts/new/"$f.conf"
   cp linux-template.conf "$f.conf"
   chown icinga:icinga "$f.conf"

done < linux-list.txt

Once everything got copied, I get these errors below (for all the nodes, ie. node 1):

cp: cannot stat ‘node1’: No such file or directory 
chown: cannot access ‘node1’: No such file or directory

Upvotes: 1

Views: 49

Answers (1)

Bobby Tables
Bobby Tables

Reputation: 301

It looks like it's complaining because there isn't a file called "node1" in your directory and you have verbose mode on.

This script looks like it will also cause undesired behavior if you're not located in the /etc/icinga2/zones.d/master/hosts/new/ directory when you run it.

The script is saying:

  1. Copy files node1,node2,... in my current directory and place the copy here: /etc/icinga2/zones.d/master/hosts/new/"$f.conf"
  2. Copy linux-template.conf from the current directory and name it "node[1-9].conf" in the current directory.
  3. Chown the "node[1-9].conf" in the current directory.

I suggest using absolute paths and I'm not quite sure why the first cp is necessary. If you're intending to copy linux-template.conf into each node[1-9].conf that you created in step 1, the second copy will create and overwrite the file anyway and step 1 would not be needed.

Upvotes: 1

Related Questions