Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 379
  • Last Modified:

Korn shell script

I wrote the following script, but it is not working when I run it as root. It is supposed to read one line at a time and process each line. As root it only reads one line. As my userid it reads each line, but can't rsh to the computer name listed in the file it reads. Any suggestions?
#!/usr/bin/ksh
while read dev
do
   if [[ $dev != lastrecord ]]
   then
     echo "-"$dev"-"
     var1=`rsh -l root $dev lpstat -d | awk '{print $4}'`
     echo $dev"  "$var1 >> ./test.file
   else
     break
   fi
done < ./hp.txt
0
carydb
Asked:
carydb
  • 3
  • 3
1 Solution
 
ahoffmannCommented:
1. your rsh command misses the hostname (typo?)
2. check your  /.rhosts file
0
 
carydbAuthor Commented:
I did some further checking and found that the while loop breaks after the rsh command succeeds. I have to rewrite the script. Thanks anyway.
0
 
ahoffmannCommented:
so my suggestion was right
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
carydbAuthor Commented:
ahoffmann - No, your suggestion was not right. What happened is the rsh was working fine. It would log on to the remote and write the default printer to a file, but when the rsh line completed the input file to the script was already closed so the while loop would not continue. the ./rhost file was not a problem and my rsh command did not miss the host name, thus no typo? I appriciate you input, but I rewrote the script to write a script that had multiple rsh commands to get rid of the while loop.  Perhaps I should withdraw the question since I already solved it. Can I withdraw a question? How?
0
 
ahoffmannCommented:
look at the Support topic at E-E, I think email was support@experts-exchange.com
0
 
ksbCommented:
The "rsh" command is reading all of stdin when it fails.

Use "rsh -n" and the original code will work fine.


0
 
carydbAuthor Commented:
Sheesh! It was that easy huh? I rewrote the script from a Korn script to a C program that used system calls to get around the problem. I tested the "-n" flag on rsh and the script ran just fine. Thanks a bunch! :)  
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now