Running multiple commands remotely via SSH in a script
In a script I am writing I am trying to add logic so that the script can figure out if a remote server uses rpm or dpkg and then run the appropriate command to print a list of installed packages. This works locally, but I need to get it to work through SSH and I have no idea how to do that. The relevant portion of the script is below. It would also be nice to find a way to not need the full path to the executables but I'm not real concerned about that.
So anyone know how to make this code work via SSH? Code:
if [ -x /usr/bin/dpkg ]; then |
I don't think your stating your problem properly, or at least I don't understand. You want your script to use ssh to retrieve the data from the servers?
|
Something like this, but you will need to supply the password or pub_key to the server but you get the idea?
Code:
SSHDPKG='ssh root@host -l username dpkg --get-selections' |
Thanks AutoBot, but that wouldn't really do what I need. What I am trying to do is have a backup server talk to multiple remote servers, figure out whether the remote server has rpm or dpkg, then execute the appropriate command to list the installed packages, all on the remote client via SSH. With your code that would perform the if statement on the backup server, which is not what I want. I need the if statements AND rpm/dpkg commands to be ran on the remote client via SSH. I already have key based auth set up....except for the backup server can't SSH to itself using a key, but I'll fix that later.
The reason I am trying to do it this way is in my backup script I have a array which holds the backup sources ($LINBACKUPSRC). I then use a 'for' loop to perform the backup command ($RSYNC) on each machine in the array to move it to the backup server ($BACKUPDEST). This works perfectly with the rsync portion of my backup, but I wanted to add a list of installed packages to the backup of each machine as well. The relevant portions of my code are below so you can see what it is doing. This code works perfectly, I just want to add the ability to print a list of installed packages too and not have worry about the fact 'Indigo' uses dpkg and 'Teal' uses rpm, hence the 'if' statements to figure that out for me. Am I just rambling or does that make any sense? If anyone wants the entire script, just ask and you can have it but there are minor problems in it still. Code:
CURDATE=$(date +%m-%d-%y) #If the script runs past midnight, this will still show the date the run started since the date is set here and simply remembered for the remainder of the script. Code:
#Backup Linux OS |
Figured it out.
Here is the entire loop in the script: Code:
#Backup Linux OS, add another elif line in the section below for another package managment system if you don't use rpm or dpkg, or adjust the path if needed. |
All times are GMT -5. The time now is 11:19 AM. |