Saturday, May 4, 2024
 Popular · Latest · Hot · Upcoming
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 1010  / 3 Years ago, sun, june 13, 2021, 8:02:09

Problem description : I am using something called play framework in my development which requires me to make the python script play available in the path. Hence I create a symbolic link in /usr/local/bin ... Now I have written a shell script (call it status.sh) which calls this python script as follows : play status <some values here related to my app> &> /tmp/xyz.txt and this shell script then sends me the file via email. This works perfectly when I execute the script as follows ./script.sh. However when the script is executed as a cron expression everyday I get an output from stderr saying 'play: command not found'.



Hence I did some digging on my own and here are my findings :




  1. echo $PATH when I am on the shell shows that I have /usr/local/bin available to me hence I can successfully execute the command play status

  2. however when I type in sudo bash and then echo $PATH I do not have the path /usr/local/bin anymore. It is a limited set of folders (one of them being /usr/bin).



Q : Why this behavior ?! I fail to understand why the path is different. Also as a workaround would you suggest I do :




  • new symbolic link from /usr/bin to /usr/local/bin (what are the side effects of this?)

  • remove /usr/local/bin sym link altogether and only use /usr/bin

  • is there a convention that I am not following here for linking new programs and executing them from $PATH ?



Thanks.


More From » scripts

 Answers
7

All users, including root, have a set of environment variables that are applied each time a new shell is opened.



For a normal user you can add to the existing path by editing ~/.bashrc and putting the followling line at the very end:



PATH=$PATH:/mypath_to_my_files


For root I believe you would have to edit /root/.bashrc instead. In this case however it probably makes sense to make sure that all users have this in their path and for this you can use the edit line above and just put it at the end of the file /etc/bash.bashrc


[#34074] Monday, June 14, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ibuteking

Total Points: 35
Total Questions: 128
Total Answers: 138

Location: Indonesia
Member since Thu, Oct 1, 2020
4 Years ago
ibuteking questions
Sat, Sep 10, 22, 08:44, 2 Years ago
Fri, May 12, 23, 10:10, 1 Year ago
Tue, May 23, 23, 13:38, 1 Year ago
;