LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Need Scripting assistance - checking systems on network to build a report of updates (https://www.linuxquestions.org/questions/programming-9/need-scripting-assistance-checking-systems-on-network-to-build-a-report-of-updates-648881/)

Echo Kilo 06-12-2008 01:59 PM

Need Scripting assistance - checking systems on network to build a report of updates
 
I am using the script below to check available updates on systems on the network. It works fine on Redhat (using yum list updates instead of sudo apt-get -s upgrade), but it seems to have an issue with Ubuntu.

It works for the 1st IP, but then seems to fail on the next and is looking for password again.

For now, I am entering the password manually as it logs on, and then again for sudo, but not sure why it fails on the subsequent IP's.

Here is the output from the script:

=====================================================================
Host ops1corp at IP 192.168.1.236 has the following updates available
=====================================================================
The following packages have been kept back:
ssl-cert
The following packages will be upgraded:
apache2 apache2-mpm-worker apache2-utils apache2.2-common bsdutils bzip2
e2fslibs e2fsprogs libblkid1 libbz2-1.0 libcomerr2 libgnutls13 libkrb53
libopenssl-ruby1.8 libpcre3 libpq5 libsnmp-base libsnmp9 libss2 libuuid1
libwrap0 libxml2 linux-libc-dev mount mysql-client-5.0 mysql-server
mysql-server-5.0 nagios-plugins nagios-plugins-basic nagios-plugins-standard
python2.5 python2.5-minimal samba-common smbclient snmp ssh tar util-linux
util-linux-locales
39 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.

=====================================================================
Host ops2corp at IP 192.168.1.237 has the following updates available
=====================================================================
Password:

=====================================================================
www1stg at IP 192.168.1.238 has the following updates available
=====================================================================
Password:

<see script below - not sure how to box the script for viewing>

#!/bin/bash

# loop that checks each system in iprange specified
for i in $(seq 236 238)
do
ip=192.168.1.$i
host=$(ssh $ip -C hostname 2>&1)
echo " "
echo "====================================================================="
echo "Host $host at IP $ip has the following updates available"
echo "====================================================================="
ssh $ip "sudo apt-get -s upgrade"
done > updates 2>&1

# do something with 'updates' here...

pixellany 06-12-2008 02:17 PM

The ssh command is inside the loop---so why would it not ask for password each time through? (Or maybe I am missing something.)

Echo Kilo 06-12-2008 03:53 PM

Yes, It does and it give it the password 2x each, so I'm not sure why it's having this error. It worked fine on Redhat and instead of "Password" it had the updates listed.

Echo Kilo 06-12-2008 05:24 PM

For example, here is a similar script that uses the command "top" and it works fine so I'm not sure why the "sudo apt-get -s upgrade" does not work.


#!/bin/bash

# loop that checks each system in iprange specified
for i in $(seq 236 238)
do
ip=192.168.1.$i
host=$(ssh $ip -C hostname 2>&1)
echo " "
echo "======================================================================"
echo "Host $host at IP $ip is running the following services"
echo "======================================================================"
ssh $ip "top -bn 1"
done > topreport 2>&1

# manipulate file 'report_file' here...

unSpawn 06-12-2008 06:28 PM

Please post your questions in one thread once and in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread should be closed because it is a duplicate of what's at http://www.linuxquestions.org/questi...script-648880/.

Echo Kilo 06-13-2008 11:24 AM

How do I close this thread - I only see a button for reply?

unSpawn 06-14-2008 06:57 PM

You can't close it yourself. Use the "Report" button on your topmost post or this link http://www.linuxquestions.org/questi....php?p=3182824 to ask for the thread to be closed or merged with the other one.


All times are GMT -5. The time now is 03:27 PM.