Ok I am trying to read the contents of a file (servers) and create a new file off of it with more information line by line. You will see the logic soon. I know how to do this via a script but not php. The end result is servers2 should have (ssh root@$count 'echo $user|passwd --stdin root' ; done). The variable $count is the list of servers in the (servers) file, so it will have the line above for each server name.
<?php
$counterFile='servers';
file_exists($counterFile) ? $count=trim(implode('',file($counterFile))) :
$count++;
//echo "$count ";
//Make script to excute password reset
$filename = ("/usr/local/apache/htdocs/linuxadmin/servers2");
$somecontent = "ssh root@$count 'echo password|passwd --stdin user' ; done\n";
// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {
// In our example we're opening $filename in write mode 'w' or append mode 'a'.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
if (!$handle = fopen($filename, 'w')) {
echo "Cannot open file ($filename)";
exit;
}
// Write $somecontent to our opened file.
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
// echo "Success, wrote ($somecontent) to file ($filename)";
fclose($handle);
} else {
echo "The file $filename is not writable";
}
?>