LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-20-2009, 08:01 AM   #1
uncle-c
Member
 
Registered: Oct 2006
Location: The Ether
Distribution: Ubuntu 16.04.7 LTS, Kali, MX Linux with i3WM
Posts: 299

Rep: Reputation: 30
Bash script not running on shell login.


Hi there,

I've written a simple shell script to run each time I login ( via KDM ) into my desired environment of choice, be it fluxbox, kde or enlightenment.
This script is pretty self explanatory. It tests to see which window manager is running and then executes a program if a statement is true, in this case if the window manager I am running is enlightenment.

Code:
wm=`wmctrl -m | awk ' /Name/ { print $2 }'`
if [ $wm = Enlightenment ] ; then fbsetbg -u feh -f ~/backgrounds/image.jpg ; fi
The script was named wmanager, I made it executable using chmod u+x and placed it in my /home/user/bin directory which was also in my $PATH so I could execute the script from any location. I tested this out and the script executed with no problem.

I added this script to my .bash_profile file, logged out and logged back in into my GUI environment ( via KDM). Unfortunately, the script did not run. I changed its name to wmanager.sh incase that was the problem but still no luck. Have I put the pointer to the script in the correct file ? I'm sure it should not be in the .bashrc. Perhaps there could be a problem with the script itself ? However, it runs fine when I execute it from command line. Any help would be greatly appreciated.

Cheers,
Uncle-c
(Fedora 9)
 
Old 02-20-2009, 08:29 AM   #2
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
Use quotes when dealing with strings that way, otherwise the script will fail if for some reason the string remains empty:

Code:
wm=`wmctrl -m | awk ' /Name/ { print $2 }'`
if [ "$wm" = "Enlightenment" ] ; then fbsetbg -u feh -f ~/backgrounds/image.jpg ; fi
Quote:
I added this script to my .bash_profile file, logged out and logged back in into my GUI environment ( via KDM).
~/.bash_profile is sourced by bash, and kdm is not bash, and your wm is not bash either. This file will only be used by bash, and when bash is started as an interactive login shell (not in xterm, for example). Since you are login in kdm and not directly into a shell, such thing like a login shell isn't even invoked on your system (in other words, all the shells you use are non-login ones, those which use ~/.bashrc, and not ~/.bash_profile).

Anyway, since you want this to be run for every wm, I guess that the place you should be looking at is kdm. But there's one fundamental problem: this must be run after the wm has started (otherwise it makes no sense to try to detect the wm name, duh).

KDM probably uses some kind of session script to launch the wms, if I had it installed I could investigate, but I haven't got it.

Another less generic approach would be to launch it from the wm. All the major wms and desktops provide a way to autolaunch scripts and programs at startup. But then the whole point of having a generic script is defeated.

So, I'd investigate around kdm. Maybe you could even integrate your script inside the session script for kdm, whatever it is.

Last edited by i92guboj; 02-20-2009 at 08:34 AM.
 
Old 02-20-2009, 08:32 AM   #3
JulianTosh
Member
 
Registered: Sep 2007
Location: Las Vegas, NV
Distribution: Fedora / CentOS
Posts: 674
Blog Entries: 3

Rep: Reputation: 90
.bash_profile is executed for login shells
.bashrc is executed for interactive non-login shells.

Neither will execute when you login to a GUI. Other than putting the command as a session in gnome, I dont know how to help you more.
 
Old 02-20-2009, 09:07 AM   #4
/bin/bash
Senior Member
 
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802

Rep: Reputation: 47
Well you could put it in /etc/init.d. Then you add a symlink to it in the runlevel directory for your X session. Most distros use runlevel 5 for X but a few use 4. And you need to give it a name so it executes after kdm. To do that you need to look in runlevel directory to find SXXkdm (the XX is a number that controls the order in which scripts are executed.) Just make the symlink a higher number than the SXXkdm link.

So you would end up doing something like this as root:

# cp /home/user/bin/somescript /etc/init.d
# ln -s /etc/rc5.d/S88somescript /etc/init.d/somescript

NOTE: This will cause the script to execute for any user. If that is undesired you would only need to add a test in the script to make it not execute unless you are the $USER. Or have it grab the image from $HOME/bgimage.jpg then any user could benefit by placing their own $HOME/bgimage in their home directory.

Last edited by /bin/bash; 02-20-2009 at 09:16 AM. Reason: Added NOTE:
 
Old 02-20-2009, 09:34 AM   #5
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
Quote:
Originally Posted by /bin/bash View Post
Well you could put it in /etc/init.d. Then you add a symlink to it in the runlevel directory for your X session. Most distros use runlevel 5 for X but a few use 4. And you need to give it a name so it executes after kdm. To do that you need to look in runlevel directory to find SXXkdm (the XX is a number that controls the order in which scripts are executed.) Just make the symlink a higher number than the SXXkdm link.
Except that he needs to enforce that it's run AFTER the wm has been started, which is more difficult. I don't think that init.d is the right place for this.

In kdm it should be doable and easy to do. You just need to find from where does it launch the wm, sleep for a couple of seconds and then run his code.
 
Old 02-20-2009, 12:48 PM   #6
uncle-c
Member
 
Registered: Oct 2006
Location: The Ether
Distribution: Ubuntu 16.04.7 LTS, Kali, MX Linux with i3WM
Posts: 299

Original Poster
Rep: Reputation: 30
Thanks a lot gents. On rethinking perhaps my requirements could have been better described.
I actually want to run the following command when and ONLY when I use the enlightenment wm :

Quote:
fbsetbg -u feh -f ~/background.jpg
I am using Fedora 9 and on searching have found some interesting files in the /usr/share/xsessions directory :

Quote:
[unclec@localhost ~]$ cd /usr/share/xsessions
[unclec@localhost xsessions]$ ls
enlightenment.desktop fluxbox.desktop kde.desktop
[unclec@localhost xsessions]$ cat enlightenment.desktop
[Desktop Entry]
Encoding=UTF-8
Name=Enlightenment
Comment=Log in using Enlightenment (Version 0.16.999.050)
Type=XSession
Icon=/usr/share/enlightenment/data/images/enlightenment.png
Exec=/usr/bin/enlightenment_start
TryExec=/usr/bin/enlightenment_start
[unclec@localhost xsessions]$
ON my KDM screen I have the choice of fluxbox, enlightenment , kde and failsafe. It seems that enlightenment.desktop is the magic script which starts the enlightenment wm. Could I create an executable script which runs the enlightenment_start executable, then sleeps for a period and then runs the fbsetbg command ? What should be the sleep period between enlightenment_start and fbsetbg ?

THanks
UC
 
Old 02-20-2009, 01:05 PM   #7
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
Quote:
Originally Posted by uncle-c View Post
ON my KDM screen I have the choice of fluxbox, enlightenment , kde and failsafe. It seems that enlightenment.desktop is the magic script which starts the enlightenment wm. Could I create an executable script which runs the enlightenment_start executable, then sleeps for a period and then runs the fbsetbg command ? What should be the sleep period between enlightenment_start and fbsetbg ?

THanks
UC
Yes. You could, though usually it'd be the other way around (bgsetbg and then start the wm). But if all you want is to run a command when starting a given wm, then you are better reading the docs for that wm and using whatever autostart feature it has. Most wm's do.

In kde you'd do that by putting your script at ~/.kde/Autostart/, in fvwm you'd use StartFunction, and in E you might have to look somewhere under ~/.e/ or ~/.enlightenment, depending on the version. However this is from memory and I've never used E for long other than for testing purposes. It might also vary depending if you use E16 or E17.

So, watch out for an autostart feature in your wm. It will be cleaner and easier.

Last edited by i92guboj; 02-20-2009 at 01:13 PM.
 
Old 02-21-2009, 08:04 AM   #8
uncle-c
Member
 
Registered: Oct 2006
Location: The Ether
Distribution: Ubuntu 16.04.7 LTS, Kali, MX Linux with i3WM
Posts: 299

Original Poster
Rep: Reputation: 30
Many thanks i92guboj. I took your advice and ran the command through the enlightenment wm's own autostart / startup feature. Initially I assumed that this was only for dedicated applications and not commands, hence my trepidation. However, I created a new "application" icon which when executed would run the fbsetbg -u feh -f ~/background.jpg command. I set this new application to "run on startup " via a configuration menu and now all is fine. The fbsetbg command only runs when the wm is enlightenment and not when wm = fluxbox/kde.
Thanks for the help.

Regards,
UC
 
Old 02-21-2009, 09:41 AM   #9
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
I am glad that it worked.

Linux is built into pieces and I know that sometimes it can be a bit of a daunting experience to know what concrete piece to use when do something.

Cheers.
 
  


Reply

Tags
bash, enlightenment, script, startup



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
How to check in a script whether the shell is login or non login? frankie_DJ Programming 7 10-21-2015 10:09 AM
root won't use bash as login shell moob8 Linux - Software 9 10-28-2008 10:15 PM
running a shell script which invokes another shell program!!! raghu123 Programming 1 08-04-2008 09:10 AM
login directly to bash shell openart Linux - Newbie 5 10-27-2004 08:05 AM
How to login to bash shell inarin Linux - Newbie 1 10-07-2003 02:45 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:42 AM.

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