LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   change running path in bash (https://www.linuxquestions.org/questions/programming-9/change-running-path-in-bash-787254/)

sir-lancealot 02-05-2010 10:36 AM

change running path in bash
 
We have a custom app that runs on boot on some older hardware running DSL linux, and their startup manager was quite simple. We purchased some newer Asus eeebox's which run xandros and things are quite stable and run nice with 1 exception.

The application only runs from the root (/) location. This box auto logs in as 'user' and there is a /home/user/.kde/Autostart folder where you can stick scripts to run at boot. So I have a start.sh script, and with little bash programming tried things such as;

sudo cd /
sudo /startapp.pl

but the errors start spewing with the basic;
can't find data/xyz as it's looking in the local. I thought there was a basic cwd (change working directory) but everything I try just forces the run from that location.

Any ideas or suggestions are appreciated, but things like can you change the code, etc. can't be done, so it must be a programming thing. The only other thought I had but not sure, can you do a cronjob with @boot or something, that when the box starts, it can run this job as root and fire off?

Thanks

mjones490 02-05-2010 10:47 AM

What would happen if you created a symlink in the local directory back to where the real data directory is?
Code:

ln -sv /home/user/data /data

theNbomr 02-05-2010 12:41 PM

Or, it could be that some security feature (selinux?) has restricted applications from running with $PWD == / Have you tried launching the application from /etc/rc.local or making it into a system daemon, rather than waiting for KDE to start (problematic if the application requires X, or has any interactive element to it)?
--- rod.

ta0kira 02-05-2010 05:42 PM

Why don't you chdir from the program itself if it has to run from /? You can at least print an error if it fails. Also, cd is a built-in: using sudo, if it works, will run whatever cd program happens to be there as a separate process, but the shell will stay in the same place. You might do exec bash -c 'cd /; /path/to/app;' in a script, also. If that doesn't work, you might need to . bashrc or use -login.
Kevin Barry


All times are GMT -5. The time now is 05:25 AM.