Help needed on ssh in bash scripting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help needed on ssh in bash scripting
# 1  
Old 02-10-2015
Linux Help needed on ssh in bash scripting

HI
I have the following requirement

I have a script a.sh which will deploy files in multiple servers .The argument for the a.sh is abc.gz host1.conf
where abc.gz is a zip file and one.conf will contain all the database connection string .

Now I have to write a b.sh which will call a.sh internally but the argument to the b.sh are three remote hosts
Code:
 b.sh <host1.conf> <host2.conf> <host3.conf>

Now the host.conf will have the ip address ,so that b.sh will be executed on the that host after connection through ssh inside the bash shell script .

Please help me on this .

Last edited by rbatte1; 02-10-2015 at 07:57 AM.. Reason: Added CODE tags
# 2  
Old 02-10-2015
Welcome harry00514,

I have a few to questions pose in response first:-
  • Is this homework/assignment? There are specific forums for these.
  • What have you tried so far?
  • What output/errors do you get?
  • What OS and version are you using?
  • What logical process have you considered? (to help steer us to follow what you are trying to achieve)
Most importantly, What have you tried so far?

There are probably many ways to achieve most tasks, so giving us an idea of your style and thoughts will help us guide you to an answer most suitable to you so you can adjust it to suit your needs in future.


We're all here to learn and getting the relevant information will help us all.
# 3  
Old 02-10-2015
HI

This is part of my project where I really got stuck up .Its in Linux system .
So far I have tried with ssh but not able to get how the script will be executed on remote machine and how will I get the log from the remote machine .

Code:
 ssh user@host 'bash -s' <b.sh> <host1.conf> <.gz file>

The user and host I am getting from the config file and the above ssh command I am putting inside loop .The loop will be iterated through host1.conf, host2.conf and so on.
SO that the script will be executed one by one in the remote servers .
This was my requirement.

Last edited by rbatte1; 02-10-2015 at 08:19 AM.. Reason: Removed email tags and added CODE tags
# 4  
Old 02-10-2015
So, a few more questions I'm afraid:-
  • Is the script b.sh on the local or remote host?
  • Is the log generated by b.sh or is it the screen output that you want?
# 5  
Old 02-10-2015
Both b.sh and a.sh in local host .But I want to execute it on remote server and get the log file be read from remote server and proceed towards the next remote server execution .


Thanks for your interest and early response .

Last edited by rbatte1; 02-10-2015 at 08:36 AM..
# 6  
Old 02-10-2015
You will need to send the b.sh to the remote host and make it executable. Use sftp for this. You could add this to your script so if you have several servers, an update to b.sh gets copied out each time.

To get a log file back, again an sftp get would be appropriate.

The sftp should be quite straightforward if ssh is already set up as a password-less connection.

You will end up with something like this logic:-
  • Setup generate environment on local server
  • For each server in list:-
    • Send script with sftp setting the execute on
    • Use ssh to run script remotely and generate log file
    • Retrieve log file with sftp
    • Determine if b.sh needs to flag an error and take action
  • Loop with next server in list
As an alternate, you might also consider:-
  • Setup generate environment on local server
  • For each server in list:-
    • Send script with sftp setting the execute on
    • Use ssh to run script remotely and generate log file
    • Retrieve log file with sftp to a file-name based on the server
  • Loop with next server in list
  • Process all logs to report as appropriate

Do either of these give you something to build on?



Robin
# 7  
Old 02-10-2015
Send script with sftp setting the execute on
Use ssh to run script remotely and generate log file
Can I have a snippet of code so that I will get more clarity on this.It will be kind of you .

It's getting clearer now .I will give a try and let you know .In the mean time please help me with the snippets of code.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Scripting Help needed

Hi folks, need a small help lets say i have a text file with the following content: james tom jack spielberg i want to append text to the beginning of each line with a variable(lets says FirName:) and i want to combine all the names with a space in between and store it in another... (11 Replies)
Discussion started by: tech_frk
11 Replies

2. Shell Programming and Scripting

Need some help in bash scripting with ssh

Hi @ all I have the following scenario: As Admin of a cupple of servers I tried to write the following script to figure out, if the machine is up and available and if some directory´s were available. But my script is having some probs, while running. Maybe some of you have a better way to... (9 Replies)
Discussion started by: muogli
9 Replies

3. Shell Programming and Scripting

Help needed in scripting

Hi Guys, I need help in scripting out the below : this is a sample data i have in my file: jobname type 8:00:00 AM I need to remove the ":00" from the time field alone. Thanks in advance for all ur help (8 Replies)
Discussion started by: a12ka4
8 Replies

4. Shell Programming and Scripting

Scripting help needed

Hi All, I have a conf file and it has two entries seperated by comma, look like :- best1,ls /opt/bmc/Patrol3/*/best1 ......, ....................... In which "Best1" is the product name and "ls /opt/bmc/Patrol3/*/best1" is the way to find the product version of Best1 in that particular... (5 Replies)
Discussion started by: Renjesh
5 Replies

5. Linux

Scripting advice needed

Evening all, Im trying to get a script that will: Select the most 3 recent files in a specific directory Run a command on them (like chmod) Ask of you would like to continue Copy the files to another directory If a linux guru could help me out, it would be very much appreciated. Thanks... (2 Replies)
Discussion started by: Wiggins
2 Replies

6. Homework & Coursework Questions

Scripting needed

Hi, My task is to check the file test.txt every 15 min from Mon-Fri 9:00AM - 6:00PM. We get this file from our mainframes, every 15 min it will update the same file. My task is to compare file timestamp with current system time stamp and check if the file is updated or not. If the file doesn't... (0 Replies)
Discussion started by: chinniforu2003
0 Replies

7. Shell Programming and Scripting

Help needed with scripting.

Hello Friends, I am very new to scripting and currently have come across a situation where I need to create a UNIX script which would look for certain text in a file and then email me if it finds it. I am trying to trouble shoot an issue with our internet websites and I need to know when I... (1 Reply)
Discussion started by: mahive
1 Replies

8. UNIX for Dummies Questions & Answers

sh scripting! Help Needed

Hello fellas or ladies. I am new on this site and new to the unix operating system. I have been working with UNIX and i love it so far, i learned some stuff and most of the beneficiary command but I need help renaming all the files in my directory and doing them one by one is just tiring. is there... (3 Replies)
Discussion started by: keyboardkowboy
3 Replies

9. Shell Programming and Scripting

sh scripting! Help Needed

Hello fellas or ladies. I am new on this site and new to the unix operating system. I have been working with UNIX and i love it so far, i learned some stuff and most of the beneficiary command but I need help renaming all the files in my directory and doing them one by one is just tiring.... (1 Reply)
Discussion started by: keyboardkowboy
1 Replies

10. Shell Programming and Scripting

little scripting help needed!!

guys i need bit of help!! i am writing a script which finds files that have not been accessed for a no of days and delete those files...the no of days value is inputted at the command line.... i am using the following : find $1 -atime +7 -exec rm -i in the second step i want to copy all... (2 Replies)
Discussion started by: vats
2 Replies
Login or Register to Ask a Question