Jump to content


Photo
- - - - -

Basic scripting question


  • Please log in to reply
5 replies to this topic

#1 kizzle

kizzle

    SUPR3M3 31337 Mack Daddy P1MP

  • Members
  • 446 posts

Posted 23 November 2003 - 04:54 AM

I fall asleep better when I listen to music. Trouble is I hate waking up to it. I wrote a really simple script that kills xmms in 2 hours but it is very inflexible. Here is the script in it's current sad state, any help would be greatly appreciated in making it more usable.



#!/bin/bash

# I would like to have the script figure out the pid of xmms on it's own
# Xmms has several processes running at once, killing any one of them
# kills them all
echo Killing xmms pid 11470 in 2 hours

# It's optional but it should ask the user how long it should wait
sleep 7200

# Again it should be able to figure out the pid on it's own
kill 11470
# Rather than killing it, is there a way to simply tell xmms to stop playing?

#2 paracord

paracord

    SUP3R 31337

  • Members
  • 170 posts

Posted 23 November 2003 - 05:39 AM

If you're going to sleep at roughly the same time every night, this should work-

#!/bin/bash

killall XMMS

Have cron run it at at the appropriate time.


But if sleepy time is going to be variable, something like this might work-


#!/bin/bash

sleep $1
killall XMMS

Name it whatever you like, but for the sake of demonstration I'll call it "XmmsGenocide".

It's usage would be: XmmsGenocide "sleep_time_in_seconds"


Hope this helps. If not, call me a faggot and I'll try to get it right next time.

#3 kizzle

kizzle

    SUPR3M3 31337 Mack Daddy P1MP

  • Members
  • 446 posts

Posted 23 November 2003 - 10:01 PM

I've made the script much more usefull. Thanks for the help!

#!/bin/bash
echo Stopping current song xmms is playing in $1 minutes
sleep $1m
xmms -u #pauses the current song
echo Done

#4 feend

feend

    microphone commander

  • Members
  • 497 posts

Posted 24 November 2003 - 07:25 PM

Hope this helps. If not, call me a faggot and I'll try to get it right next time.

paracord you sexy bish.

#5 Zapperlink

Zapperlink

    "I Hack, therefore, I am"

  • Agents of the Revolution
  • 951 posts
  • Country:
  • Gender:Not Telling

Posted 25 November 2003 - 06:37 PM

lol :lol:

#6 BoBB

BoBB

    SUP3R 31337

  • Members
  • 155 posts

Posted 26 November 2003 - 09:11 AM

In case anyone wants to know how to do what he originally wanted I have a script that does just that
#!/bin/bash
PID="`ps -aux | grep [s]ystemlog | awk '{print $2}'`"
kill $PID

you can change it to grep whatever you want, the [] keeps grep from matching its own process, if more than one process matches the string it will kill them all. Also you could expand on it more taking command line arguments for what process to search for and kill and how long to wait.




BinRev is hosted by the great people at Lunarpages!