L
L
larrabee2014-04-19 22:20:18
linux
larrabee, 2014-04-19 22:20:18

Determine whether the user has run a script?

Hello.
There is Arch Linux (it is desirable that it would work on all distros) and there is a python script.
It is required to determine whether the script is running from the user shell (from under the root) or by the cron (the cron is also root). Are there any differences in the environment that can help solve this problem?
Thank you.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
J
Jedi_PHP, 2014-04-21
@larrabee

https://docs.python.org/2/library/getpass.html

import getpass
current_user = getpass.getuser()

But for security purposes, this cannot be used, because. environment variables are checked, which are easy to fake.

R
Rpsl, 2014-04-19
@Rpsl

Write a cron script with a parameter and check for the presence of the parameter.

A
Alexey Lesovsky, 2014-04-20
@lesovsky

Hello.
>> It is required to define the script is started from...
Who needs to define? the script itself must determine how it is launched, or should it be determined by some other left script??
One way or another, scripts run from a logged in user and cron will differ in the set of environment variables, so try using them, for example SHLVL (variables are stored in /proc/$$/environ).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question