LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   How to set variables to a non-login account used by a service in CentOS? (https://www.linuxquestions.org/questions/linux-server-73/how-to-set-variables-to-a-non-login-account-used-by-a-service-in-centos-4175624093/)

pjbarberoiglesias 02-20-2018 09:17 AM

How to set variables to a non-login account used by a service in CentOS?
 
Hi there,

I would like to know what is the correct way to define and initialize variables to a non-login account (/usr/bin/false) that run a service on its behalf.

Regards.

MensaWater 02-20-2018 10:53 AM

Put it in a wrapper script that calls the service.

e.g. If you run a command to start a service named "myservice" but want to set variable called OUTPUTDIR you'd create a simple script that does it:Z

Code:

!/bin/bash

export OUTPUTDIR=<value>

myservice

Alternatively if this is a cron job you could just create the script with the above export and call it before the service in crontab:

Script "myenv.sh"
Code:

!/bin/bash

export OUTPUTDIR=<value>

cron entry (in the crontab of the user you want this run as):
Code:

* * * * *  . /<pathto>/myenv.sh ; /<pathto>/myservice
Note that the cron entry "sources" myenv.sh rather than simply executing it.


All times are GMT -5. The time now is 11:04 PM.