hi there !
I have a question regarding creating environment variables using a sh-script wich is started in a created service.
the environment variables are AAAA,BBBB.... FFFF
servicen-name: testserv2
sh-script-file: test2.sh
the service is starting well and also the script is starting well.
here is the code from the sh-script:
#!/bin/bash
echo "casdasdasdad"
export AAAA=aaa
export BBBB=bbb
export CCCC=ccc
export DDDD=ddd
export EEEE=eeee
export FFFF=ffff
dt=$(date)
echo "$dt"
echo "$dt">>testtime
if i run this sh-script "manually" with the command
"source test2.sh"
the environment variables are created fine and i can just see there values:
debian@A12PJX:/etc/systemd/system$ echo $AAAA
aaa
If the service is starting the sh-script, it also runs well (i can see the running time in the file "testtime" (last line in the SH-File)
but... the environment variables are not created
here my service-file:
Description=MY Script
[Service]
Type=oneshot
ExecStart=/bin/sh -c '/home/debian/test2.sh'
User=debian
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
i think the reason is the execStart :
ExecStart=/bin/sh -c '/home/debian/test2.sh'
i tried it without /bin/sh -c ... it also didnt work..
so my question:
Who can i set env. variables by running a sh-script which is started by a service ?
Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230
services - creating environment variables
- Head_on_a_Stick
- Posts: 14114
- Joined: 2014-06-01 17:46
- Location: London, England
- Has thanked: 81 times
- Been thanked: 133 times
Re: services - creating environment variables
Why do you want to create these variables and where do you want them to be applied? Please explain what it is you are actually trying to do so we can avoid an XY Problem.
The service will be run in a subshell and so any environmental variables will only apply for that subshell.
The service will be run in a subshell and so any environmental variables will only apply for that subshell.
deadbang
-
- Global Moderator
- Posts: 2979
- Joined: 2014-07-20 18:12
- Location: Europe
- Has thanked: 75 times
- Been thanked: 407 times
Re: services - creating environment variables
Discussion moved from:
- "System and Network configuration " sub-forum
- "Programming" sub-forum