M
M
Maxim2014-08-22 17:53:50
linux
Maxim, 2014-08-22 17:53:50

Is it possible to find out in a bash script how it was launched?

For example, through cron or manually from the terminal.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
RPG, 2014-08-22
@maxpointn2point

The most reliable way is to set an environment variable in the crontab, and read this environment variable in the script, but you need to change the crontab:

CRON_MODE=1
* * * * * env > ~/env

The env file will include:
SHELL=/usr/bin/sh
USER=rpg
PATH=/usr/bin:/bin
PWD=/home/rpg
SHLVL=1
HOME=/home/rpg
CRON_MODE=1
LOGNAME=rpg
_=/usr/bin/env

www.stackoverflow.com/a/3215128

D
Dmitry, 2014-08-22
@TrueBers

Has Google gone down?

I
Igor, 2014-08-22
@merryjane

If only to try to use the $PPID variable.
But it didn't show my crontab. Only sh, as the interpreter that launched the cron.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question