Linux - GeneralThis 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
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.
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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:
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>" ??
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.
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.
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)
Distribution: Red Hat 8.0, Slackware 8.1, Knoppix 3.7, Lunar 1.3, Sorcerer
Posts: 771
Rep:
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.
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.
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?
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.