Okay, I need help.
I need to ssh in to multiple linux servers execute certain commands and get them to email and print on the screen when the script is being executed.
So below is my script. Its not working :-(.
#!/bin/bash
#linux/UNIX box with ssh key based login
SERVERS="1.2.3.4"
# SSH User name
USR="abc"
# connect each host
for host in $SERVERS
do
ssh $USR@$host
mail -s "1234" abc.xyz@mmmm.com
echo "in centos"
exit
done
It does prompt for password after entering the password It will enter the appropriate server and wait for some commands to be given :wall:...
I wanted it to go ahead and execute the below mail and echo commands.
The syntax works fine in a variety of shells from bash to dash to pdksh. I can't tell why your code isn't working until you post it. (but I guess that either you messed up the end of the here-document, or you're getting accidental substitution going on.)
I finally got it working ..
Here is what i was trying to do ..
ssh-agent , ssh add was creating whole lot of issues ..
I initially thought of puting the servers in a loop call them one by one and execute commands cylicly on all the servers..
Did not have any idea of backquote etc etc ..
I was also wrong to be using pipes when i tried two commands with no relation what so ever... Then I learned the o/p of first command will be the input of another .. Yup I relatively new to Unix too ..
HARNESS_SCRIPT_GREATNESS="255.255.255.255"
###################################################
for host in $HARNESS_SCRIPT_GREATNESS
do
echo ------------------------------------------
echo $host
---------- Post updated at 09:48 PM ---------- Previous update was at 06:02 PM ----------
Hi Corona,
I am getting slightly greedy with what my script can do here. So the situation is .
I am trying to run a upgrade script I know the exact folderstructure and the extension of the file (.rpm). But I do not know the file name and There will be only 1 file with .rpm extension in the folder I am interested.
So can i get the file name assigned to a variable ?
sudo rpm -Uvh /a/b/c/d/*.rpm < THIS DOES NOT WORK
sudo rpm -UVH /a/b/c/d/${}.rmp < What should I put in the braces ?
The line as given should work. The way you're sending it over ssh might not. I can't tell what you're doing from here. For the nth time, please post your code!
In the 'general help' department, I'd try single statements by hand before adding them to the whole domino chain, like ssh username@host ls "/path/to/*.rpm" Until you can get that to work there's no point adding the big rpm command.
If your code gets complex enough, you might want to just send entire, regular script files over ssh and dispense with all this quoting junk.
Sorry, I thought my post was descriptive enough. Please find my code below. I have got it working. The issue was I was trying..
CENTOS="a.b.c.d
x.y.z.w"
ab_rel="v.1"
####################################################
####################################################
for host in $CENTOS
do
echo ------------------------------------------
echo $host
I was using the below three forms and it would not work at all ..
sudo rpm -ivh /home/xytiz/work/'$ab_rel'/x/y/build/x86/.rpm <--- Incorrect
sudo rpm -ivh /home/xytiz/work/'$ab_rel'/x/y/build/x86/"".rpm <--- Incorrect
sudo rpm -ivh /home/xytiz/work/'$ab_rel'/x/y/build/x86/${}*.rpm<--- Incorrect
Then I accidentally tried the below
sudo rpm -ivh /home/xytiz/work/'$ab_rel'/x/y/build/x86/'*'.rpm <--- Correct !
I am still improvising the script to do many more htings like sending emails once all the update has been done etc ..
But THANK YOU VERY MUCH for the help ..
Its a great website and people like you who offer to help out is what makes it great ..
This one ought to have worked for the same reason single-quotes did: It prevents your own system from trying to process the * for you before it even gets sent over ssh.
This kind of amplifies my point about testing things in a small way before adding them to a big script. Unrelated problems can easily throw you for a loop unless you know for a fact the statement does work on the remote end.