580 Part IV: Using PHP for Sysadmin Tasks (Web server certificate)
Sunday, March 23rd, 2008580 Part IV: Using PHP for Sysadmin Tasks Listing 16-8 (Continued) foreach ($entries as $logRecord) { fputs($logFD, $today: $logRecordn ); } fclose($logFD); return TRUE; } function getUsers($userFile = null) { $users = array(); if (!file_exists($userFile)) { return $users; } // For each line in the file // create a entry in users array // as: $users[username] = home_dir foreach ( file($userFile) as $line) { $userInfo = explode( : ,$line); $users[$userInfo[0]] = $userInfo[5]; } return $users; } ?> Here is how this script works: . It first gets a list of users by calling the getUsers() function. This function is given the PASSWD_FILE file name, which is configured in reminder.conf. The user list is returned into $userList. . For each user in $userList, the script calls the doRemind() function, which processes the reminders for the user. Now let s examine each of the functions used in this script.