Redirected stdin and 'while-loop'

Redirected stdin and 'while-loop'

Post by Mark » Thu, 24 Oct 2002 22:20:10



Hi,
here is what I wanna do

----------------------
#!/bin/ksh
<snip>
while read old_user old_machine
do

    userhome=`ypcat passwd | grep $old_user | cut -d: -f6 | cut -d/ -f3`

    case `exist_account $old_user $old_machine` in

        YES) echo "${old_user} on ${old_machine}  Now on: ${userhome}"
        ;;
        NO) :
        ;;
    esac

done <${old_moves}
-------------------

$old_moves consists of a file with two columns and a lot rows. When I
use 'set -x' it comes to the redirect gives out the value of $old_moves
and stops with "cannot open". So what's wrong with it?

 
 
 

Redirected stdin and 'while-loop'

Post by Bill Marcu » Fri, 25 Oct 2002 00:23:34


On Wed, 23 Oct 2002 15:20:10 +0200,

Quote:> Hi,
> here is what I wanna do

> ----------------------
> #!/bin/ksh
><snip>
> while read old_user old_machine
> do

>     userhome=`ypcat passwd | grep $old_user | cut -d: -f6 | cut -d/ -f3`

>     case `exist_account $old_user $old_machine` in

>         YES) echo "${old_user} on ${old_machine}  Now on: ${userhome}"
>         ;;
>         NO) :
>         ;;
>     esac

> done <${old_moves}
> -------------------

> $old_moves consists of a file with two columns and a lot rows. When I
> use 'set -x' it comes to the redirect gives out the value of $old_moves
> and stops with "cannot open". So what's wrong with it?

The $old_moves file does not exist or does not have read permission.  If
your script has been anywhere near a Windows machine, watch out for ^M
characters at the end of lines, like the line that sets the variable
old_moves.

 
 
 

Redirected stdin and 'while-loop'

Post by Mark » Fri, 25 Oct 2002 14:38:50



>On Wed, 23 Oct 2002 15:20:10 +0200,

>>Hi,
>>here is what I wanna do

>>----------------------
>>#!/bin/ksh
>><snip>
>>while read old_user old_machine
>>do

>>    userhome=`ypcat passwd | grep $old_user | cut -d: -f6 | cut -d/ -f3`

>>    case `exist_account $old_user $old_machine` in

>>        YES) echo "${old_user} on ${old_machine}  Now on: ${userhome}"
>>        ;;
>>        NO) :
>>        ;;
>>    esac

>>done <${old_moves}
>>-------------------

>>$old_moves consists of a file with two columns and a lot rows. When I
>>use 'set -x' it comes to the redirect gives out the value of $old_moves
>>and stops with "cannot open". So what's wrong with it?

>The $old_moves file does not exist or does not have read permission.  If
>your script has been anywhere near a Windows machine, watch out for ^M
>characters at the end of lines, like the line that sets the variable
>old_moves.

No sory. Rights are 644 and it's completely UNIX format. And this is the
look oh the file:
Thu Oct 17 10:39:21 MEST 2002 Username ws-1 ws-2 0
I would be lucky if anyone has a idea.
 
 
 

Redirected stdin and 'while-loop'

Post by Greg Andre » Fri, 25 Oct 2002 23:19:40



Quote:>>>#!/bin/ksh
>>><snip>
>>>while read old_user old_machine
>>>do

    [stuff]

>>>done <${old_moves}
>>>-------------------

>>>$old_moves consists of a file with two columns and a lot rows. When I
>>>use 'set -x' it comes to the redirect gives out the value of $old_moves
>>>and stops with "cannot open". So what's wrong with it?

>>The $old_moves file does not exist or does not have read permission.

>No sory. Rights are 644 and it's completely UNIX format.

You haven't said what is in the ${old_moves} variable.  Does it have
the path to the file and the filename?  Or does it have the contents
of the file?

  -Greg
--

     I have a map of the United States that's actual size.
                                -- Steven Wright

 
 
 

Redirected stdin and 'while-loop'

Post by Mark » Sat, 26 Oct 2002 16:23:52




>>>>#!/bin/ksh
>>>><snip>
>>>>while read old_user old_machine
>>>>do

>    [stuff]

>>>>done <${old_moves}
>>>>-------------------

>>>>$old_moves consists of a file with two columns and a lot rows. When I
>>>>use 'set -x' it comes to the redirect gives out the value of $old_moves
>>>>and stops with "cannot open". So what's wrong with it?

>>>The $old_moves file does not exist or does not have read permission.

>>No sory. Rights are 644 and it's completely UNIX format.

>You haven't said what is in the ${old_moves} variable.  Does it have
>the path to the file and the filename?  Or does it have the contents
>of the file?

>  -Greg

Sorry, here it is.
old_moves=`cat /PROJECT/var/move.tst.tmp`
 
 
 

Redirected stdin and 'while-loop'

Post by Greg Andre » Sat, 26 Oct 2002 17:40:11




>>>>>#!/bin/ksh
>>>>><snip>
>>>>>while read old_user old_machine
>>>>>do

>>    [stuff]

>>>>>done <${old_moves}

>>You haven't said what is in the ${old_moves} variable.  Does it have
>>the path to the file and the filename?  Or does it have the contents
>>of the file?

>Sorry, here it is.
>old_moves=`cat /PROJECT/var/move.tst.tmp`

Change that line to:

  old_moves=/PROJECT/var/move.tst.tmp

and you'll be much happier with the results.

  -Greg
--

     I have a map of the United States that's actual size.
                                -- Steven Wright

 
 
 

1. while-loop stops looping

Hello all,

given the shell script below (it converts a bunch of mp3 files to
wav), the while loop DOES loop when I only echo filenames, but DOES
NOT loop when the conversion program 'ffmpeg' is executed: it
processes only one single file and then stops. So, only echoing gives:

processing 000003.mp3
done
processing 000004.mp3
done
processing 000005.mp3
done
processing 000006.mp3
done
processing 000007.mp3
done
processing 000008.mp3
done
processing 000008.mp3
done
all done

After uncommenting the conversion program I get:

processing 000003.mp3
Input #0, mp3, from '000003.mp3':
  Duration: 00:41:27.3, bitrate: 64 kb/s
  Stream #0.0: Audio: mp3, 44100 Hz, mono, 64 kb/s
Output #0, wav, to '000003.wav':
  Stream #0.0: Audio: pcm_s16le, 16000 Hz, mono, 256 kb/s
Stream mapping:
  Stream #0.0 -> #0.0
Press [q] to stop encoding
size=   77729kB time=2487.3 bitrate= 256.0kbits/s  
0
done
all done

ffmpeg seems to work okay, at least it does not give any error messages and
the conversion has been accomplished succesfully. While debugging, all
mp3 files have been converted to wav now, but I am puzzled about this
behavior. Has anyone an idea what might go wrong? I looks like if the
find job is killed by ffmpeg, how can that be? By the way, I run this
script on linux with suse8.2.

#############################################
#!/bin/sh

DIR=$HOME/whatever
DATA=$DIR/data

find $DATA -follow -name "*.mp3" -print |\
while read i
do
  base=$DATA/`basename $i .mp3`
  if [ ! -s $base.wav ]
  then
    echo "processing $i"
    ffmpeg -i $i -ab 16 -ar 16000 -ac 1 $base.wav
    echo $?
    echo "done"
  fi
done
echo "all done"

-- roeland

2. can't route from en1

3. redirect interactive program's stdin, stdout

4. Modifying Redhat Boot Disk to accomodate PXE initiation and deploying via NFS

5. csh: redirect script's stdin to command?

6. Just curious, how do I do this in Windows?

7. Redirecting to a terminal's stdin

8. copy the output from wc -l <file.txt> into a shell variable.

9. Problem with 'while' loop in 'sh'

10. different behaviour of 'while read' and 'for' loops in bash

11. 4 a5200's in AL_PA 'split loop'

12. 'Socket destroy delayed...' loop on console - what's going on ?

13. namespace of variable in while-loop