- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Problem when writing a script to execute commands ...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-07-2009 02:24 AM
тАО09-07-2009 02:24 AM
I am writing following script to execute commands on multiple remote systems through passwordless ssh.
#!/usr/sbin/ksh
while read remote_host
do
{
echo ${remote_host}
ssh ${remote_host} date
}
done < hostnames.txt
exit
Here hostnames.txt contains all ,y IP's. Problem is script gives the results of first IP of hostnames.txt. Is there any thing which I need to do for my requirement?
Solved! Go to Solution.
- Tags:
- ssh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-07-2009 03:59 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-07-2009 07:27 AM
тАО09-07-2009 07:27 AM
Re: Problem when writing a script to execute commands using passwordless ssh
I did like this way
#!/usr/sbin/ksh
for i in `cat hostnames.txt`
do
{
echo $i
ssh $i date
}
done
Suraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-07-2009 08:12 AM
тАО09-07-2009 08:12 AM
Re: Problem when writing a script to execute commands using passwordless ssh
> Suraj: I did like this way
The problem with your way is that it doesn't address the use of '-n'. Moreover, instead of using the shell's built-in 'read' (the redirection of input) you spawn an extra process (the 'cat'). This is simply wasteful.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-07-2009 09:10 AM
тАО09-07-2009 09:10 AM
Re: Problem when writing a script to execute commands using passwordless ssh
Thanks for the information i'll take care next time.
Suraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-07-2009 02:00 PM
тАО09-07-2009 02:00 PM
Re: Problem when writing a script to execute commands using passwordless ssh
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=954435
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=97577
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1169808
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=613847
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=953705
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-08-2009 03:38 AM
тАО09-08-2009 03:38 AM
Re: Problem when writing a script to execute commands using passwordless ssh
Actually ssh read its standard input and it interfers whith the read builtin.
First possibility, read your hostname.txt file through another "file descriptor" :
exec 3< hostname.txt
while read -u3 remote_host ; do
print $remote_host
ssh $remote_host date
done
exec 3<&-
Second possibility : try to close the ssh standard input in your loop :
while read remote_host ; do
print $remote_host
ssh $remote_host date 0<&-
done < hostname.txt
This second possibility has the advantage for your script to be able to ran in background (your_script.ksh &) without receiving a SIGTTIN signal from the kernel.
Of course your can mix both read -u3 and ssh ... 0<&-
Cheers,
Jean-Philippe
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-08-2009 03:44 AM
тАО09-08-2009 03:44 AM
Re: Problem when writing a script to execute commands using passwordless ssh
Yes, so why do all of this hackery when -n (or < /dev/null) solves the problem?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-08-2009 04:08 AM
тАО09-08-2009 04:08 AM
Re: Problem when writing a script to execute commands using passwordless ssh
Sorry, I didn't know the -n option of ssh.
I agree this is more relevant and more elegant than 0<&-.
Cheers,
Jean-Philippe.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-08-2009 05:58 AM
тАО09-08-2009 05:58 AM
Re: Problem when writing a script to execute commands using passwordless ssh
when starting applications are making the assertion that they have
standard in 0
standard out 1
error out 2
For instance the first socket which will be opened will use fd 0 if 0 is closed.
.....
result of closing stdin could have funny and always unexpected results.
So it is always better to use
so to make what you want to do, like I wrote in the first answer the more simple is
to use -n option of ssh, or redirect stdin for ssh to /dev/null.