Tuesday, May 7, 2024
 Popular · Latest · Hot · Upcoming
4
rated 0 times [  4] [ 0]  / answers: 1 / hits: 10663  / 2 Years ago, thu, april 7, 2022, 12:16:01

In rc.local I added a line for my shell file I want to run on boot:



/direc/tory/<fileName>.sh


The script looks like this:



#!bin/sh
wget "http://somesite.org/someJava.jar" -O /direc/tory/someJavaFile.jar
java -d64 -Xincgc -Xmx512M -jar /direc/tory/someJavaFile.jar


and I would assume it would run and load in the /direc/tory/ folder but it keeps running in / and it saves all its files in there as well.



What do I have to do to force it to run in the /direc/tory/ folder?


More From » startup

 Answers
0

Your script doesn't contain any command to set the current directory, so it runs in the same directory as the process that invoked it. When it's executed from rc.local, which is executed from init, the current directory is the root directory /.



Add cd /direc/tory/ to your script. By the way, note that it's #!/bin/sh (#!bin/sh happens to work here only because you're executing your script from the root directory; it's a very bad idea to rely on this.)



#!/bin/sh
set -e
cd /direc/tory
wget "http://somesite.org/someJava.jar" -O someJavaFile.jar
java -d64 -Xincgc -Xmx512M -jar someJavaFile.jar


I also added set -e in the script. This makes it stop if one of the commands fails. For example, if wget cannot download the jar, then java isn't executed.


[#38513] Thursday, April 7, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cheeturage

Total Points: 432
Total Questions: 111
Total Answers: 115

Location: Bahrain
Member since Tue, Mar 1, 2022
2 Years ago
;