- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: loop through the accounts and servers
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
тАО01-12-2009 01:55 PM
тАО01-12-2009 01:55 PM
account1 server1
account2 server2
account3 server1
account4 server1
5 server3
6 server2
7 server2
8 server3
9 server4
10 server4
now here I have to run couple of ksh scripts which i wrote (example tar, stop, start). I have to read from the text file and using those accounts and respective servers I have to login and run those scripts one at a time for all the accounts and respective servers.
If there are 10 accounts they may be in 3 or 4 differnt servers but thats not a big issue I can put that in some sequence if needed. Write now I am doing it using multiple text files. If I have accounts in 5 servers then I put five text files where I put accounts name and loop through them using resepctive server but I need some way to do that using one text file as I have written before.
I hope I made it clear this time if not i will try to elaborate more later on
I will really appreciate any help
thanks alot
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-12-2009 02:55 PM
тАО01-12-2009 02:55 PM
Re: loop through the accounts and servers
Can I see the code you are using.
I'd suggest two loops and two files, one for server the second for accounts within the server.
But to see where your code is going wrong, I kind of need to see it.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-12-2009 02:58 PM
тАО01-12-2009 02:58 PM
Re: loop through the accounts and servers
Using 'remsh' or better yet, 'ssh' you could do something like:
#!/usr/bin/sh
while read ACCT HOST X do
ssh -n ${ACCT}@${HOST} 'uname -a'
done < accts_and_servers
...where the 'accts_and_servers' file looks like your two-column file as posted. Substitute whatever script or commands you need in place of 'uname -a' in the sample script.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-13-2009 07:42 AM
тАО01-13-2009 07:42 AM
Re: loop through the accounts and servers
I am little bit confused may be I dint understand all the code
thank you
Steven,
Till now Im just doing for one server
for account in `cat list`
do
run scripts
done < list1
this works fine for the current server coz we dont have to login and all coz its local system but i want to do the same for the accounts in other than the local server and loop through it so that for example
if act1 is in server5 it should connect first using that account name and the server name and run those scripts over there and go for another account from the list with the respective server
thanks alot
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-13-2009 07:49 AM
тАО01-13-2009 07:49 AM
Re: loop through the accounts and servers
> Hi james, could you make me more clear plz
I am little bit confused may be I dint understand all the code
The suggested code reads:
while read ACCT HOST X do
ssh -n ${ACCT}@${HOST} 'uname -a'
done < accts_and_servers
This reads a file called 'accts_and_servers' which consists of whitespace-delimited fields. The First field is an account and the second a server hostname. Any additional fields are ignored. The loop reads the file and runs a secure-shell command to each account/server pair. The command, in this example, is simply a request to return the server's 'uname' information.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-13-2009 08:11 AM
тАО01-13-2009 08:11 AM
Re: loop through the accounts and servers
can i do that using rlogin instead of ssh because some of the servers and accounts are set such a way that I only login using rlogin if i do ssh it prompt for password and I cant make it automated using public key private key also.
like
rlogin server_name -l account_name 'script name'
If not how can i run command inside those server accounts using remsh will help?
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-13-2009 09:19 PM
тАО01-13-2009 09:19 PM
Re: loop through the accounts and servers
You'll need to use remsh instead.
remsh server_name -l account_name 'script name'
For -l account_name to work, you would have to be in the ~account_name/.rhosts file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-13-2009 10:12 PM
тАО01-13-2009 10:12 PM
SolutionSecond: I would strongly suggest to look into the ssh solution... It's more robust then remsh and a lot more secure...
If you take SEP's solution and replace the ssh command to:
cat accounts_and_servers | while read ACCOUNT HOST X
do
remsh $HOST -l $ACCOUNT -n "uname -a"
done
It will work this way.
If you have a script you want to distribute and run, change the remsh to these 3 lines:
rcp script $ACCOUNT@$HOST:/tmp
remsh $HOST -l $ACCOUNT -n /tmp/script
remsh $HOST -l $ACCOUNT -n rm /tmp/script
You might even try:
cat script | remsh $HOST -l $ACCOUNT /bin/sh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-14-2009 08:27 AM
тАО01-14-2009 08:27 AM
Re: loop through the accounts and servers
its doing the same thing its supposed to go inside else statement but its not.
this is my code.
while read Account Host X
do
if [ ${Account}="account1" || "account5" ]; then
${script} -a script -p "${WORK_PATH}stop" -c specific -l ${Account}
${script} -a script -p "${WORK_PATH}start" -c specific -l ${Account}
else
remsh ${Host} -l ${Account} -n 'compile'
fi
done < list1
I am not able to find the problem here. help plz
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-14-2009 09:31 AM
тАО01-14-2009 09:31 AM
Re: loop through the accounts and servers
Change the 'if' to:
if [ ${Account} = "account1" -o ${Account} = "account5" ]; then
Regards!
...JRF...