LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-27-2012, 03:16 AM   #1
chrisgreg
LQ Newbie
 
Registered: Jan 2012
Posts: 17

Rep: Reputation: Disabled
Wink How do I run a script after log on in ubuntu?


Hi

I have set up a laptop with ubuntu, linked to server with nfs and set up MPD. This all works great, but the problem is on startup the NFS drive tries to mount at boot up, but the wireless doesn't connect until I log in, at which point the NFS isn't mounted and then MPD stalls. I have to manually re-mount and restart MPD. To start with I have written a script to mount the nfs drive after the network is up, I plan on adding a command to start the MPD after I figure out how,

What I would like to know is how to get this script to run after I log in and after everything else has started. I have been reading forums for a few days trying to figure it out but I just ended up getting really confused.

My understanding so far, place script.sh in /etc/profile.d, make it executable for all, then run update-rc.d default Is this correct? When I run the script manually it needs root, is this because I havent used the correct chmod command? I used chmod +x.

From reading another post on NFS mounting I know that there is another way to get the drive to mount after network is up, but I would like to get the script to run anyway and I'm not sure if this method would work with wireless.

Thanks in advance if anybody is able to point me in the right direction.
 
Old 01-27-2012, 07:45 PM   #2
Wayne Sallee
Member
 
Registered: Jun 2011
Location: Florida
Distribution: The one that I built. (lfs)
Posts: 269

Rep: Reputation: 17
Google "init.d"

http://www.google.com/search?hl=en&l...ih=546&num=100

Wayne Sallee
Wayne@WayneSallee.com

Last edited by Wayne Sallee; 01-27-2012 at 07:51 PM.
 
Old 01-27-2012, 10:12 PM   #3
thund3rstruck
Member
 
Registered: Nov 2005
Location: East Coast, USA
Distribution: Fedora 18, Slackware64 13.37, Windows 7/8
Posts: 386

Rep: Reputation: 43
Quote:
Originally Posted by chrisgreg View Post
Hi

I have set up a laptop with ubuntu, linked to server with nfs and set up MPD. This all works great, but the problem is on startup the NFS drive tries to mount at boot up, but the wireless doesn't connect until I log in, at which point the NFS isn't mounted and then MPD stalls. I have to manually re-mount and restart MPD. To start with I have written a script to mount the nfs drive after the network is up, I plan on adding a command to start the MPD after I figure out how,

What I would like to know is how to get this script to run after I log in and after everything else has started. I have been reading forums for a few days trying to figure it out but I just ended up getting really confused.

My understanding so far, place script.sh in /etc/profile.d, make it executable for all, then run update-rc.d default Is this correct? When I run the script manually it needs root, is this because I havent used the correct chmod command? I used chmod +x.

From reading another post on NFS mounting I know that there is another way to get the drive to mount after network is up, but I would like to get the script to run anyway and I'm not sure if this method would work with wireless.

Thanks in advance if anybody is able to point me in the right direction.
The reason you need root access is because users can't mount file-systems by default. You will need to set the setuid bit in order to allow users to run mount (or you can edit /etc/sudoers using the visudo command).

Code:
chmod +s /sbin/mount
If you need to wait for the user to be logged in before running your script then you want that code to run in ~/.bash_profile which will run after you are logged in. I'm not too keen on init.d as suggested above so I can't comment on that advise.

All you need to do to resolve your problem is to allow users to execute mount and then run your script in ~/.bash_profile.

Hope this helps

Last edited by thund3rstruck; 01-27-2012 at 10:14 PM. Reason: afterthought
 
Old 01-28-2012, 01:54 AM   #4
chrisgreg
LQ Newbie
 
Registered: Jan 2012
Posts: 17

Original Poster
Rep: Reputation: Disabled
Thanks for the advice. Ive tried init.d and that seemed to cause problems because of the wireless not being active, I might try this on another desktop just to see if I can get it to work.

So if I put it in bash_profile, is there anything I have to update as you would with init.d? Or is it just a case of making the script executable and putting it in the directory. Sorry if these are obvious questions, Ive never installed scripts before.
 
Old 01-28-2012, 07:55 AM   #5
thund3rstruck
Member
 
Registered: Nov 2005
Location: East Coast, USA
Distribution: Fedora 18, Slackware64 13.37, Windows 7/8
Posts: 386

Rep: Reputation: 43
Quote:
Originally Posted by chrisgreg View Post
So if I put it in bash_profile, is there anything I have to update as you would with init.d? Or is it just a case of making the script executable and putting it in the directory. Sorry if these are obvious questions, Ive never installed scripts before.
No, init.d has nothing to do with running scripts after the user logs in. Anything in bash_profile will get run every time the user logs in. So if you have a working script then execute it from .bash_profile.

For example, in my bash_profile I call a script that maps the user's Windows home share.
 
Old 01-28-2012, 11:04 AM   #6
WarTurkey
Member
 
Registered: Jun 2009
Posts: 67

Rep: Reputation: 16
You'll also need to invoke the command as "/sbin/mount", because "/sbin" is not in your path by default, when you're not root.
 
Old 01-28-2012, 11:14 AM   #7
chrisgreg
LQ Newbie
 
Registered: Jan 2012
Posts: 17

Original Poster
Rep: Reputation: Disabled
Is that in the script itself?
 
Old 01-28-2012, 01:22 PM   #8
thund3rstruck
Member
 
Registered: Nov 2005
Location: East Coast, USA
Distribution: Fedora 18, Slackware64 13.37, Windows 7/8
Posts: 386

Rep: Reputation: 43
Quote:
Originally Posted by WarTurkey View Post
You'll also need to invoke the command as "/sbin/mount", because "/sbin" is not in your path by default, when you're not root.
Yea, I don't know about all that. Mount is in /bin and anyways /sbin is in my regular users path. I run mount.cifs on all my linux without specifying the /sbin path.

Code:
$ ls -all $(which mount.cifs)
-rwxr-xr-x. 1 root root 38992 Dec  9 21:09 /sbin/mount.cifs
Code:
$ which mount
/bin/mount
Code:
$ echo $PATH
/usr/lib64/ccache:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/lisa.bailey/.local/bin:/home/lisa.bailey/bin

Last edited by thund3rstruck; 01-28-2012 at 01:24 PM.
 
Old 01-28-2012, 02:06 PM   #9
chrisgreg
LQ Newbie
 
Registered: Jan 2012
Posts: 17

Original Poster
Rep: Reputation: Disabled
Code:
$ ls -all $(which mount.cifs)

-rwsr-sr-x 1 root root 30424 2011-09-30 18:36 /sbin/mount.cifs

$which mount
/bin/mount

$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
This is the output from those command, the /sbin/mount.cifs bit is highlighted red. This is after I have run sudo chmod +x /sbin/mount.cifs, and sudo chmod +x /bin/mount. I'm not really sure what I am supposed to be doing. If I try and run the script manually it says mount:only root can do this, which we already know.
 
Old 01-28-2012, 03:11 PM   #10
thund3rstruck
Member
 
Registered: Nov 2005
Location: East Coast, USA
Distribution: Fedora 18, Slackware64 13.37, Windows 7/8
Posts: 386

Rep: Reputation: 43
Quote:
Originally Posted by chrisgreg View Post
I'm not really sure what I am supposed to be doing. If I try and run the script manually it says mountnly root can do this, which we already know.
post the output of:
Code:
ls -all $(which mount)
because if you set the sticky bit correctly on mount then all users can now mount filesystems. In other words when you type mount it now returns the help page instead of a message that says only root can do this.
 
Old 01-28-2012, 03:54 PM   #11
chrisgreg
LQ Newbie
 
Registered: Jan 2012
Posts: 17

Original Poster
Rep: Reputation: Disabled
Code:
-rwsr-sr-x 1 root root 72188 2011-01-20 19:54 /bin/mount
if I run mount

Code:
/dev/sda5 on / type ext4 (rw,errors=remount-ro)
proc on /proc type proc (rw,noexec,nodev)
none on /sys type sysfs (rw,noexec,nosuid,nodev)
none on /sys/fs/fuse/connections type fusectl (rw)
none on /sys/kernel/debug type debugfs (rw)
none on /sys/kernel/security type securityfs (rw)
none on /dev type devtmpfs (rw,mode=0755)
none on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
none on /dev/shm type tmpfs (rw,nosuid,nodev)
none on /var/run type tmpfs (rw,nosuid,mode=0755)
none on /var/lock type tmpfs (rw,noexec,nosuid,nodev)
none on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)
binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noexec,nosuid,nodev)
gvfs-fuse-daemon on /home/chris/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev,user=chris)
what does this all mean?
 
Old 01-28-2012, 06:04 PM   #12
thund3rstruck
Member
 
Registered: Nov 2005
Location: East Coast, USA
Distribution: Fedora 18, Slackware64 13.37, Windows 7/8
Posts: 386

Rep: Reputation: 43
Quote:
Originally Posted by chrisgreg View Post
Code:
-rwsr-sr-x 1 root root 72188 2011-01-20 19:54 /bin/mount
Looks good. Sticky bit is set.

Quote:
Originally Posted by chrisgreg View Post
if I run mount

Code:
/dev/sda5 on / type ext4 (rw,errors=remount-ro)
proc on /proc type proc (rw,noexec,nodev)
none on /sys type sysfs (rw,noexec,nosuid,nodev)
none on /sys/fs/fuse/connections type fusectl (rw)
none on /sys/kernel/debug type debugfs (rw)
none on /sys/kernel/security type securityfs (rw)
none on /dev type devtmpfs (rw,mode=0755)
none on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
none on /dev/shm type tmpfs (rw,nosuid,nodev)
none on /var/run type tmpfs (rw,nosuid,mode=0755)
none on /var/lock type tmpfs (rw,noexec,nosuid,nodev)
none on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)
binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noexec,nosuid,nodev)
gvfs-fuse-daemon on /home/chris/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev,user=chris)
what does this all mean?
When you run mount on its own without any parameters it lists all the devices that are currently monted (that's a really handy feature too!)

You should be all set now. Try to have a regular user mount something.
 
Old 01-29-2012, 01:15 PM   #13
chrisgreg
LQ Newbie
 
Registered: Jan 2012
Posts: 17

Original Poster
Rep: Reputation: Disabled
I still get the message mountnly root can do that
 
Old 01-29-2012, 01:47 PM   #14
thund3rstruck
Member
 
Registered: Nov 2005
Location: East Coast, USA
Distribution: Fedora 18, Slackware64 13.37, Windows 7/8
Posts: 386

Rep: Reputation: 43
Quote:
Originally Posted by chrisgreg View Post
I still get the message mountnly root can do that
Ugh... I accept my apologizes. When you set the sticky bit on mount you also have to have that filesystem defined in /etc/fstab with the user mountable option. Now I remember why we don't do it that way.

Hate to lead you down another path (maybe someone here can better walk through using the sticky bit with mount) but the way we (my company) allows users to mount is by editing /etc/sudoers (via visudo)

Code:
# Edit sudoers
sudo visudo

# add this line to the end of the file: 
# Allow members of the cdrom group to mount file systems (BE CAREFUL WITH THIS)
%cdrom ALL=NOPASSWD:NOEXEC:/bin/mount,/bin/umount
Now any user in the cdrom group can mount file-systems without requiring a password or anything:

Code:
sudo mount [parms] [source] [dest]
We usually create a security group called smbusers and add users into that group that have Windows shares and instead of granting those users the ability to use mount blatently we allow them to use /sbin/mount.cifs (which is exclusively for windows shares).

Hope this resolves your problem and I aoplogize for leading you down the sticky bit path
 
Old 01-29-2012, 02:57 PM   #15
jthill
Member
 
Registered: Mar 2010
Distribution: Arch
Posts: 211

Rep: Reputation: 67
To permit user mounts without giving away the keys to the kingdom, you could try adding something like this to /etc/sudoers:
Code:
ALL ALL = (ALL) NOPASSWD: /bin/mount -o loop /usr/local/isos/*.iso /media/cdrom*
ALL ALL = (ALL) NOPASSWD: /bin/mount /dev/cd* /media/cdrom*
ALL ALL = (ALL) NOPASSWD: /bin/mount /dev/dvd* /media/cdrom*
ALL ALL = (ALL) NOPASSWD: /bin/umount /media/cdrom*
with the pathnames modded to taste.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Ubuntu How to run Python script on Login? warnetgm Linux - General 14 03-13-2012 06:11 PM
Creating a script that will log into root and enter password and then run commands. tananthulus Linux - Newbie 8 11-02-2009 05:37 PM
Run this script after I log out lothario Linux - Software 2 06-03-2006 09:07 PM
Ubuntu Masquerade script to run on boot Unicron Linux - Newbie 1 06-01-2006 04:40 AM
init script won't run at log-off dimangi Linux - Newbie 1 10-29-2003 02:19 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration