Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

read file script not working

Posted on 2009-07-13
7
252 Views
Last Modified: 2013-12-06
I have created a small script on a RHE5 server that is supposed to read a list of servers from a file 'one at a time' and run some functions then return to read the next server and continue. It is running the first server then stopping.

Also I am trying to create the report file as $hostname.before but not working also.

/mnt;/mnt/sysconf.sh > /mnt/$HOST.before    <---------------

Any help would be appreciated...
get_before-cfgs.sh
 
======================START====================
#!/bin/sh
#get_before-cfgs.sh
 
set -x
$HOST='hostname -s'
N=0
while read server
do
N=$((N+1))
echo $server
ssh root@"$server" 'mount lucy:/usr/local/bin/UX_get_cfgs /mnt;/mnt/sysconf.sh > /mnt/$HOST.before;umount /mnt'
done < servers.txt
 
=============================STOP================================
 
 
 
Servers.txt
 
==============================START=============================
 
CYPRESS
DOGWOOD
FILBERT
HACKBERRY
WILLOW
CASCARA
CHERRY
CHESTNUT
CATALPA
CHINKAPIN
COTTONWOOD
BALSAM
BASSWOOD
ASPEN
BUCKEYE
BUCKTHORN
SEQUOIA
SPRUCE
SWEETGUM
SYCAMORE
TANOAK
LOCUST
MADRONE
POPLAR
REDCEDAR
REDWOOD
WALNUT
HAWTHORN
HAZEL
JUNIPER
HOLLY
LARCH
 
==========================STOP==========================
 
sysconfig.sh
 
=====================START=============================
 
#!/bin/sh
# Simple sysconfig script
 
set -x
 
rm -rf /tmp/config.servername
 
echo  "******************************************"
echo  "         System Configuration    "
echo  "******************************************"
 
uname -a
 
echo  "******************************************"
echo  "             CPU & Memory        "
echo  "******************************************"
 
 
echo  "*************/proc/version****************"
cat /proc/version
echo  "*************/proc/cpu********************"
cat /proc/cpuinfo
echo  "************/proc/meminfo*****************"
cat /proc/meminfo|grep MemTotal
 
echo  "******************************************"
echo  "             Hardware            "
echo  "******************************************"
 
 
echo  "************/etc/sysconfig/hwconf*********"
cat /etc/sysconfig/hwconf
 
#echo  "***********/sbin/sysctl -a****************"
#/sbin/sysctl -a
 
echo  "********/sbin/lspci***********************"
/sbin/lspci
 
echo  "******************************************"
echo  "             Boot Info           "
echo  "******************************************"
 
cat /etc/sysconfig/grub
 
 
echo  "******************************************"
echo  "             HBA driver          "
echo  "******************************************"
cd /proc/scsi; find . -type f -print | xargs egrep -i driver
 
 
echo  "******************************************"
echo  "             File System and Disks       "
echo  "******************************************"
 
 
#echo  "************df -k ************************"
#df -k >> /tmp/config.servername
echo  "**********/etc/fstab**********************"
cat /etc/fstab
echo  "**********mount***************************"
mount
echo  "*********fdisk -l*************************"
fdisk -l
echo  "********vgdisplay*************************"
vgdisplay
echo  "*********pvscan***************************"
pvscan
echo  "************lvmdiskscan*******************"
lvmdiskscan
 
echo  "******************************************"
echo  "             Net                 "
echo  "******************************************"
 
#echo  "***********ifconfig -a********************"
#ifconfig -a
 
#echo  "***********host***************************"
#host mozilla.org
echo  "***********ping test**********************"
#ping -c 4 -I eth0 -q www.mozilla.org|awk '{print $1,$2,$3,$4,$5}'|grep pack
 
echo  "******************************************"
echo  "               END OF REPORT               "
echo  "******************************************"
echo  "******************************************"
echo  "******************************************"
 
 
==================================STOP=============

Open in new window

0
Comment
Question by:bebo_c
  • 4
  • 2
7 Comments
 
LVL 3

Expert Comment

by:glenthorne
ID: 24845168
At first glance, one thing you might want to do is to separate your command by two ampersands (&&) instead of semicolons:

mount lucy:/usr/local/bin/UX_get_cfgs /mn && /mnt/sysconf.sh > /mnt/$HOST.before && umount /mnt

This will force each command to wait for the other to finish successfully.  You might be running into a situation where the final umount is occurring too soon.

Change $HOST to \$HOSTNAME - it worked on my machine.

Also, if the servers.txt contains only dogwood, does it run successfully?  I would verify that the scripts work on each host individually before throwing the entire list out.
0
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 75 total points
ID: 24845509

#!/bin/bash 
 
HOST=$(hostname)
 
while read server
do
  echo $server
  ssh root@$server "mount lucy:/usr/local/bin/UX_get_cfgs /mnt;/mnt/sysconf.sh >/mnt/$HOST.before;umount /mnt"
done < servers.txt

Open in new window

0
 

Author Comment

by:bebo_c
ID: 24855666
I used some of both of your methods and the Servername works now but no loop:

==============START====================
#!/bin/sh
# get_before-cfgs.sh

set -x

while read server
do
echo $server
ssh root@$server "mount lucy:/usr/local/bin/UX_get_cfgs /mnt && /mnt/sysconf.sh > /mnt/$server.before && umount /mnt"
done < servers.txt
=====================STOP============================
=====================START===========================
#!/bin/sh
# get_after-cfgs.sh
set -x

while read server
do
echo $server
ssh root@$server "mount lucy:/usr/local/bin/UX_get_cfgs /mnt && /mnt/sysconf.sh > /mnt/$server.after && umount /mnt'
done < servers.txt

diff $server.before $server.after > $server.diff
=============================STOP========================

-rwx--x--x   1 root       sys            214 Jul 13 16:09
-rw-r--r--   1 root       root         44640 Jul 14 18:47 CYPRESS.after
-rw-r--r--   1 root       root         44640 Jul 14 18:42 CYPRESS.before
-rw-------   1 root       sys              0 Jul 14 18:47 CYPRESS.diff
-rwx--x--x   1 root       sys            272 Jul 14 18:47 get_after-cfgs.sh
-rwx--x--x   1 root       sys            232 Jul 14 18:41 get_before-cfgs.sh
-rwx------   1 root       sys            231 Jul 14 18:37 get_before-cfgs.sh.origg
-rwx--x--x   1 root       sys            256 Jul 14 18:32 servers.txt
-rwx--x--x   1 root       sys           2608 Jul 13 16:10 sysconf.sh


Creates proper filename...but does not loop through rest of servers in servers.txt. Is it because I am calling out another script ...

" /mnt/sysconf.sh > /mnt/$server.before"

Still not looping through the list. All servers are confirmed...
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 3

Assisted Solution

by:glenthorne
glenthorne earned 50 total points
ID: 24859238
Just out of curiosity, in the script the server list is in the file "servers.txt", and in the original post, the file name has a capital "S" (Servers.txt).  Can you double check that?
0
 

Author Comment

by:bebo_c
ID: 24859976
Yes,

It is servers.txt

====================start=====================

lucy_root> cat servers.txt
CYPRESS
DOGWOOD
FILBERT
HACKBERRY
WILLOW
CASCARA
CHERRY
CHESTNUT
CATALPA
CHINKAPIN
COTTONWOOD
BALSAM
BASSWOOD
ASPEN
BUCKEYE
BUCKTHORN
SEQUOIA
SPRUCE
SWEETGUM
SYCAMORE
TANOAK
LOCUST
MADRONE
POPLAR
REDCEDAR
REDWOOD
WALNUT
HAWTHORN
HAZEL
JUNIPER
HOLLY
LARCH
===============stop==============

lucy_root> ls -l
total 288
-rwx--x--x   1 root       sys            214 Jul 13 16:09
-rw-r--r--   1 root       root         44640 Jul 14 18:47 CYPRESS.after
-rw-r--r--   1 root       root         44640 Jul 14 18:42 CYPRESS.before
-rw-------   1 root       sys              0 Jul 14 18:47 CYPRESS.diff
-rwx--x--x   1 root       sys            257 Jul 14 18:49 get_after-cfgs.sh
-rwx--x--x   1 root       sys            232 Jul 14 18:41 get_before-cfgs.sh
-rwx------   1 root       sys            231 Jul 14 18:37 get_before-cfgs.sh.orig
-rwx--x--x   1 root       sys            256 Jul 14 18:32 servers.txt
-rwx--x--x   1 root       sys           2608 Jul 13 16:10 sysconf.sh
0
 

Author Comment

by:bebo_c
ID: 24859996
Sorry, the script is here...........


==========start===========
#!/bin/sh
# get_before-cfgs.sh

set -x

HOST=$(hostname)

while read server
do
echo $server
ssh root@$server "mount lucy:/usr/local/bin/UX_get_cfgs /mnt && /mnt/sysconf.sh > /mnt/$server.before && u
mount /mnt"

done < servers.txt
=============stop=======================
0
 

Accepted Solution

by:
bebo_c earned 0 total points
ID: 24861783
I changed the script and it works now:

lucy_root> cat cfg_before.sh
#!/bin/sh
# get_before-cfgs.sh

set -x

rm *.before *.after *.diff

ServNames="porthos cypress dogwood filbert hackberry willow cascara cherry chestnut catalpa chinkapin cottonwood sequoia spruce sycamore locust madrone poplar redwood walnut"

for Server in $ServNames

do
ssh  root@$Server "umount  /mnt"
ssh root@$Server "mount lucy:/usr/local/bin/UX_get_cfgs /mnt && /mnt/sysconf.sh > /mnt/$Server.before && umount /mnt"

done

0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my business, I use the LTS (Long Term Support) versions of Linux. My workstations do real work, and so I rarely have the patience to deal with silly problems caused by an upgraded kernel that had experimental software on it to begin with from a r…
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question