If I add some debug, I see weird output with newlines:
sed -i "54
55 i\U_CRON_JOBS='0'" /usr/local/hestia/data/users/athertons/user.conf
I’m not too sure why its doing that? Looking at /usr/local/hestia/data/users/athertons/user.conf , it all looks ok (one entry per line) … so I’m not too sure whats causing it?
Not sure what would cause that? Manually removing the duplicated lines fixes it, but it seems to be all the user accounts that have the issue - and I have quite a few! Is there a better fix?
I wrote a little Perl script that would find all the user.conf files, and remove any duplicated lines. Its not perfect, but at least cleans them all up without manually doing it:
#!/usr/bin/perl
use strict;
use warnings;
my @list = split /\n/ , `find /usr/local/hestia/data/users/ -type f -name user.conf`;
foreach (@list) {
# Define the configuration file path
my $config_file = $_;
# Create a backup of the original file
my $backup_file = "$config_file.bak";
system("cp $config_file $backup_file");
# Read the original configuration file
open my $input_fh, '<', $config_file or die "Unable to open $config_file: $!";
my @lines = <$input_fh>;
close $input_fh;
# Remove duplicate lines
my %seen;
my @unique_lines;
foreach my $line (@lines) {
# Remove leading and trailing whitespaces from each line before checking for duplicates
my $trimmed_line = trim($line);
# Skip empty lines
next if $trimmed_line eq '';
# Check if the line has been seen before, if not, add it to the list of unique lines
push @unique_lines, $line unless $seen{$trimmed_line};
# Mark the line as seen
$seen{$trimmed_line} = 1;
}
# Write the unique lines back to the configuration file
open my $output_fh, '>', $config_file or die "Unable to open $config_file for writing: $!";
print $output_fh @unique_lines;
close $output_fh;
sub trim {
my $str = shift;
$str =~ s/^\s+|\s+$//g;
return $str;
}
print "Duplicate lines removed from $_, and a backup of the original file has been created.\n";
}
I need to try and see what happened though, in terms of the lines being duplicated. I’ve checked other servers with the same version of Hestia, and they seem ok - so its a bit of a weird one!
Ditto. I’m going to run through my other servers and see if any of them have the same issue. Its weird its only one server so far (and I only happened to notice it as our webmail stopped working)
I’ve just run through all my servers, and none of them seem to have the issue. The others have gone through the update to 1.8.10, so I don’t think it was that. Very odd. I’ll keep an eye out and see if it happens again
Sorry, I was away for the weekend. It seems to run fine now and not duplicate. All of it seemed to come out of the last update for some reason. Not sure if that’s just random, or something that happened which caused it during the update process
I have been testing and have not been able to simulate the problem. The first error you posted is because of duplicated variables but as I said, I have not been able to duplicate the problem and I have no idea why it happened to you. I am still looking at it
Yeah. I’m not sure how often it will happen. I wonder if some better error handling would be good in main.sh - update_user_value() { } …
lnr=$(grep -n "^$key='" $HESTIA/data/users/$1/user.conf | cut -f 1 -d ':')
# if lnr has a newline in, show error and email!
if [[ "$lnr" =~ $'\n' ]]; then
echo "Error: update_user_value for $key has a newline in it!"
echo "Error: update_user_value for $key has a newline in it!" | mail -s "Error: update_user_value for $key has a newline in it!" $CONTACT
fi
So that it emails us when it happens, so we are at least aware it has happened? (and hopefully pin down the last thing that happened, before it caused an issue)