-
Notifications
You must be signed in to change notification settings - Fork 3
Examples
Stefan Giermair edited this page Mar 3, 2013
·
11 revisions
###Content:
- [Create /etc/network/interfaces out of a csv-file](#Create /etc/network/interfaces out of a csv-file)
- [Create an index.html from a folder and add the folder content as links](#Create an index.html from a folder and add the folder content as links)
###Create /etc/network/interfaces out of a csv-file
####CSV-file content (test.csv):
eth0;10.1.0.10;255.255.0.0;10.1.0.1
eth1;192.168.0.10; 255.255.255.0;192.168.0.1
####Template (interfaces.tpl):
#% IFS=';'
#% while read "Val1" "Val2" "Val3" "Val4"; do
auto $Val1
iface $Val1 inet static
address $Val2
netmask $Val3
gateway $Val4
#% done < "$CSVFILE"
####Command:
$ CSVFILE=test.csv sh -c "$( shtpl interfaces.tpl )"
####Result:
auto eth0
iface eth0 inet static
address 10.1.0.10
netmask 255.255.0.0
gateway 10.1.0.1
auto eth1
iface eth1 inet static
address 192.168.0.10
netmask 255.255.255.0
gateway 192.168.0.1
###Create an index.html from a folder and add the folder content as links
####Template (index.html.tpl): <title>Directory listing for /$FOLDER/</title>
-
#% find "$FOLDER"/* | while read 'LINE'; do
#% TEXT="$( printf "%s" "$LINE" | sed s#"$FOLDER"/## )"
- $TEXT #% done
Note: This is not a safe approach to list the content of a folder. Newlines in file/folder names are going to break it. ####Command: $ FOLDER=myfolder sh -c "$( shtpl index.html.tpl )