Is this for a SP module, a MP server, or just to see if it can be done?
If it's one of the latter two, the answer is likely to try the NWNX function for altering known spells, either off the standard server add on or NWNCX. The function to try would be:
void NWNXFuncs_AddKnownSpell(object oCreature, int iclass, int iSpellLevel, int iSpell, int iCharacterLevel=0)
It's in NWNX_FUNCS in the windows version, not sure if it's in a same named one for linux.