By westmoreland
I’m pretty new to bash scripts and I’m trying to work through some issues. Would appreciate any
suggestions.
I have a list of servers in a text file (I used the FQDN‘s), I assign the file name to a variable, I then use cat to read the list of file names and echo them to the screen. But when it assigns the variable it seems to append a r to the end of the variables value. Although the r doesn’t show up unless I use the set command to debug. As you can see from code below, I’m trying to use a server list to perform a secure copy of my password files so that I don’t have to log on to each server. Here is the code snippet in question:
Code:
#!/bin/bash
#
set -x
FILENAME=server_list.txt
cat $FILENAME | while read LINE
do
echo "$LINE"
# mkdir /sysadmin/bin/passwd_audit/$LINE
# scp root@$LINE:/etc/passwd /sysadmin/passwd/$LINE-passwd.txt
# scp root@$LINE:/etc/group /sysadmin/passwd/$LINE-group.txt
# scp root@$LINE:/etc/sudoers /sysadmin/passwd/$LINE-sudoers.txt
done
set +x
Here are the first few lines in the file:
Quote:
api01r5v.lamar.edu
appworxdbdev.lamar.edu
appworxdbprod.lamar.edu
appwxdbdevr5p.lamar.edu
|
Here’s what the output from the script looks like:
Quote:
[root@netbkpmaster passwd_audit]# ./getinfo_script
+ FILENAME=server_list.txt
+ cat server_list.txt
+ read LINE
+ echo $’api01r5v.lamar.edur’
api01r5v.lamar.edu
+ read LINE
+ echo $’appworxdbdev.lamar.edur’
appworxdbdev.lamar.edu
+ read LINE
+ echo $’appworxdbprod.lamar.edur’
appworxdbprod.lamar.edu
+ read LINE
+ echo $’appwxdbdevr5p.lamar.edur’
appwxdbdevr5p.lamar.edu
|
Is this normal behavior? I’ve used this same script in the past and it’s worked fine for me. Not sure why it changed suddenly. Any suggestions would be greatly appreciated.
…read more
Source: FULL ARTICLE at The UNIX and Linux Forums