time to start learning bash scripting
Geoffrey S. Mendelson
yellowdog-general@lists.terrasoftsolutions.com
Tue Aug 26 14:55:01 2003
Stefan Jeglinski wrote:
> to start? From my naive world view, I know whether the program is
> running based on
>
> ps caux |grep name_of_program
>
> The name_of_program in question will only ever have one instance in
> the ps list, FWIW.
In this case there will be two.
example:
:~>ps -ax |grep ps
1087 ? S 0:38 ypserv
3746 pts/4 R 0:00 ps -ax
3747 pts/4 S 0:00 grep ps
(I should have picked something other than ps)
I use the following bash code to see if more than one copy of a program
called cabelstart is running:
CPS=`ps -ax | grep cablestart | grep -cv grep `
if [ "2" == "$CPS" ] ; then
echo "ok starting cable connection"
else
echo "cablestart is already running."
exit
fi
But then I use the following perl code to determine if I need to convert
a file I downloaded or if it's already in the form I need. Note that
the files are called <something>.mp3 and the corrected files have the
same name in a subdirectory called "sony".
#!/usr/bin/perl
$FILES=`ls *mp3`;
@FILES = split('\n',$FILES);
foreach $file (@FILES)
{
printf("checking %s\n",$file);
$out_name = "sony/" . $file;
if ( -r $out_name)
{
printf("file already converted.\n");
next;
}
system("rm temp.wav 2>/dev/null");
system("mpg123 -v -w temp.wav " . $file);
system("lame --resample 32 -b 128 temp.wav " . $out_name);
}
system("rm temp.wav 2>/dev/null");
Geoff.
--
Geoffrey S. Mendelson gsm@mendelson.com 972-54-608-069
Icq/AIM Uin: 2661079 MSN IM: geoffrey_mendelson@hotmail.com (Not for email)
Carp are bottom feeders, koi are too, and not surprisingly are ferrets.