How to use Awk to use a template and save a copy on a remote server?

Viewed 28

I have the following command that I am trying to run. The problem is every time I run the script it says it cannot find the file or directory.

awk -v host=$host -v stockcode=$other1 '{sub(/DIGICODE/,host);sub(/SYSMAN/,stockcode); print }' ${web}service/cert.html >> ${web}service/cert_new.html

So cert.html is my template, cert_new.html is my desired output file.

${web} is my servers IP address ie "127.0.0.1/test/" $host and $other1 are local variables inside my bash script.

Now when it runs the output is the following :

127.0.0.1/test/service/cert_new.html: No such file or directory

I am not sure if Awk is the best way to go ?

1 Answers

Your problem has nothing to do with awk.

To verify this assumption, first run

awk -v host="$host" -v stockcode="$other1" '{sub(/DIGICODE/,host);sub(/SYSMAN/,stockcode); print }' ${web}service/cert.html

if it produces the expected output you are fine.

Then, verify the directory and eventually the file you are trying to append exist (in the same directory you are expecting to run awk)

if [[ ! -d "${web}service/" ]]
then
    echo "error"
fi

if [[ ! -f "${web}service/cert_new.html" ]]
then
    echo "file does not exist"
fi
Related