How to make the command in /etc/profile be found? [duplicate]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite













This question already has an answer here:



  • Difference between Login Shell and Non-Login Shell?

    4 answers



Os: debian9.



touch /home/test/test.log


There is a simple function write-date in /etc/profile.



write-date()
date >> /home/test/test.log



Create a service running at reboot or shutdown.



vim /etc/systemd/system/test.service 

[Unit]
Description=Run command at shutdown
Before=shutdown.target reboot.target

[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/bin/bash /home/test/test.sh

[Install]
WantedBy=multi-user.target


The simple function write-date in /home/test/test.sh.



vim /home/test/test.sh
write-date


Enable the test.service.



sudo systemctl enable test.service


Reboot my pc and check log of test.service



sudo journalctl -u test
-- Logs begin at Thu 2018-02-01 00:03:59 HKT, end at Thu 2018-02-01 00:15:54 HKT. --
Feb 01 00:04:04 test systemd[1]: Starting Run command at shutdown...
Feb 01 00:04:05 test bash[438]: /home/test/test.sh: line 3: write-date: command not found
Feb 01 00:04:11 test systemd[1]: test.service: Main process exited, code=exited, status=127/n/a
Feb 01 00:04:11 test systemd[1]: Failed to start Run command at shutdown.
Feb 01 00:04:11 test systemd[1]: test.service: Unit entered failed state.
Feb 01 00:04:11 test systemd[1]: test.service: Failed with result 'exit-code'.


How to make the command in /etc/profile be found ?



cat -vet /home/test/test.sh
$
$
write-date$
$
$






share|improve this question














marked as duplicate by muru, G-Man, cas, Community♦ Feb 1 at 14:17


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • From what you show, you have the function defined but never invoked.
    – DopeGhoti
    Jan 31 at 16:39










  • @DopeGhoti That doesn't really explain the "command not found". However, I wonder if /home still exists at the point when the service is invoked? I don't know much about systemd, but /home might be unmounted at shutdown and reboot on some systems, I presume?
    – Kusalananda
    Jan 31 at 16:43







  • 3




    There's two function definitions for write-date, one in /home/test/test.sh and one in /etc/profile, and as DopeGhoti said, you don't appear to be calling it. Also, /etc/profile is only (automatically) read for login shells, which a systemd-invoked script would not be.
    – Jeff Schaller
    Jan 31 at 16:52










  • Two blank lines on the top.
    – scrapy
    Feb 1 at 2:37










  • The content you showed with vim /home/test/test.sh and the one with cat are completely different,
    – muru
    Feb 1 at 2:41














up vote
0
down vote

favorite













This question already has an answer here:



  • Difference between Login Shell and Non-Login Shell?

    4 answers



Os: debian9.



touch /home/test/test.log


There is a simple function write-date in /etc/profile.



write-date()
date >> /home/test/test.log



Create a service running at reboot or shutdown.



vim /etc/systemd/system/test.service 

[Unit]
Description=Run command at shutdown
Before=shutdown.target reboot.target

[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/bin/bash /home/test/test.sh

[Install]
WantedBy=multi-user.target


The simple function write-date in /home/test/test.sh.



vim /home/test/test.sh
write-date


Enable the test.service.



sudo systemctl enable test.service


Reboot my pc and check log of test.service



sudo journalctl -u test
-- Logs begin at Thu 2018-02-01 00:03:59 HKT, end at Thu 2018-02-01 00:15:54 HKT. --
Feb 01 00:04:04 test systemd[1]: Starting Run command at shutdown...
Feb 01 00:04:05 test bash[438]: /home/test/test.sh: line 3: write-date: command not found
Feb 01 00:04:11 test systemd[1]: test.service: Main process exited, code=exited, status=127/n/a
Feb 01 00:04:11 test systemd[1]: Failed to start Run command at shutdown.
Feb 01 00:04:11 test systemd[1]: test.service: Unit entered failed state.
Feb 01 00:04:11 test systemd[1]: test.service: Failed with result 'exit-code'.


How to make the command in /etc/profile be found ?



cat -vet /home/test/test.sh
$
$
write-date$
$
$






share|improve this question














marked as duplicate by muru, G-Man, cas, Community♦ Feb 1 at 14:17


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • From what you show, you have the function defined but never invoked.
    – DopeGhoti
    Jan 31 at 16:39










  • @DopeGhoti That doesn't really explain the "command not found". However, I wonder if /home still exists at the point when the service is invoked? I don't know much about systemd, but /home might be unmounted at shutdown and reboot on some systems, I presume?
    – Kusalananda
    Jan 31 at 16:43







  • 3




    There's two function definitions for write-date, one in /home/test/test.sh and one in /etc/profile, and as DopeGhoti said, you don't appear to be calling it. Also, /etc/profile is only (automatically) read for login shells, which a systemd-invoked script would not be.
    – Jeff Schaller
    Jan 31 at 16:52










  • Two blank lines on the top.
    – scrapy
    Feb 1 at 2:37










  • The content you showed with vim /home/test/test.sh and the one with cat are completely different,
    – muru
    Feb 1 at 2:41












up vote
0
down vote

favorite









up vote
0
down vote

favorite












This question already has an answer here:



  • Difference between Login Shell and Non-Login Shell?

    4 answers



Os: debian9.



touch /home/test/test.log


There is a simple function write-date in /etc/profile.



write-date()
date >> /home/test/test.log



Create a service running at reboot or shutdown.



vim /etc/systemd/system/test.service 

[Unit]
Description=Run command at shutdown
Before=shutdown.target reboot.target

[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/bin/bash /home/test/test.sh

[Install]
WantedBy=multi-user.target


The simple function write-date in /home/test/test.sh.



vim /home/test/test.sh
write-date


Enable the test.service.



sudo systemctl enable test.service


Reboot my pc and check log of test.service



sudo journalctl -u test
-- Logs begin at Thu 2018-02-01 00:03:59 HKT, end at Thu 2018-02-01 00:15:54 HKT. --
Feb 01 00:04:04 test systemd[1]: Starting Run command at shutdown...
Feb 01 00:04:05 test bash[438]: /home/test/test.sh: line 3: write-date: command not found
Feb 01 00:04:11 test systemd[1]: test.service: Main process exited, code=exited, status=127/n/a
Feb 01 00:04:11 test systemd[1]: Failed to start Run command at shutdown.
Feb 01 00:04:11 test systemd[1]: test.service: Unit entered failed state.
Feb 01 00:04:11 test systemd[1]: test.service: Failed with result 'exit-code'.


How to make the command in /etc/profile be found ?



cat -vet /home/test/test.sh
$
$
write-date$
$
$






share|improve this question















This question already has an answer here:



  • Difference between Login Shell and Non-Login Shell?

    4 answers



Os: debian9.



touch /home/test/test.log


There is a simple function write-date in /etc/profile.



write-date()
date >> /home/test/test.log



Create a service running at reboot or shutdown.



vim /etc/systemd/system/test.service 

[Unit]
Description=Run command at shutdown
Before=shutdown.target reboot.target

[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/bin/bash /home/test/test.sh

[Install]
WantedBy=multi-user.target


The simple function write-date in /home/test/test.sh.



vim /home/test/test.sh
write-date


Enable the test.service.



sudo systemctl enable test.service


Reboot my pc and check log of test.service



sudo journalctl -u test
-- Logs begin at Thu 2018-02-01 00:03:59 HKT, end at Thu 2018-02-01 00:15:54 HKT. --
Feb 01 00:04:04 test systemd[1]: Starting Run command at shutdown...
Feb 01 00:04:05 test bash[438]: /home/test/test.sh: line 3: write-date: command not found
Feb 01 00:04:11 test systemd[1]: test.service: Main process exited, code=exited, status=127/n/a
Feb 01 00:04:11 test systemd[1]: Failed to start Run command at shutdown.
Feb 01 00:04:11 test systemd[1]: test.service: Unit entered failed state.
Feb 01 00:04:11 test systemd[1]: test.service: Failed with result 'exit-code'.


How to make the command in /etc/profile be found ?



cat -vet /home/test/test.sh
$
$
write-date$
$
$




This question already has an answer here:



  • Difference between Login Shell and Non-Login Shell?

    4 answers









share|improve this question













share|improve this question




share|improve this question








edited Feb 1 at 2:41

























asked Jan 31 at 16:18









scrapy

317213




317213




marked as duplicate by muru, G-Man, cas, Community♦ Feb 1 at 14:17


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by muru, G-Man, cas, Community♦ Feb 1 at 14:17


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.













  • From what you show, you have the function defined but never invoked.
    – DopeGhoti
    Jan 31 at 16:39










  • @DopeGhoti That doesn't really explain the "command not found". However, I wonder if /home still exists at the point when the service is invoked? I don't know much about systemd, but /home might be unmounted at shutdown and reboot on some systems, I presume?
    – Kusalananda
    Jan 31 at 16:43







  • 3




    There's two function definitions for write-date, one in /home/test/test.sh and one in /etc/profile, and as DopeGhoti said, you don't appear to be calling it. Also, /etc/profile is only (automatically) read for login shells, which a systemd-invoked script would not be.
    – Jeff Schaller
    Jan 31 at 16:52










  • Two blank lines on the top.
    – scrapy
    Feb 1 at 2:37










  • The content you showed with vim /home/test/test.sh and the one with cat are completely different,
    – muru
    Feb 1 at 2:41
















  • From what you show, you have the function defined but never invoked.
    – DopeGhoti
    Jan 31 at 16:39










  • @DopeGhoti That doesn't really explain the "command not found". However, I wonder if /home still exists at the point when the service is invoked? I don't know much about systemd, but /home might be unmounted at shutdown and reboot on some systems, I presume?
    – Kusalananda
    Jan 31 at 16:43







  • 3




    There's two function definitions for write-date, one in /home/test/test.sh and one in /etc/profile, and as DopeGhoti said, you don't appear to be calling it. Also, /etc/profile is only (automatically) read for login shells, which a systemd-invoked script would not be.
    – Jeff Schaller
    Jan 31 at 16:52










  • Two blank lines on the top.
    – scrapy
    Feb 1 at 2:37










  • The content you showed with vim /home/test/test.sh and the one with cat are completely different,
    – muru
    Feb 1 at 2:41















From what you show, you have the function defined but never invoked.
– DopeGhoti
Jan 31 at 16:39




From what you show, you have the function defined but never invoked.
– DopeGhoti
Jan 31 at 16:39












@DopeGhoti That doesn't really explain the "command not found". However, I wonder if /home still exists at the point when the service is invoked? I don't know much about systemd, but /home might be unmounted at shutdown and reboot on some systems, I presume?
– Kusalananda
Jan 31 at 16:43





@DopeGhoti That doesn't really explain the "command not found". However, I wonder if /home still exists at the point when the service is invoked? I don't know much about systemd, but /home might be unmounted at shutdown and reboot on some systems, I presume?
– Kusalananda
Jan 31 at 16:43





3




3




There's two function definitions for write-date, one in /home/test/test.sh and one in /etc/profile, and as DopeGhoti said, you don't appear to be calling it. Also, /etc/profile is only (automatically) read for login shells, which a systemd-invoked script would not be.
– Jeff Schaller
Jan 31 at 16:52




There's two function definitions for write-date, one in /home/test/test.sh and one in /etc/profile, and as DopeGhoti said, you don't appear to be calling it. Also, /etc/profile is only (automatically) read for login shells, which a systemd-invoked script would not be.
– Jeff Schaller
Jan 31 at 16:52












Two blank lines on the top.
– scrapy
Feb 1 at 2:37




Two blank lines on the top.
– scrapy
Feb 1 at 2:37












The content you showed with vim /home/test/test.sh and the one with cat are completely different,
– muru
Feb 1 at 2:41




The content you showed with vim /home/test/test.sh and the one with cat are completely different,
– muru
Feb 1 at 2:41










1 Answer
1






active

oldest

votes

















up vote
0
down vote













You probably need to explicitly tell your service that it needs to source /etc/profile.



[Unit]
Description=Run command at shutdown
Before=shutdown.target reboot.target

[Service]
EnvironmentFile=-/etc/profile
Type=oneshot
RemainAfterExit=true
ExecStart=/bin/bash /home/test/test.sh

[Install]
WantedBy=multi-user.target


Note the EnvironmentFile line.






share|improve this answer




















  • What does =- means in EnvironmentFile=-/etc/profile? What does minus (-) means in =-?
    – scrapy
    Feb 1 at 2:58











  • It means: read the file if it's there, but continue to try to start up without it.
    – Tim Kennedy
    Feb 1 at 18:08

















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













You probably need to explicitly tell your service that it needs to source /etc/profile.



[Unit]
Description=Run command at shutdown
Before=shutdown.target reboot.target

[Service]
EnvironmentFile=-/etc/profile
Type=oneshot
RemainAfterExit=true
ExecStart=/bin/bash /home/test/test.sh

[Install]
WantedBy=multi-user.target


Note the EnvironmentFile line.






share|improve this answer




















  • What does =- means in EnvironmentFile=-/etc/profile? What does minus (-) means in =-?
    – scrapy
    Feb 1 at 2:58











  • It means: read the file if it's there, but continue to try to start up without it.
    – Tim Kennedy
    Feb 1 at 18:08














up vote
0
down vote













You probably need to explicitly tell your service that it needs to source /etc/profile.



[Unit]
Description=Run command at shutdown
Before=shutdown.target reboot.target

[Service]
EnvironmentFile=-/etc/profile
Type=oneshot
RemainAfterExit=true
ExecStart=/bin/bash /home/test/test.sh

[Install]
WantedBy=multi-user.target


Note the EnvironmentFile line.






share|improve this answer




















  • What does =- means in EnvironmentFile=-/etc/profile? What does minus (-) means in =-?
    – scrapy
    Feb 1 at 2:58











  • It means: read the file if it's there, but continue to try to start up without it.
    – Tim Kennedy
    Feb 1 at 18:08












up vote
0
down vote










up vote
0
down vote









You probably need to explicitly tell your service that it needs to source /etc/profile.



[Unit]
Description=Run command at shutdown
Before=shutdown.target reboot.target

[Service]
EnvironmentFile=-/etc/profile
Type=oneshot
RemainAfterExit=true
ExecStart=/bin/bash /home/test/test.sh

[Install]
WantedBy=multi-user.target


Note the EnvironmentFile line.






share|improve this answer












You probably need to explicitly tell your service that it needs to source /etc/profile.



[Unit]
Description=Run command at shutdown
Before=shutdown.target reboot.target

[Service]
EnvironmentFile=-/etc/profile
Type=oneshot
RemainAfterExit=true
ExecStart=/bin/bash /home/test/test.sh

[Install]
WantedBy=multi-user.target


Note the EnvironmentFile line.







share|improve this answer












share|improve this answer



share|improve this answer










answered Feb 1 at 2:54









Tim Kennedy

13.4k22949




13.4k22949











  • What does =- means in EnvironmentFile=-/etc/profile? What does minus (-) means in =-?
    – scrapy
    Feb 1 at 2:58











  • It means: read the file if it's there, but continue to try to start up without it.
    – Tim Kennedy
    Feb 1 at 18:08
















  • What does =- means in EnvironmentFile=-/etc/profile? What does minus (-) means in =-?
    – scrapy
    Feb 1 at 2:58











  • It means: read the file if it's there, but continue to try to start up without it.
    – Tim Kennedy
    Feb 1 at 18:08















What does =- means in EnvironmentFile=-/etc/profile? What does minus (-) means in =-?
– scrapy
Feb 1 at 2:58





What does =- means in EnvironmentFile=-/etc/profile? What does minus (-) means in =-?
– scrapy
Feb 1 at 2:58













It means: read the file if it's there, but continue to try to start up without it.
– Tim Kennedy
Feb 1 at 18:08




It means: read the file if it's there, but continue to try to start up without it.
– Tim Kennedy
Feb 1 at 18:08


Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay