(SAT) Demo Application - updatethost |
Source Code |
#!/usr/bin/ksh #====================# # SCRIPT: updatehost # #====================# { mysql -v -v demo 2>&1 << !SQL update host set os = '${6}', processors = '${7}', speed_mhz = '${8}', memory_mb = '${9}', ip_address = '${10}', updated = updated+1 where host = '${4}' and updated = '${5}'; select 'satmysql silent'; select updated from host where host='${4}'; !SQL } | satmysql Host && echo "setMessage {\"Host Updated\"}"
Comments |
This script updates a host entry in the demo database.
Called by: displayhost
{ mysql -v -v demo 2>&1 << !SQLThe mysql command is used to access the demo database. The verbosity of mysql is set to -v -v. All output is directed to standard output so that it will be seen by satmysql. SQL satements are read until !SQL.
update host set os = '${6}', processors = '${7}', speed_mhz = '${8}', memory_mb = '${9}', ip_address = '${10}', updated = updated+1 where host = '${4}' and updated = '${5}';The host entry in the demo database is updated. The update will only take place if the value of the updated column is the same as it was when the host data was read. As the updated column is incremented each time the host is updated, this ensures that the update will not be written if the host information has been updated since it was read by the user attempting the update.
select 'satmysql silent';When the updated value is selected no messages are to be generated (silent).
select updated from host where host='${4}';The new value of the updated column is read. This allows another update to be performed if required.
!SQL } | satmysql Host && echo "setMessage {\"Host Updated\"}"The output from the mysql command is piped to satmysql. If the update is successful a "Host Updated" message is displayed. Any error messages generated by the SQL will be trapped and labeled with Host. For example: If the update satement is unable to update the host, satmysql will generate an "Unable to Update Host" message.