LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-28-2003, 10:57 AM   #1
drsanchez
LQ Newbie
 
Registered: Mar 2003
Distribution: RedHat 8.0, Knoppix
Posts: 4

Rep: Reputation: 0
Basic shell stuff


I think it's my first post on this forum--be gentle! Here's a frivolous question but the info I get will certainly be useful for other applications: I've written a very basic shell script that looks like:

#!/bin/sh
cp ~/ogg/stan_ridgway_anatomy.playlist ~/.xmms/xmms.m3u
xmms --play &


The script just copies a playlist for xmms to its default, then plays xmms in the background. While it's playing, I sometimes stop (not the whole application, just the 'stop' button on the player) and start another script. I have a different shell for each playlist. The problem is that stopping the playlist and starting another doesn't exit out of the original shell script. When I list my processes, after stopping and starting a few shells, I get 5 or 6 instances of xmms running at once. So, the question: how do I play around with all my shells, exiting one before starting another, without going to the command line and typing "kill -9 <process number>" ??
 
Old 05-28-2003, 11:39 AM   #2
slightcrazed
Member
 
Registered: May 2003
Location: Lisbon Falls, Maine
Distribution: RH 8.0, 9.0, FC2 - 4, Slack 9.0 - 10.2, Knoppix 3.4 - 4.0, LFS,
Posts: 789

Rep: Reputation: 30
If I may, this seems like a silly way to start a playlist in Xmms, but, the best way I can think would be to add a couple lines to your script at the begining to check if xmms is already running, kill it if it is, and then run the rest of the script to start xmms and play it again. I suck at scripting, so I wont even try to write an example, but I'm sure one of the Guru's can come up with something.

slight
 
Old 05-28-2003, 11:56 AM   #3
drsanchez
LQ Newbie
 
Registered: Mar 2003
Distribution: RedHat 8.0, Knoppix
Posts: 4

Original Poster
Rep: Reputation: 0
I would have to agree about the silliness of this exercise, but I would like it to grow to a point where I could be working on something, decide that I really must hear Beck's latest album right now, and type 'run seachange' from the command line to fire it off.

In reality, I just wanted to start simple with shells. Back in my DOS days, I discovered batch files were the way to go. Now, I discovered that shells can do even more.

So, now that I know something like this can be done, I'll STW and RTM (I just left out the F's--no need to get nasty with my own self) to find out how. Any tips in the meanwhile are appreciated.
 
Old 05-28-2003, 12:03 PM   #4
0x4B
Member
 
Registered: May 2003
Location: Nashville TN, USA
Distribution: Debian (I'm unstable)
Posts: 117

Rep: Reputation: 15
the easy option is to add
killall xmms
at the beginning of the script, this will kill every instance of xmms you have running

I'm assumint that there are multiple instances of xmms, but not of the shell script itself (it should be exiting after starting xmms)

you can tell a running instance of xmms to stop and start (and even specify a specific instance). It doesn't look like you can have it reload the playlist, but it might automatically (or you can try to use kill SIGHUP to have it reload)
 
Old 05-28-2003, 12:08 PM   #5
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
How about "exec xmms --play &"?
In your Bash shell type "help exec" for more.
 
Old 05-28-2003, 12:11 PM   #6
nxny
Member
 
Registered: May 2002
Location: AK - The last frontier.
Distribution: Red Hat 8.0, Slackware 8.1, Knoppix 3.7, Lunar 1.3, Sorcerer
Posts: 771

Rep: Reputation: 30
See the man page for killall . It basically lets you kill ( or send a signal to a process ( or a bunch of those ) if you know the process name. killall xmms in your case.

Also as a simple improvement for your script, I would suggest the use of the select construct in bash so you can use one shell script to copy ( not really, I would soft link it ) to the default play list.

if you have all your playlists in say ~/lists

select MYCHOICE in $(ls ~/lists)
do
ln -sf ~/lists/$MYCHOICE ~/.xmms/xmms.m3u
done.

or something similar. HTH
 
Old 05-28-2003, 12:22 PM   #7
slightcrazed
Member
 
Registered: May 2003
Location: Lisbon Falls, Maine
Distribution: RH 8.0, 9.0, FC2 - 4, Slack 9.0 - 10.2, Knoppix 3.4 - 4.0, LFS,
Posts: 789

Rep: Reputation: 30
OK, this is probably the most inefficient way to do it, but I would:


#!/bin/sh
jobs > ~/jobfile
jobs=$(cat ~/jobfile | grep xmms)
if [ "$jobs" -eq ""]; then
echo "xmms not running"
else
killall -9 xmms
fi
cp ~/ogg/stan_ridgway_anatomy.playlist ~/.xmms/xmms.m3u
xmms --play &


I am probably the sloppiest script writer in the cosmos, and I can't even guarantee that the syntax above is correct, but it should at least give you an idea of where to start.

slight
 
Old 05-28-2003, 12:32 PM   #8
drsanchez
LQ Newbie
 
Registered: Mar 2003
Distribution: RedHat 8.0, Knoppix
Posts: 4

Original Poster
Rep: Reputation: 0
Thanks for the tips. I'm at work on my windows machine so I have to wait til I get home to try this out. By analogy, it sounds like the 'exec' command is similar to DOS's 'start' command in that it seems to spawn another process, then disconnect itself from the shell/bat file so that the spawned process can be messed with on its own.

Also, in reading the man page for 'killall', it sounds like I need to be a super-user to kill processes, right?

For the soft link, xmms uses the file xmms.m3u as the default. So shouldn't the link be the other way? That is, linking xmms.m3u to $mychoice, then running xmms?

Thanks again.
 
Old 05-28-2003, 12:40 PM   #9
0x4B
Member
 
Registered: May 2003
Location: Nashville TN, USA
Distribution: Debian (I'm unstable)
Posts: 117

Rep: Reputation: 15
the first option to ln is the source (the original file) and the second (optionally) is the name of the link to create. the way nxny presented it will create a link to ~/lists/$MYCHOICE called ~/.xmms/xmms.m3u
 
Old 05-28-2003, 12:42 PM   #10
drsanchez
LQ Newbie
 
Registered: Mar 2003
Distribution: RedHat 8.0, Knoppix
Posts: 4

Original Poster
Rep: Reputation: 0
See? My 3-line shell has now given me a lesson (or at least homework) in:

the 'if' command,
grep
pipes/redirection
being super-user
killing stuff
soft links

all of which is pretty new to me. So, give me a couple weeks to master it, then I'll be happy.
 
Old 05-28-2003, 12:49 PM   #11
slightcrazed
Member
 
Registered: May 2003
Location: Lisbon Falls, Maine
Distribution: RH 8.0, 9.0, FC2 - 4, Slack 9.0 - 10.2, Knoppix 3.4 - 4.0, LFS,
Posts: 789

Rep: Reputation: 30
Shell scripting basics


Great place to start to learn the basics.

slight
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell Scripting (For my wireless card stuff) chiefreborn Linux - General 9 08-31-2005 06:32 PM
Install my basic Linux stuff--Linspire 4 lectraplayer Linux - Software 13 07-10-2005 08:46 PM
basic shell script help lin00b Linux - Newbie 2 10-08-2004 11:32 PM
Really basic stuff here gauge73 Linux - Newbie 5 02-19-2004 09:18 AM
Basic security stuff mymojo Linux - Security 9 11-26-2003 11:49 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:07 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