Page 1 of 1
Daily scripting task for removing inactive users
Posted: Mon Oct 19, 2009 1:11 pm
by FTP
-- Description: Daily scripting task for removing inactive users that have not logged in within 15 days
-- Author: Luke
-- Date: 2009-10-12
Code: Select all
do
--Get user list from domain "demo"
local strUserlist = c_GetUserList("demo")
local userlist = Split(strUserlist,"\n")
for _,username in pairs(userlist) do
local user = c_GetUser("demo",username)
local logintime = user.last_logintime
--get last login time, formatted as time_t
local logintime_t = c_TranslateTime(logintime)
if (os.time() - logintime_t) >= 3600*24*15 then
c_DeleteUser("demo",username)
end
end
end
You may add a hourly task and input the above lua script.
Re: Daily scheduler task for removing inactive users
Posted: Tue Jul 12, 2016 9:22 am
by thomas.mccall
Hello,
Could you explain how to modify this example so that inactive accounts are disabled not deleted?
Thanks!
Re: Daily scheduler task for removing inactive users
Posted: Sat Jul 16, 2016 6:49 am
by FTP
thomas.mccall wrote:Hello,
Could you explain how to modify this example so that inactive accounts are disabled not deleted?
Thanks!
You just need to replace the following line:
into:
Code: Select all
for k,v in pairs(user) do
if type(v) == "boolean" then
if v == true then
user[k] = 1
else
user[k] = 0
end
end
end
user.enable_account = 0
user.oldpassword = user.password
AddUser("demo", user)
Re: Daily scheduler task for removing inactive users
Posted: Wed Jul 20, 2016 11:09 am
by thomas.mccall
Probably I done something wrong with the code but when I try to enter it into the task editor it rejects it saying:
attempt to call local 'type' (a string value)!
Code: Select all
do
--Get user list from domain "CBUK"
local strUserlist = c_GetUserList("CBUK")
local userlist = Split(strUserlist,"\n")
for _,username in pairs(userlist) do
local user = c_GetUser("CBUK",username)
local logintime = user.last_logintime
--get last login time, formatted as time_t
local logintime_t = c_TranslateTime(logintime)
if (os.time() - logintime_t) >= 3600*24*15 then
for k,v in pairs(user) do
if type(v) == "boolean" then
if v == true then
user[k] = 1
else
user[k] = 0
end
end
end
user.enable_account = 0
user.oldpassword = user.password
AddUser("CBUK", user)
end
Re: Daily scheduler task for removing inactive users
Posted: Wed Jul 20, 2016 3:26 pm
by FTP
Already told you very clearly, just replace one line. OK, paste the full code here:
Code: Select all
do
--Get user list from domain "demo"
local strUserlist = c_GetUserList("demo")
local userlist = Split(strUserlist,"\n")
for _,username in pairs(userlist) do
local user = c_GetUser("demo",username)
local logintime = user.last_logintime
--get last login time, formatted as time_t
local logintime_t = c_TranslateTime(logintime)
if (os.time() - logintime_t) >= 3600*24*15 then
for k,v in pairs(user) do
if type(v) == "boolean" then
if v == true then
user[k] = 1
else
user[k] = 0
end
end
end
user.enable_account = 0
user.oldpassword = user.password
AddUser("demo", user)
end
end
end