Bash script Problem.

General support questions
Post Reply
johnpraxel
Posts: 2
Joined: 2017/11/09 18:55:09

Bash script Problem.

Post by johnpraxel » 2018/10/23 21:18:15

Hello,

I have a problem with the following script. I hope that some can point me in the right direction as I am new to this. This script is intended to log into 69 clients and change the messages log after backing it up and moved to a backup directory. We do have the logs rotating, however we have a simulation lab and sometimes when all the clients are running client does rotate but does not create a log and the system crashes. I wrote this script and can access the clients using auto ssh but once I log in none of the commands are executed. Please note i did not put the passwords in the script.

#!/bin/sh
#
#
#
set -x

for host in $(cat sorted.txt);
do
sshpass -p "" autossh -M0 -t root@$host
echo $host
cd /var/log;
pwd
mv messages "messages.$(date)"
ls -l "messages.$(date)"
pwd
echo $host
touch messages
chmod 600 messages
echo $host;
echo "------------------------------------------------------" >> /home/user/Desktop/logrotate/output.$host
ls -l messages >> /home/user/Desktop/logrotate/output.$host
ls -l 'messages.($date)'
mv "messages.$(date)" >> /home/user/Desktop/logrotate/backup;
done;
#
echo Logs cleaned up;
exit;

Post Reply