skip to Main Content

I have a jar file in the /root directory of a debian 11 VPS. I am having trouble creating a startup shell script.

The contents of the script (/etc/init.d/runjar.sh) are as follows:

#!/bin/sh

echo "Running Jar"
java -jar /root/bot.jar

exit 0

I had ran both "chmod +x /etc/init.d/runjar.sh" and "update-rc.d runjar.sh defaults". When I restarted the VPS, the jar did not run.

I tried running the script through the terminal "sh /etc/init.d/runjar.sh" and was met with the response:

root@api:~# sh /etc/init.d/runjar.sh
: not found/runjar.sh: 2:
Running Jar
Error: Unable to access jarfile /root/bot.jar
: not found/runjar.sh: 5:

I have made sure the permissions were set using "chmod +x /root/bot.jar" and "chmod 777 /root" to no avail.

Any help would be appreciated.

2

Answers


  1. Instead of using sh you can use the service command because the runjar.sh is palced in the init.d folder.

    Login or Signup to reply.
  2. 1. run a new script for a test

    echo -e '#!/bin/shnecho "Running Jar"ndate && echo "successful"' > /etc/init.d/runjar.sh

    sh /etc/init.d/runjar.sh

    if output info is successful,then it proved the env of shell is fine

    2. rewrite your script

    echo -e '#!/bin/shnecho "Running Jar"njava -jar /root/bot.jarnexit 0' > /etc/init.d/runjar.sh

    chmod +x /etc/init.d/runjar.sh

    sh /etc/init.d/runjar.sh

    and check the output info.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search