Run Command at Login/Startup

All Gurus once were Newbies
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Please stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions prefer the other forums within the support section.
Before you post please read how to get help
Post Reply
User avatar
grimdestripador
Level 6
Level 6
Posts: 1052
Joined: Fri Feb 16, 2007 2:26 am

Run Command at Login/Startup

Post by grimdestripador » Thu Jun 10, 2010 8:59 pm

I've noticed differences between ubuntu and mint.
Question: What is the proper way to run a command at startup. Specifically I am looking to start a synergy server using

Code: Select all

synergys --config /etc/synergy.conf
For completeness please tell me how I can run this...
  • At startup/before login/like
    At beginning of login/
    After Login/like windows' startup folder
please tell me the file I would need to edit. I was hoping to insert like

Code: Select all

sudo su
echo "synergys --config /etc/synergy.conf" >> some_bash_startup_file
or perhaps sed or equivalent.

User avatar
RedWagon
Level 5
Level 5
Posts: 632
Joined: Tue May 26, 2009 6:41 pm

Re: Run Command at Login/Startup

Post by RedWagon » Fri Jun 11, 2010 12:15 am

I would create an startup script for it in /etc/init.d/ and then add it to the proper run level. I don't know the specifics for Mint (never had to do this in an Ubuntu based distro) but that should get you on the right path.

vincent
Level 8
Level 8
Posts: 2217
Joined: Tue Feb 09, 2010 4:10 am

Re: Run Command at Login/Startup

Post by vincent » Fri Jun 11, 2010 1:41 am

Actually, what I do is put my startup commands in /etc/rc.local, which works perfectly fine for me.
Debian Testing x64/LM9 Main x64/Windows 7 x64 - LG R580 laptop w/ Intel Core 2 Duo T6500 2.1 GHz, 4 GB DDR2 RAM, Nvidia Geforce G 105M, Ralink rt2860 802.11n, 300 GB WD HD 5400 rpm

User avatar
RedWagon
Level 5
Level 5
Posts: 632
Joined: Tue May 26, 2009 6:41 pm

Re: Run Command at Login/Startup

Post by RedWagon » Fri Jun 11, 2010 9:11 am

Actually, what I do is put my startup commands in /etc/rc.local, which works perfectly fine for me.
Nice tip! That's a much easier way to do the exact same thing I was getting at.

piratesmack
Level 5
Level 5
Posts: 694
Joined: Mon May 26, 2008 3:08 pm

Re: Run Command at Login/Startup

Post by piratesmack » Fri Jun 11, 2010 9:56 am

When you edit /etc/rc.local. there is no need to 'sudo su'
rc.local is run as root.

User avatar
grimdestripador
Level 6
Level 6
Posts: 1052
Joined: Fri Feb 16, 2007 2:26 am

Re: Run Command at Login/Startup

Post by grimdestripador » Wed Jun 23, 2010 2:07 pm

I found some graphical ways, on the ubuntu web site
https://help.ubuntu.com/community/SynergyHowto

User avatar
grimdestripador
Level 6
Level 6
Posts: 1052
Joined: Fri Feb 16, 2007 2:26 am

Re: Run Command at Login/Startup

Post by grimdestripador » Thu Jul 01, 2010 1:39 pm

In Linux Mint 9 Isadora which is based off the Ubuntu Lucid build 10.04. These commands should be good for most versions as well. If the file exists, your solid;P
To run a command during start up sequence; place a file in init.d near the alphabetical end. or perhaps hijack this file

Code: Select all

sudo pico /etc/init.d/rc.local
To run a command at start up, as root, just before anyone logs in

Code: Select all

sudo pico /etc/rc.local 
I use this command to run synergy. In this way both login screens can be controlled by one keyboard/mouse even before either computer logs in.

Code: Select all

 
export privilegedfile=/etc/rc.local
sudo sh -c "echo '#!/bin/sh -e' > $privilegedfile"
sudo sh -c "echo '# rc.local' >> $privilegedfile"
sudo sh -c "echo '# By default this script does nothing' >> $privilegedfile"
sudo sh -c "echo 'export JRE_HOME=/usr/lib/jvm/java-6-sun-1.6.0.20' >> $privilegedfile"
sudo sh -c "echo '/usr/local/tomcat/bin/startup.sh' >> $privilegedfile"
sudo sh -c "echo 'synergys --config /etc/synergy.conf' >> $privilegedfile"
sudo sh -c "echo 'exit 0' >> $privilegedfile"
 
To run a command with environment variables seen by user. It is observed after viewing ~/.profile that bash_login is desired

Code: Select all

sudo pico ~/.bash_login
Which I use as a place to store some frequency commands I use as environment variables

Code: Select all

echo "export tomcatdown='sudo /usr/local/tomcat/bin/shutdown.sh'" >> ~/.bash_login
echo "export tomcatup='sudo /usr/local/tomcat/bin/startup.sh'" >> ~/.bash_login
echo "export tomcat=/usr/local/tomcat/webapps" >> ~/.bash_login

User avatar
grimdestripador
Level 6
Level 6
Posts: 1052
Joined: Fri Feb 16, 2007 2:26 am

Re: Run Command at Login/Startup: To access Environment Vari

Post by grimdestripador » Tue Jul 06, 2010 12:55 pm

It turns out half of my problem stemed from a gnome-terminal issue.
I read through the following, and its a common problem to think that setting an environment vairable carries over to a gnome-terminal. Solution is to 'Edit Profile': Click 'Title & Command': Click 'Run command as login shell'. Upon open a new shell, the variables will be acessable.

http://www.linuxquestions.org/questions ... tup-76398/
http://www.debianhelp.org/node/11913
http://www.linuxquestions.org/questions ... nal-65055/

Post Reply

Return to “Newbie Questions”