Sponsored Content
Top Forums Shell Programming and Scripting Bash script puts \r at the end of variable Post 302769806 by westmoreland on Wednesday 13th of February 2013 01:13:45 PM
Old 02-13-2013
Bash script puts \r at the end of variable

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.edu\r'
api01r5v.lamar.edu
+ read LINE
+ echo $'appworxdbdev.lamar.edu\r'
appworxdbdev.lamar.edu
+ read LINE
+ echo $'appworxdbprod.lamar.edu\r'
appworxdbprod.lamar.edu
+ read LINE
+ echo $'appwxdbdevr5p.lamar.edu\r'
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.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How do you parse a variable in a bash script?

I have a script I use on my web server (Apache2). I am changing to Lighttpd and need to make a few changes. This is what I use on my apache server #!/bin/bash # accepts 3 parameters: <domain name> <user name> <XXXXXXXX> # domain name is without www (just domain.com) # username would be... (3 Replies)
Discussion started by: vertical98
3 Replies

2. Shell Programming and Scripting

Puts command in a script

Hi, I am trying to output a set of fields to a file: set outFile "printHeader.tmp" set dbFields "REPORT.TIMESTAMP.s,REPORT.CUSTOMER.s,REPORT.CODE.s" puts $dbFields > $outFile I receive the following error message: bad argument "printHeader.tmp": should be "nonewline" ... (2 Replies)
Discussion started by: MrG-San
2 Replies

3. Shell Programming and Scripting

passing variable from bash to perl from bash script

Hi All, I need to pass a variable to perl script from bash script, where in perl i am using if condition. Here is the cmd what i am using in perl FROM_DATE="06/05/2008" TO_DATE="07/05/2008" "perl -ne ' print if ( $_ >="$FROM_DATE" && $_ <= "$TO_DATE" ) ' filename" filename has... (10 Replies)
Discussion started by: arsidh
10 Replies

4. Shell Programming and Scripting

end of file error bash ftp script

Hello kind programmers :) I am a newbie and running into an error "line 28: syntax error: unexpected end of file" on the script shown below. Any help would be greatly appreciated. Thanks! #! /bin/bash if ($#argv <3) then echo 'Usage get_modis_snow ' echo 'ftp script for MYD10A2... (2 Replies)
Discussion started by: cmshreve
2 Replies

5. Shell Programming and Scripting

script to detect a file from inserted usb and puts into a Variable

There is a same named log file that I have on my 2 different android phones. When I plug it into my computer, it appears in the media folder, For example the first android phone: /media/F6BA-0AF5/folder/A.log I want to put that into a variable to be manipulated.... (3 Replies)
Discussion started by: tobenguyen
3 Replies

6. Shell Programming and Scripting

script puts;; I need just ;

Hello Folks, I must be blind that I cant figure out this perl script why I end up with ;; at the end of the line. I am not an expert by any means #!/usr/bin/perl use File::Find; open F,shift or die $!; my %ip=map/(\S+)\s+(\S+)/,<F>; close F; find sub{ if( -f ){ local... (4 Replies)
Discussion started by: richsark
4 Replies

7. Shell Programming and Scripting

Bash script having variable substitution problems

Hi I am setting the variables like this : setenv MODULE1 modem5__3 setenv MODULE2 modem5__2 setenv MODULE3 modem_ctrl_1_1 setenv MODULE4 modem_1_0 setenv COUNT 10 I am having a bash script as shown below ################################################ #!/bin/bash for ((... (5 Replies)
Discussion started by: kshitij
5 Replies

8. Shell Programming and Scripting

Acces Variable from expect-Script in bash-Script

Hi all, I have a little problem with a expect in a bash Script. The hull of my script: #!/bin/sh ( expect -c ' set a \"eee\"; # the variable a ' ) echo $a; # using the variable out of the expect script I would like to use the variable out of the expect script(in bash),... (3 Replies)
Discussion started by: gandalfthepink
3 Replies

9. Shell Programming and Scripting

Script that gathers specific values from files and puts it into HTML to send e-mail

Hi All, Sorry for long topic here. So the drill goes like that, I need a script which gathers different values from different files/locations. A_CT=`cat a.dat | awk -F'|' '{print $1}' >> report.txt` B_CT=`cat b.dat | awk -F'|' '{print $3}' >> report.txt` C_CT=`cat c.dat | awk -F'|'... (4 Replies)
Discussion started by: shivakid
4 Replies

10. Shell Programming and Scripting

With script bash, read file line per line starting at the end

Hello, I'm works on Ubuntu server My goal : I would like to read file line per line, but i want to started at the end of file. Currently, I use instructions : while read line; do COMMAND done < /var/log/apache2/access.log But, the first line, i don't want this. The file is long... (5 Replies)
Discussion started by: Fuziion
5 Replies
MEDIT(1)						      General Commands Manual							  MEDIT(1)

NAME
medit - text editor SYNOPSIS
medit [OPTION]... [FILES] DESCRIPTION
medit is a text editor. OPTIONS
-n, --new-app run new instance of medit. By default medit opens FILES (or creates a new document if none are given) in an existing instance of application -s, --use-session[=yes|no] load and save session. By default medit does it when -n is not used. If this option is not given on command line then medit uses the corresponding preferences setting. --pid PID use existing instance with process id PID. --app-name NAME use instance name NAME. If an instance with this name is already running, then it will send files given on the command line to that instance and exit. -e, --encoding ENCODING use provided character encoding to open the file -l, --line LINE open file and position cursor on line LINE. Alternatively line number may be specified with filename, e.g. medit foo.txt:12 -r, --reload automatically reload opened file if it was modified on disk by another program. -w, --new-window open file in a new window. -t, --new-tab open file in a new tab. --log-file FILE write debug output into FILE. This option is only useful on Windows. --log-window show debug output in a log window. This option is only useful on Windows. --debug DOMAINS enable debug output for DOMAINS (if medit was compiled with --enable-debug option). --geometry WIDTHxHEIGHT --geometry WIDTHxHEIGHT+X+Y default window size and position. -h, --help show summary of options. -v, --version show program version. FILES list of files to open. Filenames may include line numbers after colon, e.g. /tmp/file.txt:200. Trailing colon is ignored. ENVIRONMENT VARIABLES
MEDIT_PID if set, it is used as --pid argument. When medit spawns a process (e.g. a DVI viewer) it sets MEDIT_PID to its own process id, so the child process may in turn simply use 'medit filename' to open a file (e.g. for inverse DVI search). CONTACT
http://mooedit.sourceforge.net/contact.html AUTHOR
Written and maintained by Yevgen Muntyan <emuntyan@users.sourceforge.net> September 2010 MEDIT(1)
All times are GMT -4. The time now is 06:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy