It is currently Tue, 07 Dec 2021 03:09:37 GMT



 
Author Message
 converting csh script to ksh

 Greetings. I have a simple csh script that will rsh
(remsh in the case of HPUX) to machines that are in a
file called MACHINELIST, do a bdf -l, and basically
report any filesystems that are in excess of 70%.
Here it is:

#!/bin/csh
foreach machine (`cat ~ma040985/scripts/MACHINELIST `)
echo $machine
remsh $machine bdf -l | awk 'int($5)>=70{print $5,$6}'
echo ""
end

 I would like to do this in the kornshell. My question
for the newsgroup is; using the above example, how
might I use an input file (like MACHINELIST) as source
for my program? I have noticed a significant difference
between the two shells, i.e., the 'for' command seems
to function differently in ksh and syntax such as '('
is not liked by the ksh. I have reference a couple of
textbooks on the kornshell, but have not been able to
figure it out. For example, these books refer to the
'<' symbol as file I/O redirect and Here-Documents.

--
-----------
Mark Fearer
mfea...@mail.fearernet.com
http://www.**-**.com/



 Sat, 02 Sep 2000 03:00:00 GMT   
 converting csh script to ksh

Mark, yes the ksh "for" syntax is a little different:

#/bin/ksh
for machine in `cat ~ma040985/scripts/MACHINELIST`;
do
echo $machine
remsh $machine bdf -l | awk 'int($5)>=70{print $5,$6}'
echo ""
done

note the ; (semi-colon) at the end of the for line, you need it.

Blaine Owens
bow...@eastman.com



 Sat, 02 Sep 2000 03:00:00 GMT   
 converting csh script to ksh

In article <6em9ft$ok...@emngw1.eastman.com>,
        "Blaine Owens" <bow...@eastman.com> writes:

Not if the do is on the next line. The newline terminates the list
as well.

Christian
--
Christian Bauernfeind
Not speaking for Siemens
Not even working for IBM
e-mail: v2bau...@fishkill.ibm.com



 Sat, 02 Sep 2000 03:00:00 GMT   
 converting csh script to ksh

On Tue, 17 Mar 1998 11:48:11 -0500, "Blaine Owens"

Unless you'd like to win the useless use of cat award,
I'd replace the   `cat filename`   with   $(<filename)

a slightly less efficient option (but more efficient than
the for loop with cat) is a while loop:

while read machine
do
...
done <filename

which is more useful if you're reading multiple fields,
or entire lines with spaces in them.

Hope that helps,
Douglas Wilson



 Sat, 02 Sep 2000 03:00:00 GMT   
 converting csh script to ksh

In the referenced article, mfea...@mail.fearernet.com (Mark Fearer) wrote

The literal translation would be
#!/bin/ksh
for machine in `cat ~ma040985/scripts/MACHINELIST `
do
        echo $machine
        remsh $machine bdf -l | awk 'int($5)>=70{print $5,$6}'
        echo ""
done

but it would be better written as

#!/bin/sh
while read machine
do
        echo $machine
        remsh "$machine" bdf -l
done < /home/ma040985/scripts/MACHINELIST | awk 'NF==1 { machine=$1 ; }
int($5)>=70 {print $5,$6,machine}'

which only generates lines of output that you need, only uses 1 awk
process rather than one per machine, and generally shows that 'sh' is
better than 'csh' as you can pipe out of a while loop.

Icarus



 Sun, 03 Sep 2000 03:00:00 GMT   
 converting csh script to ksh

On 18 Mar 1998 14:53:29 +0700, Icarus Sparry

I measured a speed improvement (from about 12 seconds to under 2;
for just reading a file into a loop & not processing it) by
switching from sh to ksh, and a slight improvement (about .2 more
seconds) by changing the while loop to a for loop:

for machine in $(<filename)
do
 ...
done

JMHO,
Douglas Wilson



 Sun, 03 Sep 2000 03:00:00 GMT   
 converting csh script to ksh

On Wed, 18 Mar 1998 13:32:57 GMT, dgwil...@gte.net (Douglas Wilson)
wrote:

(The while loop has alot more user time but a little less system
time than the for loop).

YMMV,
Douglas Wilson



 Sun, 03 Sep 2000 03:00:00 GMT   
 
   [ 7 post ] 

Similar Threads

1. help converting csh script to ksh?

2. Converting ksh scripts to csh scripts

3. Converting a csh script to ksh??

4. help in learning how to do Bourne shell scripts then converting them to csh scripts

5. need help converting sh scripts to csh scripts

6. Sourcing a csh script from a ksh script

7. csh scripts inside ksh script?

8. ksh to csh and/or csh to ksh

9. exists any program (script) to port csh scripts to ksh

10. converting from csh to ksh


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software