Sunday, July 21, 2019

command line - Open Terminal at Startup and run Java application



Here am I again after successfully installing Ubuntu MATE 14.04 with the help of AskUbuntu (thanks a bunch!)



What am I trying to achieve now is the following:





  1. Launch a Terminal with root privileges at startup

  2. Change the working directory to Desktop

  3. Execute Jar file with the "java -jar filename.jar" command



What is the easiest way to do this, preferably without installing any third parties?



EDIT: I am not only looking how to run a script at startup, but also launching a command line and executing a command.



You can spawn a bash root shell inside a mate-terminal instance, change the mate-terminal's working directory to ~/Desktop and execute your jar file inside it at startup by adding this command to Startup Applications:




mate-terminal -e "sudo -H /bin/bash -c \"cd ~/Desktop && java -jar executable.jar; /bin/bash\""



  1. Hit the Super key, type "Startup Applications" and hit Enter

  2. Name you command, type the name in the "Name" field and type the command in the "Command" field

  3. Click on "Save" and click on "Close"




image-1



Command breakdown:




  • mate-terminal -e "": opens a mate-terminal instance and runs in it

  • sudo -H /bin/bash -c \"\": spawns a bash root shell and runs in it

  • cd ~/Desktop && java -jar executable.jar; /bin/bash: changes the mate-terminal's working directory to ~/Desktop, executes java -jar executable.jar and spawns another bash root shell which will be available for further uses


No comments:

Post a Comment

11.10 - Can't boot from USB after installing Ubuntu

I bought a Samsung series 5 notebook and a very strange thing happened: I installed Ubuntu 11.10 from a usb pen drive but when I restarted (...