Running the same remote script on multiple servers
Experts,
Im trying to remote into a server, run a script that resides on that server and capture the information displayed & store in a local file.
I struggled with this yesterday & finally that script is working now.
Now, here is a scope creep and the script that I wrote for 1 remote server now, should run on more than one server and then capture the log from the server and store it on my local desktop to be sent to mgt for further decision making.
However I tried this in more than one way, but none of the approaches that I took are yielding any results. The script when invoked individually work fine for each remote server but when I combine them, the second one fails to run.
Here is what I have so far. The highlight BOLD lines are working well now.
Please advise !
regards,
Lee
Here is what Results.txt Looks after first write -
First, do not use variables already in use by UNIX or your shell, use MY_NAMES_FOR_SURE !
Using a var as a file seems silly for this situation, and might not take a big output robustly, but why store when you can flow; why not just put around all "( ... ) >>log_file 2>&1" and let them inherit stdout/stderr ? "2>&1" is a good idea, so the outputs stay together in the log in original time order.
Using PPK passwordless login, and you would not need expect. That is more secure than passwords in scripts, as well as simpler to invoke.
Using expect is bound to occasionally fail in weird ways when ssh does something you didn't, well, expect. It's very unsecure too. Just set up keys, it's much less hair pull and lets you securely use ssh the way it was designed.
When you do logins properly instead of faking them with expect, you can redirect entire scripts into ssh and have them run on the remote server letter for letter, like so:
The exec /bin/sh is to make sure you get a predictable shell on the remote server and not csh or something else weird. Anything should have some sort of bourne shell...
There's mountains of instructions all over the internet for passwordless ssh. First you create a key, then ssh-copy-id username@host which amounts to the same thing as adding your key to the remote host's allowed keys. You should be able to login noninteractively thereafter.
Im running the below command
sshpass -p mypassword ssh -t user1@server2 /bin/bash -c 'echo "mypassword" | sudo -S -l; echo "$?#`grep -iE "user66|dbuser|tomcat|splunk|stash|jira|user2|docadmin" /etc/passwd`"; exit'
Below is the error I get: Output:
I run this command across a... (1 Reply)
A webservice running on multiple servers. A patch has been deployed to them and it got successful only in some set of servers. The change is in format of "logontime" from "dd.mm.yyyy hh24:mi:ss" to "dd/mm/yyyy hh24:mi:ss". A script has already generated the output from all servers with request and... (2 Replies)
Hi
Wishing to all.
I am very new joined in an organization as a unix system administrator.
I need a help in preparing a script for a report.
i have a file contains all of the linux/ubuntu servers line by line around 140 servers.
vi servers.txt
nh01
nh02
nh03
bh01
bh04
-
-
:wq (3 Replies)
Hi all,
I am baffled on this. Solaris Irix system.:confused:
I have 4 servers all connected to one another, :b: I need to write a script line that would login on to server 1-3 ($HOST) start a script in the back ground and log off while the back ground script runs over a length of time.:eek:
... (10 Replies)
new3=`cat /tmp/list3`
for pol in "$new3" $(su - dbadmin -c "ssh $new3 '/usr//llist'");
do export policy=`echo $pol`; su - dbadmin -c "ssh $x '/usr/policycmd $policy -L |grep -i active; echo $policy'">>/tmp/listxyz;done
I am having trouble with this testscript as the file list3 has two names... (1 Reply)
So I have a scriptlet called solaris_command:
for i in \
server1 server2 server3
do
echo $i
ssh $i $1
echo ""
done
I then use that as a command in multiple scripts to allow for data gathering for all virtual hosts in the environment thusly:
solaris_command "cat... (3 Replies)
Hi,
I am trying to write a script to run a command on multiple linux based servers and get the o/p. I am using ssh to login. It is a celerra box and EMC NAS product.
I am able login but i am not able to run nas command nas_pool -size -all the NAS server. I am getting the following error. ... (2 Replies)
I have a script on about 15 hosts that I need to run for each host whenever I want (not crontab). Problem is, this script takes 5-10 mins to run for each host. Is there a way I can run the script in parallel for all the hosts instead of 1 at a time? Also, I'm remotely running the script on the... (3 Replies)
I have 20 Servers (They are Windows 2003) that I remote every day using names or IP address and type in my username & Password then copy folders manually to my local computer.
I'm wondering if i can just run script(s) from my local computer to do this job without using FTP(because of security... (5 Replies)
Hi,
I am running a shell script from a central server to multiple remote servers using the following code:
application_check()
{
# Linux/UNIX box with ssh key based login
SERVERS=`cat /tmp/server-details`
# SSH User name
USR="user"
# create new file
> /tmp/abc.log
# connect... (2 Replies)