create_system_profiles.sh 894 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/bin/bash
  2. if [ $# -lt 1 ] ; then
  3. echo -e "\nNeed mapping file\n"
  4. echo -e "e.g. $(basename $0) mapping.csv\n"
  5. exit 1
  6. fi
  7. MAPPING=$1
  8. if [ ! -e $MAPPING ] ; then
  9. echo -e "\nMapping file $MAPPING does not exist\n"
  10. exit 1
  11. fi
  12. if [ ! -d profiles ] ; then
  13. mkdir profiles
  14. fi
  15. echo -e "#!/bin/bash\n" > profiles/addall.sh
  16. for profile in $(cat $MAPPING | grep -v ^MAC) ; do
  17. MAC=$(echo $profile | cut -d "," -f 1 )
  18. HOSTNAME=$(echo $profile | cut -d "," -f 2 )
  19. IPADDR=$(echo $profile | cut -d "," -f 3 )
  20. OUTFILE=${HOSTNAME}.sh
  21. cat template.sh \
  22. | sed -e "s/^HOSTNAME=/HOSTNAME=\"$HOSTNAME\"/" \
  23. -e "s/^IPADDR=/IPADDR=\"$IPADDR\"/" \
  24. -e "s/^MAC=/MAC=\"$MAC\"/" > profiles/$OUTFILE
  25. echo "./$OUTFILE" >> profiles/addall.sh
  26. chmod 755 profiles/$OUTFILE
  27. done
  28. echo -e "\ncobbler sync\n" >> profiles/addall.sh
  29. chmod 755 profiles/addall.sh