Run Command at Login/Startup

Quick to answer questions about finding your way around Linux Mint as a new user.
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. Stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions use the other forums in the support section.
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
User avatar
grimdestripador
Level 6
Level 6
Posts: 1051
Joined: Fri Feb 16, 2007 2:26 am

Run Command at Login/Startup

Post by grimdestripador »

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.
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
RedWagon

Re: Run Command at Login/Startup

Post by RedWagon »

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

Re: Run Command at Login/Startup

Post by vincent »

Actually, what I do is put my startup commands in /etc/rc.local, which works perfectly fine for me.
RedWagon

Re: Run Command at Login/Startup

Post by RedWagon »

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

Re: Run Command at Login/Startup

Post by piratesmack »

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: 1051
Joined: Fri Feb 16, 2007 2:26 am

Re: Run Command at Login/Startup

Post by grimdestripador »

I found some graphical ways, on the ubuntu web site
https://help.ubuntu.com/community/SynergyHowto
User avatar
grimdestripador
Level 6
Level 6
Posts: 1051
Joined: Fri Feb 16, 2007 2:26 am

Re: Run Command at Login/Startup

Post by grimdestripador »

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: 1051
Joined: Fri Feb 16, 2007 2:26 am

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

Post by grimdestripador »

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/
Locked

Return to “Beginner Questions”