FTP Program

Hi all,

I have a script in 5 servers that looks like this: (collector.sh)

#!/usr/bin/sh

cat /var/log/messages | grep -i nscmd > nscmd_output
cat /var/log/messages | grep -i sshd | grep -i accepted > sshd_output
sleep 3
cat nscmd_output sshd_output | sort > user_activity
sleep 2
echo
echo "User Logs for Backup-Server:"
echo "----------------------------"
echo
cat user_activity
echo
echo "User History for Backup-Server:"
echo "-------------------------------"
echo
cat .bash_history
echo

The script will collect all the user activity logs from /var/log/messages and as well as the contents of the .bash_history and will put the printed output into /tmp/ directory.

Cat somebody help me how to create a script that will connect to each server through SSH, then execute the script, then get the logs (thru ftp) after the execution of collector.sh, and put all the generated logs from each server under /tmp/ directory of the main server (Server1)

Let's say, the script will be deployed in Server1, so once I executed it, it will first execute the the collector.sh within its self, and then perform the same actions on each server. So that in Server1 /tmp/ directory I have an output of:

collector_output_server1.log
collector_output_server2.log
collector_output_server3.log
collector_output_server4.log
collector_output_server5.log

Please help and advice,

Best regards,
rymnd_12345

Hi,

ssh may be used to execute a single command on the remote server in the form:

ssh user@remote_server command

see man ssh for further info on this.

If ssh remote server is available, my advice is to use scp to copy files from remote servers to local server.

A pseudo-script algrithm may look like:

for remote_server in <server1> <server2> <...>
do
   ssh $user@${remote_server} /path/to/collector.sh
   scp $user@${remote_server}:/path/to/collector_output.log /localpath/to/collector_output_${remote_server}.log
done

Using ssh key-based authentication is *STRONGLY* advisable in order to keep script simple.

see ya
fra

Hi frappa,

Thanks for your advice!

Br,
rymnd_12345