The requirement was to get a list of all users connected to a particular swmfs server and notify them that the server was about to go down.
I discovered that the FOR command is just what the doctor ordered for this task. The basic form is as follows...
FOR /F "skip=5 delims=@" %%i IN ('swmfs_list -full \\%COMPUTERNAME%\sw400\product\data message.ds') DO net send %%i Smallworld server going down in 2 minutes.
Where...
- FOR /F ... IN ...
- Command key words that tell the system that you want to iteratively process the results of some file or command
- ('swmfs_list -full \\%COMPUTERNAME%\sw400\product\data message.ds')
- the command that will have each line processed individually for some information. This particular command provides a list of all the user@computername that are connected to message.ds in the specified folder on %COMPUTERNAME%
- %%i
- the internal variable representing each line of the file/command
- "skip=5 delims=@"
- instructions to the command to skip the first 5 lines of swmfs_list and then also split the processed lines by the @ character.
- DO
- a command key word that indicates that what follows next is the command to be processed on each line of iterator
- net send %%i Smallworld server going down in 2 minutes.
- the NET SEND command is used to send the message "Smallworld server going down in 2 minutes" to the user specified in variable %%i. Remember that the variable %%i represents the first element of each line after it has been split by the @ character.
3 comments:
Nice script, Alfred. Should come in handy! Thanks!
Nice.. script is there a Magik equavalent method to get connected users and add them to a rope??
_block
# returns all the users currently connected to
# c:\smallworld41\product\data\message.ds
#
# modify as required
_local str << system.input_from_command({"swmfs_list","-full","c:\smallworld41\product\data","message.ds"})
_local a_line
_local users << equality_set.new()
_loop
_if (a_line << str.get_line()) _is _unset
_then
_leave
_endif
# we are only interested in the lines that have @ in them
# because those are the ones that indicate user information.
_if a_line.index_of(%@) _isnt _unset
_then
# if we are on a user line, then take the string up to the
# first space_char as the user ID.
users.add(a_line.split_by(space_char).first)
_endif
_endloop
# show results
print(users)
_endblock
$
Post a Comment