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.
#e.g. You start a script Monday evening and it runs until Tuesday morning, this will still show a date of Monday. This is to keep logs consistent.
TIME='date +%r' #Change your time format here.
OUTLOG=/media/data/Logs/Backup/$CURDATE-STDOUT.log #Change log location and name here.
ERRLOG=/media/data/Logs/Backup/$CURDATE-STDERR.log #Change log location and name here.
LINOS='/etc /boot /var/log /home /root' #Change source directories for Linux machines here.
BACKUPDEST='white@192.168.1.150::data' #Change rsync destination here, Google and man pages are your friends for finding out how to set up an rsync daemon.
RSYNC='rsync -alpEAhR --stats --delete --exclude .gvfs' #Change rsync options here.
BACKUPUSER='backupuser' #Enter the user used by SSH here, see the "Prerequisites" section above for details.
LINBACKUPSRC=( "Indigo" "Teal" ) #Add Linux backup sources here.
Code:
#Backup Linux OS
for i in "${LINBACKUPSRC[@]}";do
echo "`$TIME` - Backing up $i - OS - START"|tee -a $OUTLOG $ERRLOG
ssh $BACKUPUSER@$i sudo $RSYNC $LINOS $BACKUPDEST/Backup/$i 1>>$OUTLOG 2>>$ERRLOG
echo "`$TIME` - Backing up $i - OS - COMPLETE"|tee -a $OUTLOG $ERRLOG
done