User tasks in ~/.logout

Polytropon freebsd at edvax.de
Tue Oct 11 14:39:20 UTC 2011


On Tue, 11 Oct 2011 10:27:13 -0400 (EDT), Daniel Feenberg wrote:
> 
> 
> On Tue, 11 Oct 2011, Polytropon wrote:
> 
> > I have some users who I want to "schedule" a specific job
> > for which gets executed on their user account. For some
> > of them, it will be twice a day, for others just once a
> > month. It should happen at logout time.
> >
> > The intended mechanism to do so is ~/.logout, the C shell's
> > logout script.
> >
> 
> If the user doesn't want to wait for the script to complete for the
> session to end, you could start the script with a call to "batch" or "at".

Ah thanks, good idea! And concluded: Why not use detach?
It's a program that allows to run programs "detached" from
a controlling terminal - the thing that disappears at logout
time. :-)

Oh, and even the OS brings such a tool - "daemon", just found
its manpage.

I will compare both and see. Thanks, your inspiration seems
to do the trick.

Still, completition time should be minimal (less than 10 seconds
I think), so it wouldn't be _that_ complicated. The only thing
is to educate users to _properly_ close the connection so
I don't end up with "stale connections", e. g. in "top" or "w"
output, login shells running with nobody at the other end.



> The shell documentation claims that .logout executes whenever the shell
> exits, so your script should execute even if the user neglects to properly 
> log out, however I haven't experimented with that.

Maybe it's also good to make a timeout setting for that
shell, e. g. inactivity for 30 minutes causes connection
to be closed properly, including a "valid" shell exit.

Situations like "the shell never exists" or "the shell exits
accidentally when the user logs in for the next time" would
be unpleasant.



> Are you sure you wouldn't be better off with a cron job? Is it that you 
> don't want the script running while the user is logged in?

Yes, this is _one_ aspect. The other one is to create
things like backup sets depending on user interactivity.
For those who do two sessions per day, have two backup
files per day. For those only doing one session per
month, only this backup set will be used. This means
that every "session state" (last one, the one of yesterday,
the one of last month) can be restored.

Typical scenario... okay, I don't know if it's typical,
but a good example: User logs in, enters data. Fine.
Logs in later again, deletes data. Night comes, backup
runs. Next day: "I need my data of yesterday morning,
where is it?"



-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...


More information about the freebsd-questions mailing list