file not found during running a script


New Member

-I have a script /opt/labs/installer/fabric/first-network/ . This script internally call various files like ./docker_cli.yaml , ./docker-compose-cli.yaml which are located in /opt/labs/installer/fabric/first-work folder.
-When I am logged in as root and run the script as "/opt/labs/installer/fabric/first-work/ up" it works perfectly fine.
-But when I am logged in as other user and run the script as "/opt/labs/installer/fabric/first-work/ up" it says docker_cli.yaml , docker-compose-cli.yaml are missing and could find them in the directory.
-I cannot update the script manually and give the full path as it is over 600 lines of code
-How do I run the script so that all these files are visible to the byfn .sh script? Please help.

Thanks in advance


Well-Known Member
Not sure what to suggest offhand, so I'll spit-ball some ideas off the top of my head, based on the information you have presented.

If the script can see the files when running as root, but not when running as a user - it sounds like it could be a permissions related thing - perhaps?

Or perhaps, if the yaml files are specified in the script using relative paths - e.g. ./docker_cli.yaml - perhaps it is related to the directory you were in when you ran the script.

Which directory were you in when you ran the script as root?
Were you in a different directory when you ran as the user?

Perhaps it will work if you cd into /opt/labs/installer/fabric/first-work/ and then run the script:
cd /opt/labs/installer/fabric/first-work/
That should work whoever you are logged in as - provided there are no permissions related issues.
With the above - the current working directory will be where the yaml files are. So the lines of the script that use relative file-paths like ./docker_cli.yaml should work just fine.

Also - the size of the script shouldn't make any difference to your ability to edit/modify it. You could easily modify all of the relative paths in the script in no time whatsoever by using a simple one-liner using sed - or by using the search/replace functionality in any text editor.

So it shouldn't matter if the script is 600 lines, or 6000 lines of code.
If you think editing the script to use absolute paths to the YAML files will fix the issue - just do it!

But keep a backup of the original before you make any edits to it.

Is this script something that you have downloaded from somewhere? or is it something you have written? or is it something that you have been given as a part of a course?

I have had another thought - the use of relative paths in the script could be deliberate.
If the script is indended for you to be able to set up different instances of something - based on different criteria specified in YAML files.

So for example:
If you have a Projects folder with two subfolders for different projects:

And project1 and project2 both have their own complete set of yaml files.

If you go into /home/user/Projects/project1/ and run the script /opt/labs/installer/fabric/first-work/ would use the YAML files in /home/user/Projects/project1/ and would set things up for project1.

If you ran the script from the project2 folder - it would use the YAML files for project2.

So the use of relative file-paths might be deliberate in the script - that is, if it is intended to be used in this way!

So as far as I see it - depending on what this script is and how it is intended to be used - you can either:
1. cd into the /opt/labs/installer/fabric/first-work/ directory and run the script
2. Modify the script to use absolute file-paths for the YAML files instead of relative-paths
3. Ensure you have the appropriate YAML files in the current directory before running the script.
  • Like
Reactions: Rob

Members online