It is quite possible to take safe mode in remote scripts, this little chunk of python (similar constructs are possable in other languages, of course) is what I use:
def lock(self, take):
tries = 0
success = -1
modes = [["] > "], ["] <SAFE> "]]
try:
self.refreshconnection()
while success != 0:
if tries >= 30:
raise error("Locking failed")
tries = tries + 1
self.connection.write("\x18\n")
success = self.connection.expect(modes[take], 1)[0]
except:
raise error("Locking failed")
The important part is this: self.connection.write("\x18\n")
Particularly, the \x18\n bit.
The \x18 sends a literal ^x, and the \n sends a newline which generates a fresh prompt.
Very useful for preventing multiple asynchronous scripts from colliding, and leaving the router in an indeterminate state (and preventing the script from locking itself, and you, out of the router). It can be used just like a thread lock, and could even be abstracted further to create semaphores and such.
--Eric