Having problems with IFS Variable using SSH

I have a perl script that needs to pass a string of code to a remote system via ssh.  The code works perfectly while ssh'd into the command shell of the remote system, but when it is passed to the remote system via ssh, I am unable to manipulate the IFS Variable to and the code fails.  I have tried sourcing ~./bashrc at the beginning of the command string, but to no avail.  Any help would be greatly appreciated. Probably something simple with the enviornment, but it's driving me crazy.

Linux localsystem 2.6.18-53.el5 #1 SMP Wed Oct 10 16:34:19 EDT 2007 x86_64 x86_64 x86_64 GNU/Linux
Linux remotesystem 2.6.18-92.el5 #1 SMP Tue Apr 29 13:16:15 EDT 2008 x86_64 x86_64 x86_64 GNU/Linux
(keys have properly installed between systems)
(This Works)
ssh remotesystem
 echo -e "begin\n\n\n";  cd /home/program/jboss-eap-4.2.CP07/jboss-as/server/customer/log_sec; pwd; IFS=$'\n'; echo $IFS | od -c; FILES=( $(find ./ -maxdepth 1 -type f -printf "%f\n"  ) ); echo -e "NUMBR:${#FILES[*]}\nFILES\n${FILES[*]}\n1.)${FILES[0]}\n2.)${FILES[1]}\n-------------"; if [[ -n $FILES ]]; then for i in ${FILES[*]}; do echo -e "i:$i";  MD5=$(/usr/bin/md5sum $i); MD5VAL=${MD5:0:32 }; FNAME=${MD5:34}; echo "$MD5VAL,\"$FNAME\""; done; else echo -e "False\n${#FILES[*]}\n"; fi


--------------------------------------Desired Output--------------------------------------------------------
/home/program/jboss-eap-4.2.CP07/jboss-as/server/customer/log_sec
0000000  \n
0000001
NUMBR:2
FILES
this
this is also a file
1.)this
2.)this is also a file
-------------
i:this
d41d8cd98f00b204e9800998ecf8427e,"this"
i:this is also a file
6607e4132c9a84526d2a11b27979ec0c,"this is also a file"

(This Fails)
 ssh remotesystem 'source ~./bashrc; echo -e "begin\n\n\n";  cd /home/program/jboss-eap-4.2.CP07/jboss-as/server/customer/log_sec; pwd; IFS=$'\n'; echo $IFS | od -c; FILES=( $(find ./ -maxdepth 1 -type f -printf "%f\n"  ) ); echo -e "NUMBR:${#FILES[*]}\nFILES\n${FILES[*]}\n1.)${FILES[0]}\n2.)${FILES[1]}\n-------------"; if [[ -n $FILES ]]; then for i in ${FILES[*]}; do echo -e "i:$i";  MD5=$(/usr/bin/md5sum $i); MD5VAL=${MD5:0:32 }; FNAME=${MD5:34}; echo "$MD5VAL,\"$FNAME\""; done; else echo -e "False\n${#FILES[*]}\n"; fi'

----------------------------------FAILED OUTPUT------------------------------------------------------------
begin



/home/cscott/jboss-eap-4.2.CP07/jboss-as/server/firstrade/log_sec
0000000  \n
0000001
NUMBR:1
FILES
this
this is also a file
1.)this
this is also a file
2.)
-------------
i:this
this is also a file
,""
bash: ~./bashrc: No such file or directory
/usr/bin/md5sum: this
this is also a file: No such file or directory

cp5c0ttAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

arober11Commented:
Hi

Your:

source ~./bashrc;  

should probably read:

source ~/.bashrc;  

Anyway I don't believe that's your problem, as I dought your file loop:

for i in ${FILES[*]}; do echo -e "i:$i";

Will return the individual files, stick an extra colon on the end or you echo to prove this e.g.

echo -e "i:$i:";
0
cp5c0ttAuthor Commented:
Yes, I fixed the ~/.bashrc, hazards of cut and paste ;-)
Here is the applicable output from your recommeded change -

then for i in ${FILES[*]}; do echo -e "i:$i:";

---- OUTPUT -----

i:this
this is also a file:

---- END ----

As  I mentioned earlier, this code works perfectly when I ssh into a shell on the remote machine, it is only when I pass the code to the remote machine via an ssh command.  For some reason (I suspect Security) the IFS Variable can not be manipulated.  

Thank you for your input arobert11!
0
arober11Commented:
Nope, you can play happily play around with the IFS variable in a remote shell e.g.

ssh localhost 'echo -e "begin\n\n\n";  cd $HOME/boo; pwd; IFS=$'\n'; echo $IFS | od -c; FILES=( $(find ./ -maxdepth 1 -type f -printf "%f\n"  ) ); echo -e "NUMBR:${#FILES[*]}\nFILES\n${FILES[*]}\n1.)${FILES[0]}\n2.)${FILES[1]}\n-------------"; if [[ -n $FILES ]]; then IFS=':';for i in `echo "${FILES[*]}"|/usr/bin/tr "\n" ":" `; do echo -e "i:$i:";  MD5=$(/usr/bin/md5sum $i); MD5VAL=${MD5:0:32 }; FNAME=${MD5:34}; echo "$MD5VAL,\"$FNAME\""; done; else echo -e "False\n${#FILES[*]}\n"; fi'

It's the escaping in your example that's the issue.
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

arober11Commented:
With your host / file names:

ssh remotesystem 'echo -e "begin\n\n\n";  cd /home/program/jboss-eap-4.2.CP07/jboss-as/server/customer/log_sec; pwd; IFS=$'\n'; echo $IFS | od -c; FILES=( $(find ./ -maxdepth 1 -type f -printf "%f\n"  ) ); echo -e "NUMBR:${#FILES[*]}\nFILES\n${FILES[*]}\n1.)${FILES[0]}\n2.)${FILES[1]}\n-------------"; if [[ -n $FILES ]]; then IFS=':';for i in `echo "${FILES[*]}"|/usr/bin/tr "\n" ":" `; do echo -e "i:$i";  MD5=$(/usr/bin/md5sum $i); MD5VAL=${MD5:0:32 }; FNAME=${MD5:34}; echo "$MD5VAL,\"$FNAME\""; done; else echo -e "False\n${#FILES[*]}\n"; fi'
0
arober11Commented:
Appears I have the same cut-n-paste issues, as your good self:

ssh remotesystem 'echo -e "begin\n\n\n";  cd /home/program/jboss-eap-4.2.CP07/jboss-as/server/customer/log_sec; pwd; IFS=$'\n'; echo $IFS | od -c; FILES=( $(find ./ -maxdepth 1 -type f -printf "%f\n"  ) ); echo -e "NUMBR:${#FILES[*]}\nFILES\n${FILES[*]}\n1.)${FILES[0]}\n2.)${FILES[1]}\n-------------"; if [[ -n $FILES ]]; then IFS=:;for i in `echo "${FILES[*]}"|/usr/bin/tr "\n" ":" `; do echo -e "i:$i";  MD5=$(/usr/bin/md5sum $i); MD5VAL=${MD5:0:32 }; FNAME=${MD5:34}; echo "$MD5VAL,\"$FNAME\""; done; else echo -e "False\n${#FILES[*]}\n"; fi'
0
arober11Commented:
The following should give the desired results:

ssh remotesystem 'echo -e "begin\n\n\n";cd /home/program/jboss-eap-4.2.CP07/jboss-as/server/customer/log_sec;pwd;FILES=`find ./ -maxdepth 1 -type f|wc -l`;echo -e "NUMBR:$FILES";for aFile in `find ./ -maxdepth 1 -type f`; do aFile=`basename $aFile`;echo ":$aFile";MD5=$(/usr/bin/md5sum $aFile); MD5VAL=${MD5:0:32 }; FNAME=${MD5:34}; echo "$MD5VAL,\"$FNAME\""; done'
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cp5c0ttAuthor Commented:
arobert11 you rock.  Thanks!  I believe my issue stemmed from the (incorrect) thought that the find was storing the results into $FILES (at least that is what I was trying to do) as an array based on the -printf "$f\n" statement.  

In anycase modifying the -printf to use ":" instead of "\n", allowed me to process the list using the IFS as a colon.  Awesome, Thanks again!
0
cp5c0ttAuthor Commented:
BTW Final code snippet: (If anyone cares :-P )
 ssh remotesystem 'cd /home/program/jboss-eap-4.2.CP07/jboss-as/server/customer/log_sec; IFS=$:; FILES=( $(find ./ -maxdepth 1 -type f -printf "%f:"  ) ); if [[ -n $FILES ]]; then for i in ${FILES[*]}; do  MD5=$(/usr/bin/md5sum $i); MD5VAL=${MD5:0:32 }; FNAME=${MD5:34}; echo "$MD5VAL,\"$FNAME\""; done; else echo -e "False\n${#FILES[*]}\n"; fi'

--------- Desired Output ----------------------------------
d41d8cd98f00b204e9800998ecf8427e,"this"
6607e4132c9a84526d2a11b27979ec0c,"this is also a file"
--------- End of Output -----------------------------------


0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.