Ubuntu: Can I use while and source in the bash script?


I have this script, it's cut down, but fine for this example:

#!/bin/bash    source /home/user/configs/config-file    while read host; do    find /home/user/configs/$host.cfg -type f -exec sed -i 's/value=./#value= /g' {} \;    echo "value="$value >> /home/user/configs/$host.cfg    done < hosts.list  

The hosts.list file contains a list of hostnames

XYZ123  ABC567  LIN999  

etc. The config-file contains entires like:

value=ZZZZZZZ  othervalue=YYYYYYY  3rdvalue=XXXXXXX  

Full script makes use of all values, this example just uses value Hope that make sense.

Running this script creates a file with each hostname from the hosts.list file, but with a ? at the end, so one would look like XYZ123?.cfg During the run process I see:

find: â/home/user/configs/XYZ123\r.cfgâ: No such file or directory  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »