Hi there, I am new to scripting and need your help showing me how to create a script that does ssh on multiple servers run remote commands e.g. checking a process and report the outcome to one of the servers lets name it server1, regards..Bader
Last edited by zaxxon; 06-27-2012 at 10:40 AM..
Reason: Please don't make your font smaller at the half of the posting, thanks. Did not see any reason for that and harder to read ;)
from the server where I need the report on, I created a list of all servers that I need to generate the report from called it server list so wrote something like this ---------- Post updated at 08:00 AM ---------- Previous update was at 07:49 AM ----------
Hi Zaxxon, is there a better way to do this, again, I am still learning this and don't have a big knowledge when it comes to writing scripts
Last edited by zaxxon; 06-27-2012 at 11:32 AM..
Reason: code tags
Not sure if this is a typo, but a comma will not work to separate commands. Use a semicolon or start a new indented line do; ssh ....
Also the blank between "server list" might not work. I never use filenames with a blank when I have the choice and use a dot or underscore to enhance readability of them.
You write the output of grep to each server. Don't you want that centralized on the host you are issuing this command from?
Also please use code tags when posting code, data or logs etc.
By adding the printf on the line that is being read, you know which element of your list is currently being processed. The output of the ssh command is written after the host name.
Try something like this. All goes to a local file from the machine where you issue the command.
If the ssh gets stuck after executing the first cycle, add a -n to the ssh call.
ssh in a loop can always be a bugger when you're first starting off in scripting. Firstly, the reason it can be such a bugger is because of how ssh handles terminals, when the ssh command completes it exits out of the terminal which in turn will cause your script to fail. Very frustrating!
So, to resolve this you can do 1 of 2 things. You can either tell ssh to use a null terminal or you can use exec to read in your file which will in turn cause your loop to iterate appropriately.
Also, make sure that when you're doing your output redirection that you're appending (>>) vs. rewriting (>)
ssh null terminal
exec ssh ---------- Post updated at 09:48 AM ---------- Previous update was at 09:46 AM ----------
Good point, I didn't catch that his quotes were around the whole of the command. . Yes, depending on where your quotes are... it will cause your output to either go to the remote box or to go to your local box.
I'm new to utilities like socat and netcat and I'm not clear if they will do what I need.
I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes.
I'm using Cygwin bash on Windows 10.
My... (3 Replies)
Hello all,
I am facing a weird issue while executing a code below -
#!/bin/bash
cd /wload/baot/home/baotasa0/sandboxes_finance/ext_ukba_bde/pset
sh UKBA_publish.sh UKBA 28082015 3
if
then
echo "Param file conversion for all the areas are completed, please check in your home directory"... (2 Replies)
I am trying to call a script(callingscript.sh) from a master script(masterscript.sh) to get string type value from calling script to master script. I have used scripts mentioned below.
#masterscript.sh
./callingscript.sh
echo $fileExist
#callingscript.sh
echo "The script is called"... (2 Replies)
I am using blow script :--
#!/bin/bash
FIND=$(ps -elf | grep "snmp_trap.sh" | grep -v grep) #check snmp_trap.sh is running or not
if
then
# echo "process found"
exit 0;
else
echo "process not found"
exec /home/Ketan_r /snmp_trap.sh 2>&1 & disown -h ... (1 Reply)
Hi guys
I have a shell script that executes sql statemets and sends the output to a file.the script takes in parameters executes sql and sends the result to an output file.
#!/bin/sh
echo " $2 $3 $4 $5 $6 $7
isql -w400 -U$2 -S$5 -P$3 << xxx
use $4
go
print"**Changes to the table... (0 Replies)