run a script at login (for display & mount issues)

If you are new to Linux or new to Sabayon Linux and just not sure where to post, here ya go. Post without fear of being told to RTFM :-)

Moderator: Moderators

run a script at login (for display & mount issues)

Postby ninodog » Thu Dec 03, 2009 20:30

Hi,

How do I write a script that runs automatically when I log in? I know that's basic, but I never learned it.

I have loaded Sabayon 5 with KDE 4.3.3 on my laptop, an IBM Thinkpad X61 (more info if necessary.)

Display Issue: When I start the laptop out of its docking station, the screen resolution after I log in is just fine. If I start it in the docking station, which has a second display, then the resolution is not set correctly for either screen and will be 1024x768 regardless of what I do. If I go to the System Settings and click on Display, the display will automatically change to 1280x1024 on both screens and the cursor will disappear. The change is made before I have the chance to select a resolution. I have tried several things to fix the problem: 1) eliminate all but one screen mode from xorg.conf 2) delete xorg.conf and let automatically regenerate 3) copy saved xorg.conf.original to xorg.conf and 4) copy xorg.conf.sabayon to xorg.conf -- None of these fixed the problem of wrong screen resolution at login and disappearing cursor but I can fix the display problem with this command:
Code: Select all
xrandr --output LVDS --mode 1280x1024 --output VGA --mode 1280x1024

It's still wrong at login, but that fixes it without the cursor disappearing. I don't know if this is an X, KDE or Sabayon problem.

Mount Issue: I have network disks I would like to automatically mount. I can easily mount them on the command line with
Code: Select all
sudo mount 192.168.1.103:/home/arkh /home/arkh
sudo mount 192.168.1.103:/home/video /home/video
sudo mount 192.168.1.103:/home/music /home/music

I have tried adding these mounts to my /etc/fstab using
Code: Select all
192.168.1.103:/home/arkh /home/arkh nfs rsize=8192,wsize=8192,timeo=14,intr
192.168.1.103:/home/music /home/music nfs rsize=8192,wsize=8192,timeo=14,intr
192.168.1.103:/home/video /home/video nfs rsize=8192,wsize=8192,timeo=14,intr

but the mounts do not happen. I suspect it is a permission problem but don't know for sure. (It works with Kubuntu.) - It could also be a problem with the boot up order because the connection to the network is wireless and maybe the system tries to mount the shares before the wireless connection has been established. Again, though, I can easily fix the problem on the command line and not worry about doing things the way they're supposed to be done.

The easiest solution for me would be to write a script containing the commands I've described above that would run automatically when I log in (and, that would be a useful knowledge anyway) but will certainly consider better solutions if anyone has them to offer.

If you need any other information, please ask me for it.

BTW, I love Sabayon 4 and use it for my work computer. It and KDE 3.5 are great. This is my 4th or 5th attempt to deal with KDE 4 and it's going better than before, I'm even beginning to enjoy the slower pace of things. -- One thing I liked about Sabayon 4 was the "everything including the kitchen sink" package with everything in it. Would enjoy a Sabayon 5 package like that too.

Thanks,

John (Nino's my dog)
ninodog
Baby Hen
 
Posts: 13
Joined: Tue Apr 14, 2009 3:32

Re: run a script at login (for display & mount issues)

Postby ninodog » Thu Dec 03, 2009 23:50

OK, I've solved some of this. I've written the script, made it executable and tested it, successfully. Can't manage to get it to run at startup or it's not running successfully at that time. If I run it after logging in, it will do what I want (change screen resolutions and mount NFS shares.)
I wrote the file, which I named "jph091203-startup" and put it in the /etc/init.d directory.
Code: Select all
sudo nano /etc/init.d/jph091203-startup

and put these lines of text in it
Code: Select all
xrandr --output LVDS --mode 1280x1024 --output VGA --mode 1280x1024
sudo mount 192.168.1.103:/home/arkh /home/arkh
sudo mount 192.168.1.103:/home/video /home/video
sudo mount 192.168.1.103:/home/music /home/music

Then I made the file executable
Code: Select all
sudo chmod +x /etc/init.d/jph091203-startup

Then I tested it
Code: Select all
/etc/init.d/jph091203-startup

and it did what I wanted - change screen resolution and mount NFS shares
Then I set it to run at startup (or attempted to)
Code: Select all
sudo rc-update add jph091203.startup default

and then I tested it by rebooting.
After booting and logging in, there were no changes - the shares were not mounted and the screens were not set right.
So, I ran the script manually:
Code: Select all
/etc/init.d/jph091203-startup

and it mounted the volumes and changed screen resolutions but the cursor disappeared! Grrrrr.
running
Code: Select all
xrandr --output LVDS --mode 1280x1024 --output VGA --mode 1280x1024
restored the cursor. (I used this command because it was in my history.)
Any thoughts? re 1) making script run automatically and 2) the disappearing cursor?
Thanks again for any suggestions.
John
ninodog
Baby Hen
 
Posts: 13
Joined: Tue Apr 14, 2009 3:32

Re: run a script at login (for display & mount issues)

Postby smb96 » Fri Dec 04, 2009 1:03

for your 2. problem you can try to add nfs or nfsmount to your boot runlevel. I am not sure which one. But you can try

Code: Select all
eselect rc add nfs boot


or

Code: Select all
eselect rc add nfsmount boot
smb96
Simple Hen
 
Posts: 70
Joined: Mon Nov 23, 2009 11:44

Re: run a script at login (for display & mount issues)

Postby Fitzcarraldo » Fri Dec 04, 2009 10:22

ninodog, why not just launch your script by calling it from /etc/conf.d/local? Much easier.

Code: Select all
acertm8215 ~ # cat /etc/conf.d/local
# Here is where you can put anything you need to start
# that there is not an init script for.

local_start() {
        # This is a good place to load any misc programs
        # on startup (use &>/dev/null to hide output)

# Following line inserted by Fitzcarraldo to make sure Bluetooth for KDE 4 works:
udevadm trigger --subsystem-match=bluetooth

        # We should always return 0
        return 0
}

local_stop() {
        # This is a good place to unload any misc.
        # programs you started above.

        # We should always return 0
        return 0
}
acertm8215 ~ #
User avatar
Fitzcarraldo
Sagely Hen
 
Posts: 7987
Joined: Sat Mar 10, 2007 5:40
Location: United Kingdom

Re: run a script at login (for display & mount issues)

Postby ninodog » Fri Dec 04, 2009 17:36

smb96 & Fitzcarraldo - thank you for your input. I appreciate it.

ninodog, why not just launch your script by calling it from /etc/conf.d/local? Much easier.

Well, because I didn't know about it. I take it /etc/conf.d/local loads automatically. I'll give it a try in the next day or two. Thanks.
ninodog
Baby Hen
 
Posts: 13
Joined: Tue Apr 14, 2009 3:32


Re: run a script at login (for display & mount issues)

Postby Marius » Sat Dec 05, 2009 23:05

All the answers to ninidog's original post are about executing a script at boot time, not at login. If he indeed wants to execute any command at login, just put it in the .login file in the home directory. This is precisely the place for such commands.

I generally prefer not to tinker with the boot sequencence. It is very easy to forget what one has done and where, and this often leads later, after subsequent system updates, to hard to track down boot problems.
Marius
Simple Hen
 
Posts: 82
Joined: Thu Nov 01, 2007 5:48
Location: Berkeley, California

Re: run a script at login (for display & mount issues)

Postby Fitzcarraldo » Sun Dec 06, 2009 1:45

Marius wrote:All the answers to ninidog's original post are about executing a script at boot time, not at login. If he indeed wants to execute any command at login, just put it in the .login file in the home directory. This is precisely the place for such commands.

Try it with Sabayon Linux.

Marius wrote:I generally prefer not to tinker with the boot sequencence. It is very easy to forget what one has done and where, and this often leads later, after subsequent system updates, to hard to track down boot problems.

/etc/conf.d/local is specifically intended to execute users' commands at the end of the boot process. There's nothing wrong with using it for that, it is not "tinkering with the boot sequence" and it's no easier to forget than a hidden file in a home directory. Many Gentoo/Sabayon users use it and it's well-known in the Gentoo community. (SL is a customised version of Gentoo.)

$ cat /etc/conf.d/local
# Here is where you can put anything you need to start
# that there is not an init script for.

local_start() {
# This is a good place to load any misc programs
# on startup (use &>/dev/null to hide output)

# We should always return 0
return 0
}

local_stop() {
# This is a good place to unload any misc.
# programs you started above.

# We should always return 0
return 0
}

If ninodog actually wants to run his script upon login to his specific user account, then the easier place to put it would be in the directory ~/.kde4/Autostart (~/.kde/Autostart if he has created a symlink to ~/.kde4). This is the standard mechanism provided by KDE (which is what he is using) for launching user's applications, scripts and Desktop Config files at login. Google throws up examples of how to start scripts at login in the case of Gentoo/Sabayon Linux; here's just one: Bash script not running on shell login.

Thinking about what ninodog is trying to do, viz. mount disks which he was unable to achive via the (system-wide) /etc/fstab file, this could be done without problem in /etc/conf.d/local. However, I think xrandr should be executed after he has logged in, so the best place to put it would be in the ~/.kde4/Autostart directory. He can use Dolphin or Konqueror to navigate to the ~/.kde4/Autostart directory, right-click on the window and select Create New > Link to Application... from the pop-up menu. Then he can click on the Application tab and enter the xrandr command in the Command box, fill in the other boxes as desired, and click on the icon on the General tab to select a nice icon of his choice. Alternatively, if ninodog wants to kick off his shell script then he could instead put sh /home/ninodog/jph091203-startup in the Command box.

(There is yet another way for setting the screen resolution: /home/ninodog/.kde4/share/config/krandrrc (see [SOLVED] KDE4.1 Display Settings not saved in Kubuntu). It would possibly also work if he put the xrandr command in the .xinitrc file instead.)
User avatar
Fitzcarraldo
Sagely Hen
 
Posts: 7987
Joined: Sat Mar 10, 2007 5:40
Location: United Kingdom

Re: run a script at login (for display & mount issues)

Postby Marius » Sun Dec 06, 2009 11:45

Fitzcarraldo wrote:
Marius wrote:All the answers to ninidog's original post are about executing a script at boot time, not at login. If he indeed wants to execute any command at login, just put it in the .login file in the home directory. This is precisely the place for such commands.

Try it with Sabayon Linux.


Well, this has nothing to do with Sabayon Linux but with what shell one is using: coming to Linux from Berkeley UNIX/SUN OS, I have been using csh and more recently tcsh (which means for the last 15 years). The latter is by the way excellent; I use bash mostly for scripting.

Fitzcarraldo wrote:
Marius wrote:I generally prefer not to tinker with the boot sequencence. It is very easy to forget what one has done and where, and this often leads later, after subsequent system updates, to hard to track down boot problems.

/etc/conf.d/local is specifically intended to execute users' commands at the end of the boot process. There's nothing wrong with using it for that, it is not "tinkering with the boot sequence" and it's no easier to forget than a hidden file in a home directory. Many Gentoo/Sabayon users use it and it's well-known in the Gentoo community. (SL is a customised version of Gentoo.)


I know, I know. Still, what you propose is not for user's commands but for superuser's commands. My advice is still the same: touch the system internals as little as you must or be prepared to pay the consequences later unless you simply enjoy learning how Linux works. I have been doing that for the last 10 years, and 15 more years with UNIX.

Another thing is that though I own 7 computers myself, on most computers I use I have no superuser privileges. And all of them run under Linux or UNIX.


Your response to my post, Fitzcarraldo, provides me with an opportunity i have been waiting for, to openly express my admiration at your good will, readiness to help others, the quality and clarity of provided information, and last but not least---your patience. Sabayon Linux forum is blessed to have somebody like you among its most active members. I would say that if the quality of the Sabayon's look-and-feel (Thanks to Ian Whyman!) was the first reason why I switched from Fedora, then your posts in the forum would be the second.
Marius
Simple Hen
 
Posts: 82
Joined: Thu Nov 01, 2007 5:48
Location: Berkeley, California

Re: run a script at login (for display & mount issues)

Postby Fitzcarraldo » Sun Dec 06, 2009 13:18

Firstly, thank you for your kind words, Marius. My point regarding .input was that, if ninodog did as you suggested then it would not have worked. Mind you, neither would my first suggestion of executing the xrandr command via /etc/conf.d/local. I doubt he would be interested in changing shells, and there is no need to do so in order to achieve his goal. Haven't used the C shell myself since I used Unix professionally in the early 1990s, when I also used the Korn shell. Never tried the TENEX C shell, though.
User avatar
Fitzcarraldo
Sagely Hen
 
Posts: 7987
Joined: Sat Mar 10, 2007 5:40
Location: United Kingdom

Next

Return to Beginners|Newbies Area

Who is online

Users browsing this forum: No registered users and 1 guest