Lighthouse Script Templates are a powerful way to run shell scripts on nodes, either automatically at enrollment time via Configure Nodes -> Node Enrollment -> Enrollment Bundles, or manually via Configure Nodes -> Configuration Templates -> Apply Templates.
Advanced users may have custom scripts that they wish to not just run, but install on individual nodes – e.g. to automate maintenance tasks. Furthermore, it may be desirable to have these scripts run regularly via cron.
These users may create and upload a Script Template that pushes a "self-installing" script to the node, as shown below. The parts of the script that are installed on the node are shown in bold.
Note: Some text editors will create corrupt script files, particularly in Windows environments. Use the freely available Notepad++ which allows you to save the script with Unix (LF) line endings, not DOS (CRLF) line endings. Ensure any 'single' and "double" quotation marks have not been converted into curly “smart quotes”.
#!/bin/bash # # Install example script and nightly cronjob # target_script=example.sh # # Write out example script to node # mkdir -p /etc/config/scripts cat << 'EOF' > "/etc/config/scripts/$target_script" #!/bin/bash me=$(basename $0) echo "Example script ran successfully at $(date)" > "/tmp/$me.log" EOF # # Optional: install cronjob to run nightly at 1am # ( crontab -l | grep -v "$target_script" echo "0 1 * * * bash /etc/config/scripts/$target_script" ) | crontab -
Note: To have custom scripts run automatically in response to remote events rather than regularly via cron, use config commands to configure Auto-Response on the node. This may also be centrally orchestrated from Lighthouse using the Script Template or ad hoc using node-command.