Ubuntu – How to run shell commands in general and on startup

bashcommand linejavascripts

Beginner in Ubuntu 16.4 .
I have two commands which needs to be started when the computer starts up
Command 1: java -jar ~/folder/abc.jar
Command2: ~/folder/q/l32/q -p 8712
Both of these commands workd perfectly fine from teminal.Both from the home directory.
I have created 2 bash files one with

#!/bin/sh
java -jar ~/folder/abc.jar

another with

#!/bin/sh
~/folder/q/l32/q -p 8712
  1. How do I run these bash files individually? Double click doesn't run them.
  2. If I want these two scripts to be run at startup what I do? I modified the rc.local file and added the path of these two bash files but its not working.

Best Answer

Okay,so finally I did it.Let me explain the steps.

My file didn't have root access./etc/rc.local was trying to run it and was failing.As rc.local runs the file in root context.

Therefore I switched to crontab where I can specify the file to be run with respect to which user

crontab -e -u myusername

Once inside the crobtab file i used

@reboot /home/username/pathToMyBashFile

It worked.

Related Question