LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Run a command at login (https://www.linuxquestions.org/questions/linux-newbie-8/run-a-command-at-login-918965/)

corbinc 12-15-2011 05:26 PM

Run a command at login
 
As a user, how can I run the following command (to start dropbox) everytime I login?

~/.dropbox-dist/dropbox &

I am on open suse 11.4, soon to be 12.1

I was browsing the forums and saw a post from years ago that solved it by adding the command to etc/rc.local, however I can't find that file and when i try to cd there, it says file does not exist.

If you need any more info let me know.

thanks

TobiSGD 12-15-2011 05:36 PM

If you want it to start when the user logs in (which would be a good thing with dropbox) rather than being launched when the machine starts (which would be the case when you put that in rc.local) just add the command to your ~/.bashrc file.

corbinc 12-15-2011 05:43 PM

Quote:

Originally Posted by TobiSGD (Post 4551064)
If you want it to start when the user logs in (which would be a good thing with dropbox) rather than being launched when the machine starts (which would be the case when you put that in rc.local) just add the command to your ~/.bashrc file.

I dont have a .bashrc file in my home directory (all i have access to), i do however have a .cshrc, is that the same thing? If so what is the syntax for adding the command in there? Or do i literally just type the command in there?

here is the contents of the .cshrc file:

#
# Standard .cshrc file for new accounts
#

# If you want the system to shut up (i.e. skip all of the
# xxxxxx added to environment messages at login), uncomment the next line
setenv QUIET 1

# The following lines set up a default, generic account which will work on
# all of the supported operating systems in the department. If you want to
# change the set of software available in your account, see the COG web site
# at http://intranet.cs.nmsu.edu/COG/CogDocs/setup.html, comment out the next
# line and see the tail end of this file.
source /local/config/cshrc.standard
source ~/.alias

# Custom configurations
# To customize, comment out the first source line of this file and uncomment
# the section below. Read the COG documentation on customizing your account.
# For the impatient - the setenv statements below register the OS name and
# revision you have logged in on. The if/then/else statements select a
# section based on the OS name and revision. The source statemetns inside
# the branches actually do the work. In this code, they again source the
# default setups, which are different on each OS. A reasonable starting point
# is to log in to the OS for which you wish to customize and replace the
# appropriate cshrc.standard line with the contents of the
# /local/config/cshrc.standard file on that platform, then add and delete
# source lines as needed

#setenv OS_NAME `uname -s`
#
#if( $OS_NAME == "Linux" ) then
# source /local/config/cshrc.standard
#else if ( $OS_NAME == "SunOS" ) then
# # This part is for Solaris
# source /local/config/cshrc.standard
#else
# echo "Unknown Operating System"
#endif
source /home/CS273/cshrc.cs273

TobiSGD 12-15-2011 05:54 PM

If you don't have .bashrc, but you have .cshrc that indicates that you are not using Bash, but csh as shell. I know nothing about .csh, but I would just try to add that command at the end of the file (yes, just type it in).
If that doesn't work try to create a .bashrc and add the command there.

suicidaleggroll 12-15-2011 06:00 PM

Putting it in .bashrc will cause it to run every time he opens a terminal. Probably not what he's looking for with dropbox...

OP - you need to be more clear exactly WHEN you want this to run. When the machine first boots up? When the user first logs in in a text session? When the user first logs in in a graphical session? Every time the user opens a terminal? All of these have different solutions and ramifications.

corbinc 12-15-2011 06:03 PM

I just added it to the end of the .cshrc file, then i logged out and logged back in and it appears to be running because the dopbox icon is on the system tray (it never showed up there until i ran the command before).

So that seemed to have worked.

Thanks!

suicidaleggroll 12-15-2011 06:07 PM

Quote:

Originally Posted by corbinc (Post 4551081)
I just added it to the end of the .cshrc file, then i logged out and logged back in and it appears to be running because the dopbox icon is on the system tray (it never showed up there until i ran the command before).

So that seemed to have worked.

Thanks!

Careful...the way you have it set up, it's going to be launching dropbox every time you open a terminal. Now if dropbox is clever enough to see that it's already running and cancel the launch, then you're fine, but if not you're going to end up with a LOT of duplicate dropbox sessions after a very short while.

suicidaleggroll 12-15-2011 06:11 PM

For what it's worth, I have mine set to launch on boot using the cron.

Code:

areynolds@craig:~> crontab -l
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.rUx0TX installed on Tue Nov 15 19:23:18 2011)
# (Cronie version 4.2)
@reboot $HOME/.dropbox-dist/dropboxd


MTK358 12-15-2011 06:43 PM

Quote:

Originally Posted by TobiSGD (Post 4551064)
If you want it to start when the user logs in (which would be a good thing with dropbox) rather than being launched when the machine starts (which would be the case when you put that in rc.local) just add the command to your ~/.bashrc file.

.bashrc is executed whenever you open an interactive terminal, not just when you log in. .bash_profile is run when you log in. I don't know what the csh equivalent of it is, though.

TobiSGD 12-15-2011 10:19 PM

Quote:

Originally Posted by MTK358 (Post 4551105)
.bashrc is executed whenever you open an interactive terminal, not just when you log in. .bash_profile is run when you log in. I don't know what the csh equivalent of it is, though.

You are right, I confused that.

jschiwal 12-15-2011 10:51 PM

For the tsch shell, look at this from the info file:
Commands like stty(1) and tset(1), which need be run only once per login, usually go in one's ~/.login file.
The ~/.login file is also used for the csh. (In SuSE, the /bin/csh command is a dynamic link to the /bin/tsch command.)

For items when you log in, check for the term "login shell" in the documentation. It is common to set an environment variable in a wrapper. The script should check for this variable and if it doesn't exist, set it and start the service. If it does exist, don't start the service. You might instead check if the dropbox service creates a PID file, and check for that instead. You could have logged into vt2 after being logged in graphically.

Also, for system startup commands, there is a directory /etc/profile.d/ that contain system wide startup scripts for different shells. You could create a dropbox.sh & dropbox.csh script in this directory to start dropbox system wide. This script might for example simple set a variable a user would need. See the /etc/profile.d/cvs.tcsh for an example.

corbinc 12-16-2011 09:09 AM

To clarify - I would like the command to run one time, when i log onto a machine (graphical session). I am not root, just a user, so i only need it to start for me.

It does try to start it every time I open a terminal, which isn't ideal even though it does appear to be smart enough to kill one of the sessions. See below:

[1] 11893
daedalus[998]% Another instance of Dropbox (10221) is running!

[1] Exit 255 ~/.dropbox-dist/dropbox
daedalus[998]%

I don't really want to see this every time I open a terminal. So here is whats in my home directory which is all i have access to as a user right? I don't see a .login :(

Does anyone see the place i should put it? Or will i have access to a .login somewhere outside my home directory?

daedalus[998]% ls -all
total 366
drwxr-xr-x 78 ccarter guest 3072 2011-12-16 07:59 .
drwxr-xr-x 25 root root 512 2011-01-07 15:32 ..
drwx------ 5 ccarter guest 512 2009-07-10 09:28 .adobe
-rw-r--r-- 1 ccarter guest 161 2001-03-20 10:40 .alias
drwx------ 3 ccarter cogall 512 2011-08-04 16:52 .alice
-rw------- 1 ccarter guest 140 2009-07-30 13:37 .appletviewer
drwx------ 2 ccarter cogall 512 2011-08-23 16:15 .arduino
drwx------ 2 ccarter cogall 512 2011-12-15 14:55 bin
drwx------ 10 ccarter guest 512 2011-12-14 08:38 .cache
drwx------ 3 ccarter cogall 512 2011-08-04 11:41 .compiz
drwx------ 23 ccarter guest 1024 2011-12-14 17:03 .config
drwx------ 11 ccarter cogall 512 2011-11-08 17:05 CS273
drwx------ 4 ccarter cogall 512 2011-09-16 10:44 CS371
-rwx------ 1 ccarter guest 1707 2011-12-15 16:59 .cshrc
drwx------ 3 ccarter guest 512 2010-08-31 11:36 .dbus
drwx------ 2 ccarter guest 512 2011-12-14 12:55 Desktop
-rw------- 1 ccarter cogall 28 2011-12-16 07:59 .dmrc
drwxr-xr-x 18 ccarter guest 1024 2011-12-14 16:51 Documents
drwx------ 2 ccarter guest 512 2011-12-15 14:54 Downloads
-rw-r--r-- 1 ccarter cogall 61425 2011-12-14 10:25 Drafts
drwx------ 3 ccarter cogall 512 2011-12-16 08:06 .dropbox
drwx------ 11 ccarter cogall 512 2011-12-16 07:59 Dropbox
drwx------ 4 ccarter cogall 2048 2011-12-05 12:46 .dropbox-dist
drwx------ 4 ccarter cogall 512 2011-12-14 08:44 .eclipse
-rw------- 1 ccarter cogall 641 2011-12-14 10:50 .emacs
drwx------ 3 ccarter cogall 512 2011-12-14 10:50 .emacs.d
-rw------- 1 ccarter guest 16 2009-07-08 09:43 .esd_auth
drwx------ 7 ccarter cogall 512 2011-12-09 11:26 .evolution
drwx------ 2 ccarter guest 1536 2011-12-14 09:52 .fontconfig
drwx------ 5 ccarter guest 512 2011-12-16 07:59 .gconf
drwx------ 2 ccarter guest 512 2011-12-16 08:06 .gconfd
drwx------ 12 ccarter guest 512 2011-12-15 17:03 .gnome2
drwx------ 2 ccarter guest 512 2009-07-08 09:43 .gnome2_private
drwxr-xr-x 2 ccarter guest 512 2011-12-15 17:00 .gstreamer-0.10
-rw------- 1 ccarter cogall 177 2011-12-16 07:59 .gtk-bookmarks
drwx------ 2 ccarter guest 512 2009-07-08 09:43 .gvfs
-rw------- 1 ccarter guest 321 2009-07-08 10:21 Hello.java~
-rw------- 1 ccarter guest 22420 2011-12-16 08:06 .history
drwxr----- 2 ccarter guest 512 2010-08-31 11:36 .hplip
-rw------- 1 ccarter guest 69225 2011-12-16 07:59 .ICEauthority
drwx------ 5 ccarter cogall 512 2011-08-22 10:32 .icedtea
drwx------ 3 ccarter guest 512 2010-09-07 12:14 .icedteaplugin
drwx------ 2 ccarter guest 512 2010-08-31 11:44 .icons
drwx------ 7 ccarter cogall 512 2011-09-16 09:24 .imap
drwx------ 4 ccarter cogall 512 2011-12-13 16:50 .java
-rw------- 1 ccarter cogall 439 2011-08-15 09:24 .joe_state
drwx------ 3 ccarter guest 2048 2011-12-14 12:22 .kde-suse
drwx------ 3 ccarter cogall 512 2011-08-02 14:36 .libreoffice
drwx------ 3 ccarter guest 512 2009-07-08 09:43 .local
drwx------ 3 ccarter cogall 512 2011-12-14 09:04 .m2
drwx------ 3 ccarter guest 512 2009-07-10 09:28 .macromedia
drwx------ 3 ccarter cogall 512 2011-12-15 15:40 mail
-rw-r--r-- 1 ccarter cogall 60 2011-09-16 09:24 .mailboxlist
-rwx------ 1 ccarter guest 62 1995-12-12 16:38 .mailrc
drwx------ 2 ccarter cogall 512 2011-08-09 16:27 .mc
drwx------ 3 ccarter guest 512 2009-07-08 10:09 .mcop
-rw------- 1 ccarter guest 31 2009-08-05 13:46 .mcoprc
drwx------ 3 ccarter guest 512 2009-07-08 09:43 .metacity
drwx------ 3 ccarter cogall 512 2011-12-09 11:26 .mission-control
drwx------ 5 ccarter guest 512 2011-09-07 11:05 .mozilla
drwx------ 2 ccarter guest 512 2010-08-31 11:36 Music
drwx------ 2 ccarter cogall 512 2011-12-09 12:17 .nautilus
drwx------ 3 ccarter cogall 512 2011-12-13 16:50 .netbeans
drwx------ 6 ccarter cogall 512 2011-12-14 10:45 NetBeansProjects
drwx------ 3 ccarter guest 512 2010-08-31 11:38 .netx
-rwx------ 1 ccarter guest 0 2001-03-20 10:47 .newsrc
drwx------ 3 ccarter cogall 512 2011-12-09 11:57 .nv
drwx------ 3 ccarter guest 512 2011-08-02 14:37 .ooo-2.0
drwx------ 2 ccarter guest 512 2011-12-14 10:02 Pictures
drwx------ 2 ccarter guest 512 2010-08-31 11:36 Public
drwxr-xr-x 2 ccarter cogall 512 2011-11-22 10:45 public_html
drwx------ 2 ccarter cogall 19968 2011-12-14 12:22 .pulse
-rw------- 1 ccarter guest 256 2009-07-08 09:43 .pulse-cookie
drwx------ 2 ccarter guest 512 2009-07-08 10:02 .qt
drwx------ 3 ccarter cogall 512 2011-08-04 10:00 .rcc
-rw------- 1 ccarter guest 1958 2009-02-09 10:00 README
-rw------- 1 ccarter guest 532 2009-07-28 13:20 .recently-used
-rw------- 1 ccarter cogall 24505 2011-12-15 17:03 .recently-used.xbel
drwx------ 2 ccarter guest 512 2009-07-08 09:43 .skel
drwx------ 2 ccarter cogall 512 2011-08-23 16:15 sketchbook
drwx------ 2 ccarter cogall 512 2011-12-15 15:35 .spamassassin
drwx------ 2 ccarter cogall 512 2011-08-04 10:44 .ssh
drwx------ 3 ccarter cogall 512 2011-08-18 16:29 .subversion
drwx------ 3 ccarter cogall 512 2011-12-09 11:59 .swt
drwx------ 2 ccarter guest 512 2010-08-31 11:36 Templates
drwx------ 5 ccarter cogall 512 2011-12-14 09:00 test2
-rw------- 1 ccarter cogall 95 2011-12-09 12:00 Test.java
drwx------ 3 ccarter guest 512 2011-08-26 11:14 .themes
drwx------ 4 ccarter guest 512 2011-08-02 13:56 .thumbnails
drwx------ 4 ccarter cogall 512 2011-12-14 09:53 .thunderbird
drwx------ 4 ccarter guest 512 2010-08-31 11:36 .tomboy
-rw------- 1 ccarter guest 4744 2009-08-06 15:44 .tomboy.log
drwx------ 2 ccarter guest 512 2010-08-31 11:36 Videos
-rw------- 1 ccarter guest 4184 2011-12-15 16:43 .viminfo
drwx------ 2 ccarter guest 512 2009-08-06 15:44 .wapi
-rw------- 1 ccarter cogall 115 2011-12-14 10:17 webct_upload_applet.properties
drwx------ 6 ccarter cogall 512 2011-12-09 11:55 workspace
drwx------ 4 ccarter cogall 512 2011-12-09 12:03 workspace2
drwx------ 4 ccarter cogall 512 2011-12-09 11:59 workspace3
drwx------ 4 ccarter cogall 512 2011-12-09 12:01 workspace4
drwx------ 4 ccarter cogall 512 2011-12-13 16:58 workspaceR
-rw------- 1 ccarter cogall 420 2011-12-16 07:59 .Xauthority
drwx------ 2 ccarter guest 512 2010-08-31 12:01 .xine
-rw------- 1 ccarter cogall 27138 2011-09-15 17:02 .xsession-error
-rw-r--r-- 1 ccarter cogall 24979 2011-12-16 08:07 .xsession-errors
-rw------- 1 ccarter cogall 7361 2011-08-19 15:31 .xsession-errors.old
daedalus[999]%

jschiwal 12-17-2011 04:40 AM

Put your script in ~/.local. You should have indicated which shell you are using up front in the first post.

A login shell is a shell that starts when you login. In bash, it sources .profile. In csh it sources .local

The ~/.local file is in your directory listing. If it doesn't exist, then create a new one.

corbinc 12-19-2011 09:22 AM

Okay, where exactly do I put the command? Do I need to create a new directory?

I see the .local, in that directory there is a "share" directory and within share i have all of these directories:
ls -all
total 86
drwx------ 16 ccarter guest 512 2011-12-16 17:00 .
drwx------ 3 ccarter guest 512 2011-12-19 08:18 ..
drwx------ 2 ccarter cogall 512 2011-12-16 08:16 applications
-rw------- 1 ccarter guest 0 2010-08-31 11:36 .converted-launchers
drwx------ 2 ccarter cogall 512 2011-08-02 16:55 desktop-directories
drwx------ 6 ccarter cogall 512 2011-12-09 11:26 evolution
drwx------ 2 ccarter cogall 512 2011-12-09 11:26 folks
drwx------ 4 ccarter guest 512 2011-12-14 12:22 gnome-do
drwx------ 2 ccarter guest 512 2010-08-31 11:36 gnome-main-menu
drwx------ 3 ccarter cogall 512 2011-12-16 16:59 gnome-shell
-rw------- 1 ccarter cogall 731 2011-12-09 11:25 gsettings-data-convert
drwx------ 2 ccarter guest 1536 2011-12-19 08:20 gvfs-metadata
drwx------ 2 ccarter guest 512 2011-12-15 15:14 parcellite
-rw------- 1 ccarter cogall 68973 2011-12-16 17:00 recently-used.xbel
drwx------ 3 ccarter cogall 512 2011-12-09 11:26 telepathy
drwx------ 2 ccarter guest 512 2010-08-31 11:36 tomboy
drwx------ 3 ccarter guest 512 2011-12-19 08:16 tracker
drwx------ 5 ccarter guest 512 2011-08-02 16:54 Trash
drwx------ 3 ccarter cogall 512 2011-08-22 10:24 webkit


pwd
/home/nacs1/ccarter/.local/share

JZL240I-U 01-03-2012 02:04 AM

KDE has an autostart functionality too. I'm sitting in front of a windows box, so I can't look for it now, but I seem to remember that you can reach it via the control center.


All times are GMT -5. The time now is 03:40 AM.