TransWikia.com

How to run a .sh file in terminal on login

Ask Ubuntu Asked by user2662920 on January 19, 2021

so I have a simple sh file I want to run whenever someone logs in. I tried adding it to startup applications. This didn’t work. I tried editing the .desktop file for the startup application to set Terminal=true. This made it open temporarily but shut it down.
I tried editing .bashrc by adding the command bash /path/to/my/file.sh and it had the same effect. This seems like it should be really simple to do, even in linux, but I have tried lots of ways and had no success. I am on Ubuntu 14.something.

2 Answers

When you set Terminal=true in the desktop file, the terminal window by default closes after the "the job has finished". An easy solution is to change your (terminal-) profile settings:

  • open a terminal window, choose Profile Preferences
  • choose "Title & Command" (at least that is what it is in Dutch, the second tab)
  • in the section "when the command has finished" choose "keep terminal window open"

And of course, like you did, in the desktop file, set Terminal=true

enter image description here

Answered by Jacob Vlijm on January 19, 2021

Solution for Question --> "so I have a simple sh file I want to run whenever someone logs in. I tried adding it to startup applications."

Suppose path of your file is /home/foster/Desktop/script.sh

First make it executable by :

$ chmod +x /home/foster/Desktop/script.sh

Now just Add path of the script to file "/etc/rc.local" :

sh /home/foster/Desktop/script.sh
exit 0

Answered by vivekyad4v on January 19, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP