Billfaith:
> Do your batch files log off people by length of time logged into the
> database? Is it similar to what JJ wrote above?
The ones I was using didn't go by length of time logged on, but this one does.
It is written in javascript, which I don't know particularly well, so there are bound to be ways to make it better. You run it with cscript on windows, preferably with a batchfile rdirecting output to a textfile.
It worked like a dream ealier, especially when I used the live output batch file, so it logged live users off
Just copy the javascript below into text editor, notepad will do, and save it off as killuser.js, or whatever you want.
Please let me know if you have any problems with it.
I ran it with a batch file that went something like this:
@echo off
if exist %2%1del.bat del %2%1del.bat
cscript //nologo line.js %1 %2 > %2%1del.log
if exist %2%1del.bat more %2%1del.bat
and you call it as:
killuser.bat mydb s:\db
where mydb is the database name and s:\db is a shared directory that the checkdel.bat script looks at.
I'll tell you one thing - Javascript is a lot fiddlier than Progress, and less readable, and nastier. But, this will work even if you can't compile/run Progress programs.
I hope that helps.
Simon
////////////////////////////////////////////////////////////////////////////////
// killuser.js
//
// This script takes parameters for the database name and working directory
// It then inputs and parses a textfile to find out which users are logged on and how long they have been logged on
// Finally, it creates a batch file containing instructions on deleting users more than 5 hours old
// Copyright (c) Simon Phipp 2005
//
// Usage cscript //nologo killuser.js dbname workingdirectory
//
// As it uses stdout, you have to use cscript
// You could change it to use wscript.echo if you wanted to
//
// Warning - this does not check for permissions, or to see what processes the person is running
// Care should be taken when using this as it will log anyone off who has been logged on for 5 hours
//
////////////////////////////////////////////////////////////////////////////////
var stdout = WScript.StdOut;
var stdin = WScript.StdIn;
var lineno;
var usrinfo = new Array ();
var usrline = new Array ();
var usrcol = new Array ();
var usrdate = new Array ();
var usrno = new Array ();
var usrtime = new Array ();
var usrdiff = new Array ();
var key;
var fso;
var textfile;
var MinMilli = 1000 * 60;
var HrMilli = MinMilli * 60;
var DyMilli = HrMilli * 24;
var ForAppending = 8;
var ForWriting = 2;
var ForReading = 1;
var firsttime;
var objargs;
var i;
objArgs = WScript.Arguments;
var dbname, inputdir, inputfile, batchfile, killbatch;
// Get the starting parameters - warning - if 2 parameters are not apssed, this will error and stop
dbname = "";
dbname = objArgs (0);
inputdir = objArgs (1);
inputfile = inputdir.concat (dbname,"list.txt");
batchfile = inputdir.concat (dbname,"del.bat");
killbatch = "call f:\\db\\scripts\\";
killbatch = killbatch.concat (dbname,"del");
// Write some info to the standard output
stdout.write("Checking Users for Database: ");
stdout.writeline(dbname);
stdout.write("Input File: ");
stdout.writeline(inputfile);
stdout.write("Batch File: ");
stdout.writeline(batchfile);
// Get the starting time - to use as a reference time
firsttime = GetCurrentTime();
lineno = 0;
ReadFiles(inputfile);
WriteResults ();
function ReadFiles(inp_file)
{
var colno;
// Write info to the standard output
stdout.write("Checking File: ");
stdout.WriteLine(inp_file);
fso = new ActiveXObject("Scripting.FileSystemObject");
textfile = fs
penTextFile(inp_file, ForReading);
while (!textfile.AtEndOfStream)
{
// Read a line form the textfile to an array variable
lineno++;
usrinfo [lineno] = textfile.ReadLine();
// Split the read-in line into space-delimited fields, parse the fields, ignoring blanks and "-"
colno = 0;
usrline[lineno] = usrinfo[lineno].split (" ");
usrcol[lineno] = new Array ();
for (key in usrline[lineno]) {
if (!(usrline[lineno] [key] == "") && !(usrline[lineno] [key] == "-")) {
colno++;
usrcol[lineno][colno] = usrline[lineno] [key];
}
}
// Build up the date/time from the correct fields
usrdate[lineno] = " ";
usrdate[lineno] = usrdate [lineno].concat (usrcol[lineno][5]," ",usrcol[lineno][4]," ",usrcol[lineno][7]," ",usrcol[lineno][6]);
usrno[lineno] = usrcol[lineno][1];
// Work out the number of hours between the log-on time and the time set earlier
usrdiff[lineno] = NumHours (firsttime - GetOtherTime(usrdate[lineno]));
}
textfile.Close();
}
function GetCurrentTime(){
var d, t;
d = new Date();
t = d.getTime();
return(t);
}
function GetOtherTime(inp_date){
var d, t;
d = new Date(inp_date);
t = d.getTime();
return(t);
}
function NumHours(inp_num){
var h;
h = Math.round (inp_num / HrMilli);
return(h);
}
function WriteResults () {
var dbaction;
fso = new ActiveXObject("Scripting.FileSystemObject");
textfile = fs
penTextFile(batchfile, ForWriting, true);
textfile.writeline ("@echo off");
// Write all read-in lines as a reference
for (key = 1; key <= lineno; key++) {
stdout.writeline (usrinfo[key]);
}
stdout.writeline ("");
stdout.writeline ("");
// Decide whether to ignore, keep or kill users, writing the results to the standard output
for (key = 1; key <= lineno; key++) {
dbaction = "Keep ";
if (usrno[key] == "PROGRESS" || usrno[key] == "usr")
dbaction = "Ignore ";
if (usrdiff [key] > 5) {
dbaction = "Kill ";
// textfile.Write("call f:\\db\\scripts\\sapdel ");
textfile.Write(killbatch);
textfile.Write(" ");
textfile.WriteLine(usrno[key]);
}
stdout.write (dbaction);
stdout.write (usrno[key]);
stdout.write (" ");
stdout.writeline (usrinfo[key]);
}
textfile.Close();
}
////////////////////////////////////////////////////////////////////////////////