Solved

Korn shell script

Posted on 1998-10-05
7
367 Views
Last Modified: 2010-05-18
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
Comment
Question by:carydb
  • 3
  • 3
7 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 2007213
1. your rsh command misses the hostname (typo?)
2. check your  /.rhosts file
0
 

Author Comment

by:carydb
ID: 2007214
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 2007215
so my suggestion was right
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:carydb
ID: 2007216
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 2007217
look at the Support topic at E-E, I think email was support@experts-exchange.com
0
 
LVL 1

Accepted Solution

by:
ksb earned 50 total points
ID: 2007218
The "rsh" command is reading all of stdin when it fails.

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


0
 

Author Comment

by:carydb
ID: 2007219
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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Unix / Linux grid computing 5 149
AIX  NFS  question 1 121
How should I mount this 3 TB USB Hard disk to my Linux server? 9 100
add some character at the end of line in vi 7 63
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now