LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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 06-29-2004, 10:23 PM   #1
the_woelf
LQ Newbie
 
Registered: Jun 2004
Posts: 6

Rep: Reputation: 0
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.
 
Old 06-30-2004, 12:27 AM   #2
mikshaw
LQ Addict
 
Registered: Dec 2003
Location: Maine, USA
Distribution: Slackware/SuSE/DSL
Posts: 1,320

Rep: Reputation: 45
#!/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.
 
Old 06-30-2004, 08:44 AM   #3
the_woelf
LQ Newbie
 
Registered: Jun 2004
Posts: 6

Original Poster
Rep: Reputation: 0
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
 
Old 06-30-2004, 09:07 AM   #4
mikshaw
LQ Addict
 
Registered: Dec 2003
Location: Maine, USA
Distribution: Slackware/SuSE/DSL
Posts: 1,320

Rep: Reputation: 45
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.
 
Old 06-30-2004, 09:09 AM   #5
motub
Senior Member
 
Registered: Sep 2003
Location: The Netherlands
Distribution: Gentoo (main); SuSE 9.3 (fallback)
Posts: 1,607

Rep: Reputation: 46
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.
 
  


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
little help with bash scripts sniff Programming 2 10-26-2005 05:17 PM
bash scripts hoffmanyew Programming 3 08-11-2005 01:27 AM
Bash Scripts Skute Programming 7 03-12-2004 10:17 AM
$? in Bash scripts clinton Linux - Newbie 4 02-20-2004 11:15 AM
Bash scripts? BajaNick Programming 3 07-05-2003 10:13 PM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration