1

I have a .sh file that I execute just going to the containing folder and writing ./file.sh.

I want to execute that file when the session starts, so i create a symlink in /etc/init.d.

I expected it was executed when I start the session but it doesn't work..

The file has the "x" written next to the permissions, so I think it is executable.

Any help?

Javi

tirenweb
  • 440

5 Answers5

7

Dash-->Startup Applications-->Add-->/path/to/your/.sh

enter image description here

enter image description here

Jorge Castro
  • 71,754
tiempjuuh
  • 433
  • 2
  • 7
3

/etc/init.d/ contains scripts that are being executed when system starts.
If you want to start file.sh every time you open a terminal, place a call to this script in your .bashrc file:

# Start this awesome script
. /path/file.sh
1

There are easily a billion ways to do this but starting where you have, to add something to the old init system you need to run the following:

sudo update-rc.d foo defaults

Where foo is your script name.

Some popular alternatives:

  • Edit /etc/rc.local to call your script before the exit.
  • Create an upstart script. This is the replacement for System-V init that Ubuntu has carried for the past few releases. It's fairly good if you want more control over when your script is called but it's a more work.
  • Launch it from within your X session (if this is a graphical machine) via gnome or another method (there are probably half a billion of these methods alone)
Oli
  • 293,335
0

In the startup applications list add command below

sh <path to your file>.sh

make sure the file is marked as executable. i recommend to keep the file in home folder.

Hossain Muctadir
  • 281
  • 1
  • 3
  • 9
  • If you put sh in front of the script (as in your example), it is not required to be executable. – enzotib Dec 12 '11 at 16:57
0

or

~/.config/autostart/ --->Create a file (filename.desktop)
filename.desktop in file add:
#!/bin/bash

[Desktop Entry]
Name=startdeskapp
GenericName=Program
Comment=auto start a sample 
#
Exec=startdesk.sh # app file name (default as bin/)
Terminal=false
Type=Application
Icon=icon.png
Categories=Network;
StartupNotify=false
fossfreedom
  • 172,746
erkan şentürk
  • 1,187
  • 2
  • 9
  • 11