[Gambas-user] need help Script to start program

Ron Onstenk ronstk at ...239...
Fri Nov 12 20:25:21 CET 2004


On Friday 12 November 2004 19:14, Primorec wrote:
| # how to get safe the PID to kill ???
| #TIMID=`ps -ax |grep timidity`
| #echo "proc=${RUN}"
| TIMID=timidity
| 
| here is one way of doing it
| `
| TIMID=`ps -auxw | grep timidity | awk '{print $2}'
| kill -9 $TIMID
| 

Never had awk in mind. Using 'man awk' I understand that it 
is a whole programming language on his own. :)
I was in the neighborhood but missed the awk.
I was looking for something as substr(), left$() but found by 
accident leftpart=${parameter:start:length} as the replacement
for what I had in need.

Still in my script is the way Mike Keehan told. It works well.
After some more edit I have the next as result in timidity.sh
and the midi file association to this script.
Maybe not the most elegant but it does what I wish.
Now I can play midi files on a webpage too, by download to
a temporary directory and play the file. (rip the music :) )
The ftp site can be a copy when I need.

--------------------
#!/bin/sh
# i want to run next line
# timidity.sh /data3/media/audio/midi/gus2/SOFUNKY.MID
# it has to kill running instance(s) before new one start 
# it needs a audio output and is blocked if not killed.
#
# The script is a stub between the *.mid file assoc and the
# program to use it as argument.

TIMRUN=/var/run/timidi
TIMLCK=/var/run/timidi/tim.lock

#no interface
TIMPRG=/usr/bin/timidity 
TIMID=timidity

#the tcl interface
TIMPRG="/usr/bin/timidity-2.11.0p1 -ikt "
TIMID=timidity-2.11.0

#the gnome interface
TIMPRG="/usr/bin/timidity-2.11.3 -iat "
TIMID=timidity-2.11.3

cd ${TIMRUN}

NFIL=$1 # the argument from the command
# NFIL=/data3/media/audio/midi/gus2/SOFUNKY.MID
# NFIL=http://midi.ss.ru/rusmidis/rain_xg.mid

echo "File src='${NFIL:0:7}'"

if [ "${NFIL:0:7}" = "http://" ] ; then
  echo "wget ${NFIL}"
  wget ${NFIL}
  # need to extract the file
  NFIL=`basename ${NFIL}`
  NFIL="${TIMRUN}/${NFIL}"
  echo "got file ${NFIL}"
fi

# get the running file 
OFIL=`cat ${TIMLCK}`

#kill running timidity
killall -TERM ${TIMID}

if [ -f ${TIMLCK} ] ; then
  echo "exit player for ${OFIL}";
  unlink ${TIMLCK};
fi

#mark new file in play
echo ${NFIL} > ${TIMLCK}

# run program with new argument
# should it exit or stay running
# till process is done?
if [ -f ${NFIL} ] ; then 
  ${TIMPRG} ${NFIL} > /dev/nul &
  echo "playing now ${NFIL}"
else
  echo "playing stopped"
fi
-----------------

Thanks for the help and tips.





More information about the User mailing list