Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm using Zentyal (formerly EBox) as my home gateway/server, to evaluate it for possible use in a local organization. I wanted to change the root MySQL password, which I did, and mistakenly changed the password in the Zentyal /var/lib/zentyal/conf folder to match it. So I changed the Zentyal password back to what it was, but the problem is, when I edited that file using nano it must have added a newline character or something, because now the Perl script that retrieves the password (which uses cat to retrieve it from the file) is causing a MySQL access denied error. Yet when I hardcode the password in the Perl db connect function, it works like a charm.

I've tried nano -L to edit the file, as well as an echo > to output the password to the file, and no luck with either. What is causing the problem when the Perl script does a cat to get the password?

share|improve this question
    
How is this question off-topic? Zentyal is not a novice system, and I am not a novice trying to get it working. I'm asking a specific question about system management. –  trpt4him Aug 6 '13 at 11:20
1  
nano is not intended for system administration tasks. It has a habit of doing unexpected things to the whitespace in text files. –  Michael Hampton Aug 6 '13 at 16:09
    
@MichaelHampton, as I'm finding. So is vi/vim the usual standard for config file edits? Looks like some tutorials I've seen probably need to be adjusted. –  trpt4him Aug 6 '13 at 17:42
add comment

1 Answer

up vote 5 down vote accepted

Why aren't you just using perl's native i/o capabilities to read the file?

open FH, "/path/to/password.txt";
chomp(my $passwd = <FH>);

The chomp here discard a newline at the end of the string.

What is causing the problem when the Perl script does a cat to get the password?

Have you tried just printing out the password you've read from the file? Something like:

print ":", $passwd, ":\n";

The colons are there so you can spot any extraneous whitespace (newlines, etc). You can also use xxd (which you will have if vim is installed on your system) or od -a to view all the bytes in the file. For example, given a file that contains "secret\n", od -a would show:

$ od -a file
0000000   s   e   c   r   e   t  nl
0000007

I've tried nano -L to edit the file as well as an echo > to add the password to the file,

I don't know nano, but echo will add a newline to the end of it's output. If you don't want that:

echo -n password > file

The -n suppresses the trailing newline.

share|improve this answer
1  
perl's native i/o capabilities to read the file? - Because he is using zentyal, which was written by dumb people, and perhaps he doesn't want to hack the source for something he is going to have to upgrade at some point in the future? –  Zoredache Aug 6 '13 at 6:35
    
Yes, the Perl is a huge mess and I don't want to rework it too much. But I am going to try your suggestions this afternoon. Thanks @larsks, for your helpful and comprehensive answer. –  trpt4him Aug 6 '13 at 11:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.