I need to modify simple bash script to go through a files and add some text to the end of each file with name of the file variable. There's an example of Nagios .cfg file...so far I got something like this:
#!/bin/bash list=$(ls /root/user/test/ | sed "s/\.cfg//") for servery in `/root/user/test/*.cfg`; do for $list; do echo ` define service { host_name $list service_description All_fs_free_space check_command check_nrpe!check_all_disks!3% 1% use user-disk }` >> /etc/nagios3/conf.d/servers/test/$servery done done
which unfortunately didn't work, because of quotation marks...? Is there better solution how to achieve that? Thank you.
Debug output for Paul Hodges solution:
root@bla:~/blabla# ./add2.sh ++ fmt=' define service { host_name %s service_description All_fs_free_space check_command check_nrpe!check_all_disks!3%% 1%% use user-disk }' ++ for file in '/root/user/test/*.cfg' ++ cfg='*.cfg' ++ printf ' define service { host_name %s service_description All_fs_free_space check_command check_nrpe!check_all_disks!3%% 1%% use user-disk }' '*' ./add2.sh: line 14: /root/blabla/test/servers/$cfg: ambiguous redirect