Perhaps you have found yourself in the middle of planning a large maintenance that involves many servers and many clients and all of the work is the same and you noticed that you don’t want to write a change control document for each client or each server.
Well, here’s some code that will write one for you. Just fill in your array of clients/hosts and then the content of the change control document – then run the file with PHP and you’ll have your change control docs all ready to go.
Note that all blank lines have been removed because wordpress’ code tag sucks and breaks on empty lines in code
function write_cr($content,$client,$hostname,$today) {
$FULLPATH="/tmp";
$filename=("$FULLPATH/cr/$client.$hostname.$today.txt");
if (!file_exists("$filename")) { touch("$filename");}
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
else {
if (fwrite($handle, $content) === FALSE) {
echo "Cannot write to file [$filename]";
exit;
}
}
fclose($handle);
}
else {
echo "The file [$filename] is not writable.";
}
}
function crfile($client,$hostname,$today) {
$contents="
CHANGE CONTROL DOCUMENT FOR: $client-$hostname-$today
Date: $today
Name: $client
Phone:
Email:
Downtime Required:
Summary of Changes:
Reason for change:
Testing done prior to change:
Reveral plan:
Triggers for reversal:
Reversal plan time requirement:
Test Plan:
Who will test the changes:
Who will sign off on the changes:
";
write_cr($contents,$client,$hostname,$today);
}
$today = date('d');
$list = array(
"client1" => "hostname1",
"client2" => "hostname2");
foreach($list as $k => $v) {
$client = $k;
$hostname = $v;
crfile($client,$hostname,$today);
}
?>