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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
06-29-2004, 10:23 PM
|
#1
|
|
LQ Newbie
Registered: Jun 2004
Posts: 6
Rep:
|
Need Help With Bash Scripts
So, first as an overview, this is what i would like my slack box to do:
-upon pressing power, it will automatically login as "student"
-x is started immediately with xmms run
-upon exiting xmms, x is closed
-user presented with 3 options:
1) return to xmms (easy enough, just startx)
2) logout
3) shutdown now
----------------------------------------------------------------------------------
now, i will go over what i have tried so far, (i have made the shutdown command global, that is not the problem).
.bash_profile
============
alias shutdown='sudo /sbin/shutdown'
startx
.xinitrc
============
xmms
testscript
============
#!/bin/bash
echo "1 - Return to XMMS"
echo "2 - Logout"
echo "3 - Shutdown"
while true; do
read -s n1 var
if ( "$var" == "1" )
var=0
startx
elif ( "$var" == "2" )
logout
elif ( "$var" == "3" )
shutdown now
fi
done
------------------------------------------------------------------------------------------------
now i have tried calling testscript from inside .bash_profile, but it gives me a read error (this read error seems to occur when i try to execute this after leaving x)
if i add either the command "logout" or "shutdown now" after "startx in .bash_profile, they execute, but this is no good to me, as it leaves the user no options
when commenting out .bash_profile, and just going ./testscript, it tells me that shutdown is not a command, and that i must use "exit" not "logout", but (now correct me if im wrong), but it seems that by running a script you open a bash within bash? so by exiting, i am not logging out, only exiting the script?
------------------------------------------------------------------------------------------------
again, that is just what i have tried, and it has yeilded mixed but ultimately confusing results. I'm certian I'm at fault, if someone could just tell me how, i would really appreciate it.
ALSO, as far as autologging in as a user, i got that to work with redhat 9.0 once upon a time, though i now forget how, so if someone could say how that is done in Slackware 10.0, i would appreciate it, but i think that is easy enough, i can probably figure that one out on my own, solving (or helping me solve) the above outlined problem is all im really after.
thanks
Last edited by the_woelf; 06-30-2004 at 08:24 AM.
|
|
|
|
06-30-2004, 12:27 AM
|
#2
|
|
LQ Addict
Registered: Dec 2003
Location: Maine, USA
Distribution: Slackware/SuSE/DSL
Posts: 1,320
Rep:
|
#!/bin/sh
xmms
echo "1 - Return to XMMS"
echo "2 - Logout"
echo "3 - Shutdown"
read var
case $var in
3) sudo halt ;;
2) exit ;;
*) xmms ;;
esac
If you have your system set up with xdm, gdm, or kdm, I think you could use the above or something similar in place of a window manager....everything in one file.
|
|
|
|
06-30-2004, 08:44 AM
|
#3
|
|
LQ Newbie
Registered: Jun 2004
Posts: 6
Original Poster
Rep:
|
that didnt work very well. i changed to runlevel 5 (is that what you meant by set up with xdm,gdm, etc) (i have x windows, gnome and kde installed, if thats what you meant?)
if "1" -> wont run because youre not in x
if "2" -> command not found
if "3" -> commmand not found
i add you script to .bash_profile, is this the problem?
thanks
|
|
|
|
06-30-2004, 09:07 AM
|
#4
|
|
LQ Addict
Registered: Dec 2003
Location: Maine, USA
Distribution: Slackware/SuSE/DSL
Posts: 1,320
Rep:
|
Maybe. You don't need .bash_profile or any startup script if you use something like the above script in place of a window manager. I didn't test it, though, so the syntax may be incorrect.
What I was trying to accomplish was this:
1) kdm, or whatever graphical session manager you have configured, is set to automatically log you in using this script in place of a window manager or desktop environment. I just boot into a text runlevel, though...not sure how to set up kdm to auto login.
2) The script runs, launching xmms.
3) If xmms is closed, the script continues with a choice of options. Choosing anything but 2 or 3 reloads Xmms.
I just whipped up the script off the top of my head, and didn't test it...now looking at it again, even if it does happen to work, it will only work once, because I didn't loop back to the biginning of the script after xmms is re-run.
It may need to be something like this:
#!/bin/sh
start_xmms () {
xmms
echo "1 - Return to XMMS"
echo "2 - Logout"
echo "3 - Shutdown"
read var
case $var in
3) sudo halt ;;
2) exit ;;
*) start_xmms ;;
esac
}
start_xmms
Again, syntax may be a little off, and I've never used numbers in a case, so that may be causing trouble.
Edit: Shoot....this doesn't give you a terminal in which to enter options....I'll have to rethink that.
Sorry for wasting your time.
Last edited by mikshaw; 06-30-2004 at 09:13 AM.
|
|
|
|
06-30-2004, 09:09 AM
|
#5
|
|
Senior Member
Registered: Sep 2003
Location: The Netherlands
Distribution: Gentoo (main); SuSE 9.3 (fallback)
Posts: 1,607
Rep:
|
To the best of my recollection, Slack doesn't use runlevel 5 for "automatically start an X-based DM ( Display Manager, or more commonly "login manager"). When I was using Slack, runlevel 3 was the default, and I think runlevel 4 was the "x runlevel"-- if you look at /etc/inittab, the very start (of my backed-up one, at least says):
Quote:
# These are the default runlevels in Slackware:
# 0 = halt
# 1 = single user mode
# 2 = unused (but configured the same as runlevel 3)
# 3 = multiuser mode (default Slackware runlevel)
# 4 = X11 with KDM/GDM/XDM (session managers)
# 5 = unused (but configured the same as runlevel 3)
# 6 = reboot
|
Putting such a script in .bash_profile wouldn't help you, as afaik .bash_profile doesn't do that anyway (meaning, serve the function of running this script).
What mikshaw meant was that if you use such a DM as KDM, GDM or XDM, you should add this script to the "Sessions" folder, choose it from the Sessions menu when logging in, and make it the default session for the user when asked.
For GDM (which is the display manager I use under all distros I've ever used), you would want to:
1) Open a text editor as root.
2) Browse to /etc/X11/dm/Sessions and open one of the *.desktop files in the editor.
3) Edit the file to reflect a new name, description, and change the "Application=" field to point to the script.
4) Save the file as whatever.desktop and exit the text editor.
Don't forget to make the script executable.
When you reboot, the new Session type should appear in the GDM sessions list, you can choose it, and you will be asked if you want to make it the default session after filling in your normal login details. This will allow you to retain the other sessions you may have installed (if you choose nothing from the login Sessions menu, the default will load, if you want to run a KDE session, you would then choose KDE from the Sessions menu.
Afaik, this should also work for KDM and XDM, as they both read the session list from /etc/X11/dm/Sessions as well.
GDM also allows you to set up a "custom" session, which will load the session found in ~/.xinitrc (which is on my system a symlink to ~./xsession). The traditional manner of creating a custom session is in fact to use ~/.xsession, but on my system, this is already used by ROX, so I had to create an additional session to run the script that I use to load Openbox3 (which is my default session, but runs from a script in order to load several programs automatically at startup).
Hope this helps explain things.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 01:10 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|