Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

share|improve this question
1  
Uhmm.. What do you mean by session? Opening terminal or gnome session? –  Andrejs Cainikovs Dec 12 '11 at 15:29
    
I mean after logging in Ubuntu. –  tirengarfio Dec 12 '11 at 15:33
    
In this case follow tiempjuuh answer. –  Andrejs Cainikovs Dec 12 '11 at 15:38

5 Answers 5

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

enter image description here

enter image description here

share|improve this answer

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
share|improve this answer

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.

share|improve this answer
    
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

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)
share|improve this answer

/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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.