$query will need to be adjusted to enable you to separate staff from students and the role_assign at the end of the script will need adjusting to match the category or course that you want it to update... You can then add this as a cron script to run every 10 minutes or so...
// script to automatically add users to a course or a category in Moodle 1.9
// edited to be run from outside of the web root...
// Jon Witts 21 May 2009 - edited 2 July 2009
$ids = array();
mysql_connect($CFG->dbhost, $CFG->dbuser, $CFG->dbpass);
$query = 'SELECT * FROM `vle154_user` WHERE `email` LIKE "%shunsley.eril.net" and 'email' not like "0%";
$res = mysql_query($query);
while(list($userid) = mysql_fetch_row($res))
$ids = $userid;
//echo '<h2>Processing UserIDs</h2>';
foreach($ids as $uid)
//student roleid 5, staff category context is 53...
//role_assign($roleid, $userid, $groupid, $contextid, $timestart=0, $timeend$
role_assign('5', $uid, '0', '53');