Skip to content
zstegi edited this page Oct 22, 2012 · 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 (here 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 (here 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 "$( tinytpl 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>

Directory listing for /$FOLDER/


    #% find $FOLDER/* | while read 'LINE'; do #% TEXT="$( printf "%s" "$LINE" | sed s#$FOLDER/## )"
  • $TEXT #% done

####Command: $ FOLDER=myfolder sh -c "$( tinytpl index.html.tpl )
Clone this wiki locally