-1

I have a script in a folder:

/home/ubuntu/jasperreports-server-cp-6.3.0/ctlscript.sh

I need this script to run every time the server starts. Usually the server shuts down on Friday evenings and starts on Monday morning. What do I need to do in order to make this happen?.

How I manually start the script:

I will ssh to the server, and then go to this location /home/ubuntu/jasperreports-server-cp-6.3.0

and then run ./ctlscript.sh* start command manually.

But I am unable to start this script at the server start on Monday automatically.

I tried using rc.local , and also creating a script in /etc/init.d, I did follow this but it didn't work either How do I run a script at start up?.

Does anyone have any other suggestions? Or is my procedure wrong?

Zanna
  • 69,223
  • 56
  • 216
  • 327
user2132767
  • 3
  • 1
  • 4
  • Have you tried editing your cron table? See [this answer to "How to run scripts on start up?"](https://askubuntu.com/a/816/787506) – Hee Jin May 15 '18 at 16:56
  • @Emily the link I provided in the question has one of the method that you suggested, but I tried all 3 methods and it din't work. I am not sure as I have to run the script ctlscript.sh with a start next to it. not sure if it what needed much attention, and how to modify the case that suits this scenario. – user2132767 May 15 '18 at 17:30
  • You can use [systemd.service](http://www.freedesktop.org/software/systemd/man/systemd.service.html). Detailed procedure can be found here : [How to write startup script for systemd](https://unix.stackexchange.com/questions/47695/how-to-write-startup-script-for-systemd#47715). – Future Gadget May 15 '18 at 18:07
  • First I created vi script.sh, and added "#!/bin/sh cd /home/ubuntu/jasperreports-server-cp-6.3.0 ./ctlscript.sh start" and then used "crontab -e" command,which opens a file and I have added "@reboot sh /path/to/my/script.sh" . so when my server reboots or starts , the script is run every time. it worked for me. thank you all – user2132767 May 16 '18 at 16:23

1 Answers1

0

I solved it this time

First I created a runnable script

vi script.sh

at home location that is at /home/ubuntu (you can create it at any location,but remember you have to give the same location in crontab -e) and then added these lines to the file script.sh

#!/bin/sh
cd /home/ubuntu/jasperreports-server-cp-6.3.0
./ctlscript.sh start

(I have a parameter to use start , but for you it might be a different, so here it should be the command that you use manualy to run the script, in simile it should be the same as how you run the script manually)

and then saved it. now gave the file script.sh permission to exec using

chmod 700 script.sh

(You can give permissions based on your needs, all we need is the script to be give permission for execution)

And now opened crontab -e command, and added

@reboot sh /home/ubuntu/script.sh

so when my server reboots or starts , the script is run every time. it worked for me. thank you all

Andrea Corbellini
  • 15,616
  • 2
  • 64
  • 81
user2132767
  • 3
  • 1
  • 4