Koozali.org: home of the SME Server

cron not working

Offline crazybob

  • ****
  • 894
  • +0/-0
    • Stalzer R&D
cron not working
« on: April 16, 2018, 08:51:04 PM »
I am attempting to use an older script from Dungog for rsync to backup some remote servers, but crontab doesn't trigger the backup.
Checking the log file is see "(CRON) bad minute (/etc/crontab)".
If I do a "cat -v /etc/crontab" I see a ^M  below the rsync entries.
I do not see the ^M if I use nano as if I was going to edit it.

Before I go too far, Should I submit this to bugzilla, or post more information here?
If you think you know whats going on, you obviously have no idea whats going on!

Offline Jean-Philippe Pialasse

  • *
  • 2,763
  • +11/-0
  • aka Unnilennium
    • http://smeserver.pialasse.com
Re: cron not working
« Reply #1 on: April 16, 2018, 09:05:30 PM »
is your line confidential enought to not post it ?  (remove password if any)
are other lines in the cron still runing ?

Offline crazybob

  • ****
  • 894
  • +0/-0
    • Stalzer R&D
Re: cron not working
« Reply #2 on: April 16, 2018, 09:39:41 PM »
Here is the result of  cat -v /etc/crontab
   
Code: [Select]
#------------------------------------------------------------
#              !!DO NOT MODIFY THIS FILE!!
#
# Manual changes will be lost when this file is regenerated.
#
# Please read the developer's guide, which is available
# at http://www.contribs.org/development/
#
# Copyright (C) 1999-2006 Mitel Networks Corporation
#------------------------------------------------------------
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root


# rsync by dungog-rsync.(taxmasters)
48 4 * * * root /usr/bin/dungogrsync-rsync120746

# rsync by dungog-rsync.(drmike)
1 18 * * * root /usr/bin/dungogrsync-rsync194693

# rsync by dungog-rsync.(main server)
45 13 * * * root /usr/bin/dungogrsync-rsync422061

# rsync by dungog-rsync.(FirstChoice)
31 20 * * * root /usr/bin/dungogrsync-rsync564449

# rsync by dungog-rsync.(gls)
28 22 * * * root /usr/bin/dungogrsync-rsync582321

^M
# logrotate
12 1 */7 * * root       /sbin/e-smith/signal-event logrotate


# DMARC Reporting is disabled

# Backup task is disabled
# Workstation Backup task is disabled
2 4 * * * root sleep $[ $RANDOM \% 3600 ]; /sbin/e-smith/check4contribsupdates -m
2 4 * * * root sleep $[ $RANDOM \% 3600 ]; /sbin/e-smith/check4updates -m

# smeserver-clamscan filesystem scan
# disabled




# squid is disabled

26 9 * * 6 root  sleep $[ $RANDOM \% 60 ]; /sbin/e-smith/statusreport

and this is the template that is in   /etc/e-smith/templates/etc/crontab

 
Code: [Select]
{
  use esmith::config;
  use esmith::db;

  local %dungog;
  tie %dungog, 'esmith::config', '/home/e-smith/db/dungog';

  $OUT = "\n";

  my @all = ();
  foreach (keys %dungog)
  {
    push (@all, $_)
    if (db_get_type(\%dungog, $_) eq "rsync");
  }
  foreach (keys %dungog)
  {
    push (@all, $_)
    if (db_get_type(\%dungog, $_) eq "rsyncAnon");
  }

  #if a rsync is defined set it up
  my $all = @all || '0';
  if ($all > 0)
  {
    my $rsync;
    foreach $rsync (sort @all)
    {
      my $user    = db_get_prop(\%dungog, $rsync, "user")    || 'root';
      my $freq    = db_get_prop(\%dungog, $rsync, "freq")    || '';
      my $day     = db_get_prop(\%dungog, $rsync, "day")     || 'tue';
      my $hour    = db_get_prop(\%dungog, $rsync, "hour")    || '3';
      my $min     = db_get_prop(\%dungog, $rsync, "min")     || '30';
      my $desc    = db_get_prop(\%dungog, $rsync, "desc")    || '';
      my $mail    = db_get_prop(\%dungog, $rsync, "mail")    || '';

      #unless email is on, delete output
      unless ($mail eq 'on')
      {
        $mail = '1>/dev/null 2>/dev/null';
      }
      else
      {
      $mail = '';
      }

      if ($freq eq 'hourly')
      {
        $OUT .= "# hourly rsync by dungog-rsync.($desc)\n";
        $OUT .= "$min * * * * $user /usr/bin/dungogrsync-$rsync $mail\n";
        $OUT .= "\n";
      }
      elsif ($freq eq 'on')
      {
        $OUT .= "# rsync by dungog-rsync.($desc)\n";
        $OUT .= "$min $hour * * $day $user /usr/bin/dungogrsync-$rsync $mail\n";
        $OUT .= "\n";
      }
    }
  }
}

If you think you know whats going on, you obviously have no idea whats going on!

Offline crazybob

  • ****
  • 894
  • +0/-0
    • Stalzer R&D
Re: cron not working
« Reply #3 on: April 16, 2018, 10:06:24 PM »
I am going to try to start this over. I am going to reload SME 9.2 and start this process again to insure that it is the rsync contrib causing the issue.
If you think you know whats going on, you obviously have no idea whats going on!

Offline crazybob

  • ****
  • 894
  • +0/-0
    • Stalzer R&D
Re: cron not working
« Reply #4 on: April 16, 2018, 10:19:38 PM »
I just removed the dungog rsync contrib, and the ^M was removed from the crontab flie. I re-install the contrib, and the ^M is back.

The contrib is old, maybe from SME6 or SME7, and the author no longer supports it. It does work on SME8.2, and the ^M appears there.

looking for ideas
« Last Edit: April 16, 2018, 10:22:54 PM by crazybob »
If you think you know whats going on, you obviously have no idea whats going on!

Offline Stefano

  • *
  • 10,839
  • +2/-0
Re: cron not working
« Reply #5 on: April 16, 2018, 11:04:23 PM »
Search for ^M with google, you'll find hundreds of answers on how to remove it

Offline crazybob

  • ****
  • 894
  • +0/-0
    • Stalzer R&D
Re: cron not working
« Reply #6 on: April 16, 2018, 11:24:46 PM »
The problem is to keep it gone. If I edit the crontab file and remove it, it will come back the next time the server reboots.
Here is a copy of the template that builds the crontab entry
Code: [Select]
{^M
  use esmith::config;^M
  use esmith::db;^M
^M
  local %dungog;^M
  tie %dungog, 'esmith::config', '/home/e-smith/db/dungog';^M
^M
  $OUT = "\n";^M
^M
  my @all = ();^M
  foreach (keys %dungog)^M
  {^M
    push (@all, $_)^M
    if (db_get_type(\%dungog, $_) eq "rsync");^M
  }^M
  foreach (keys %dungog)^M
  {^M
    push (@all, $_)^M
    if (db_get_type(\%dungog, $_) eq "rsyncAnon");^M
  }^M
^M
  #if a rsync is defined set it up^M
  my $all = @all || '0';^M
  if ($all > 0)^M
  {^M
    my $rsync;^M
    foreach $rsync (sort @all)^M
    {^M
      my $user    = db_get_prop(\%dungog, $rsync, "user")    || 'root';^M
      my $freq    = db_get_prop(\%dungog, $rsync, "freq")    || '';^M
      my $day     = db_get_prop(\%dungog, $rsync, "day")     || 'tue';^M
      my $hour    = db_get_prop(\%dungog, $rsync, "hour")    || '3';^M
      my $min     = db_get_prop(\%dungog, $rsync, "min")     || '30';^M
      my $desc    = db_get_prop(\%dungog, $rsync, "desc")    || '';^M
      my $mail    = db_get_prop(\%dungog, $rsync, "mail")    || '';^M
^M
      #unless email is on, delete output^M
      unless ($mail eq 'on')^M
      {^M
        $mail = '1>/dev/null 2>/dev/null';^M
      }^M
      else^M
      {^M
        $mail = '';^M
      }^M
^M
      if ($freq eq 'hourly')^M
      {^M
        $OUT .= "# hourly rsync by dungog-rsync.($desc)\n";^M
        $OUT .= "$min * * * * $user /usr/bin/dungogrsync-$rsync $mail\n";^M
        $OUT .= "\n";^M
      }^M
      elsif ($freq eq 'on')^M
      {^M
        $OUT .= "# rsync by dungog-rsync.($desc)\n";^M
        $OUT .= "$min $hour * * $day $user /usr/bin/dungogrsync-$rsync $mail\n";^M
        $OUT .= "\n";^M
      }^M
    }^M
  }^M
}^M
Which ^M  or ^Ms should I eliminate?
If you think you know whats going on, you obviously have no idea whats going on!

Offline ReetP

  • *
  • 3,738
  • +5/-0
Re: cron not working
« Reply #7 on: April 17, 2018, 01:03:44 AM »
I can take a look but not til the morning.

Is it just a script or a rpm? I have all his old ones I think.

Can you confirm the actual rpm nane please ?
...
1. Read the Manual
2. Read the Wiki
3. Don't ask for support on Unsupported versions of software
4. I have a job, wife, and kids and do this in my spare time. If you want something fixed, please help.

Bugs are easier than you think: http://wiki.contribs.org/Bugzilla_Help

If you love SME and don't want to lose it, join in: http://wiki.contribs.org/Koozali_Foundation

Offline crazybob

  • ****
  • 894
  • +0/-0
    • Stalzer R&D
Re: cron not working
« Reply #8 on: April 17, 2018, 01:15:58 AM »
It is an RPM    dungog-rsync-1.2-3.noarch.rpm.

Seems like I've had it for ever, and hate to change because it does exactly what I need.

Thanks for the help
If you think you know whats going on, you obviously have no idea whats going on!

Offline ReetP

  • *
  • 3,738
  • +5/-0
Re: cron not working
« Reply #9 on: April 17, 2018, 10:39:30 AM »
Have a look at smeserver-rsync in the contribs repo.

We imported this last year.

https://bugs.contribs.org/show_bug.cgi?id=9476

It possibly has some outstanding bugs but if you install and use it we can probably look at ironing them out.

https://bugs.contribs.org/buglist.cgi?bug_status=__open__&component=smeserver-rsync&product=SME%20Contribs
...
1. Read the Manual
2. Read the Wiki
3. Don't ask for support on Unsupported versions of software
4. I have a job, wife, and kids and do this in my spare time. If you want something fixed, please help.

Bugs are easier than you think: http://wiki.contribs.org/Bugzilla_Help

If you love SME and don't want to lose it, join in: http://wiki.contribs.org/Koozali_Foundation

Offline ReetP

  • *
  • 3,738
  • +5/-0
Re: cron not working
« Reply #10 on: April 17, 2018, 11:48:28 AM »
Tell a lie.... it is still in smetest.

I'd be grateful if you can try it and help iron things out though.

It is the same version you have, but updated for SME v9. However it has some issues (so yours will too) but I'll try and resolve them if you can help.

Check the outstanding bugs.
...
1. Read the Manual
2. Read the Wiki
3. Don't ask for support on Unsupported versions of software
4. I have a job, wife, and kids and do this in my spare time. If you want something fixed, please help.

Bugs are easier than you think: http://wiki.contribs.org/Bugzilla_Help

If you love SME and don't want to lose it, join in: http://wiki.contribs.org/Koozali_Foundation

Offline Jean-Philippe Pialasse

  • *
  • 2,763
  • +11/-0
  • aka Unnilennium
    • http://smeserver.pialasse.com
Re: cron not working
« Reply #11 on: April 17, 2018, 02:22:17 PM »
I Support Reetp, try the imported version in sme test, it has at worst some fixes but not yours, at best your issue is fixed.
It has been renamed smeserver-rsync.

I would not bet on the invisible character, but rather on: are scripts executable, though

What tells cron logs ?

The invisible character is mostly an issue caused by a file created with windows instead of a unix editor. They are usually safe to ignore. 
At worst we can do a dos2unix command on the template file

Offline crazybob

  • ****
  • 894
  • +0/-0
    • Stalzer R&D
Re: cron not working
« Reply #12 on: April 17, 2018, 03:59:03 PM »
trying the imported version, and the script it generaates is
Code: [Select]
#!/bin/bash

# rsync 'driver' script.  (Uses SSH as the transport layer.)
export PATH=$PATH:/bin:/usr/bin:/usr/local/bin

/bin/ps ax > /tmp/check
CHK=`/bin/cat /tmp/check | /bin/grep /usr/bin/rsync`
if ! $CHK ; then
  /bin/echo 'just ignore the warning above, it tells us'
  /bin/echo 'rsync is already running, exiting...'
  exit 0
fi

# Does copy, not so verbose.
OPTS='-u -a --compress     --stats'
    echo 'Begin rsync transfer.'

    echo ''
    echo 'Sending none to none.'
    /usr/bin/rsync $OPTS -e "ssh -p 22" none none:none

    echo 'Ending rsync transfer.'
and does nothing.

Using the same parameters with the dungog swcript, I get the following
Code: [Select]
#!/bin/bash

# rsync 'driver' script.  (Uses SSH as the transport layer.)

export PATH=$PATH:/bin:/usr/bin:/usr/local/bin

# Does copy, not so verbose.
OPTS='-u -a --compress     --stats'
    echo 'Begin rsync transfer.'

    echo ''
    echo 'Recieving /home/e-smith/db/mysql from 192.168.3.1.'
    rsync $OPTS  -e "ssh -p 3522" root@192.168.3.1:/home/e-smith/db/mysql /home/e-smith/files/ibays/server1/files/

    echo ''
    echo 'Recieving /home/e-smith/files/ from 192.168.3.1.'
    rsync $OPTS  -e "ssh -p 3522" root@192.168.3.1:/home/e-smith/files/ /home/e-smith/files/ibays/server1/files/

    echo ''
    echo 'Recieving /var/lib/mysql from 192.168.3.1.'
    rsync $OPTS  -e "ssh -p 3522" root@192.168.3.1:/var/lib/mysql /home/e-smith/files/ibays/server1/files/

    echo 'Ending rsync transfer.'

I had made the adjustments for the ssh port.

I am going to try to use dos2unix on the template file. Trying to figure out the best way to use it.
If you think you know whats going on, you obviously have no idea whats going on!

Offline Jean-Philippe Pialasse

  • *
  • 2,763
  • +11/-0
  • aka Unnilennium
    • http://smeserver.pialasse.com
Re: cron not working
« Reply #13 on: April 17, 2018, 04:15:43 PM »
please report in a bug so we can fix it easily. The main reason we never finished the import, aside from time, is we missed somebody familiar with the contrib to test it and report the issues ;)

Offline ReetP

  • *
  • 3,738
  • +5/-0
Re: cron not working
« Reply #14 on: April 17, 2018, 04:52:39 PM »
@crazybob

I've just fixed a few things on the version in smetest - should now be 1.3-2

This is the first one we have to properly solve I think, which is your issue above:

https://bugs.contribs.org/show_bug.cgi?id=9681

you can check what details are set by looking at:

Code: [Select]
db dungog show
Note that we are never going to 'fix' the old version. From what I can see it is unlikely to ever work properly on v9.

Any fixes will be done via the bugtracker and contribs repo, so if you can help by adding the issues there then we'll try and get it sorted for you.
...
1. Read the Manual
2. Read the Wiki
3. Don't ask for support on Unsupported versions of software
4. I have a job, wife, and kids and do this in my spare time. If you want something fixed, please help.

Bugs are easier than you think: http://wiki.contribs.org/Bugzilla_Help

If you love SME and don't want to lose it, join in: http://wiki.contribs.org/Koozali_Foundation

Offline ReetP

  • *
  • 3,738
  • +5/-0
Re: cron not working
« Reply #15 on: April 17, 2018, 05:47:27 PM »
...
1. Read the Manual
2. Read the Wiki
3. Don't ask for support on Unsupported versions of software
4. I have a job, wife, and kids and do this in my spare time. If you want something fixed, please help.

Bugs are easier than you think: http://wiki.contribs.org/Bugzilla_Help

If you love SME and don't want to lose it, join in: http://wiki.contribs.org/Koozali_Foundation

Offline crazybob

  • ****
  • 894
  • +0/-0
    • Stalzer R&D
Re: cron not working
« Reply #16 on: April 17, 2018, 06:34:57 PM »
Thanks.
I will give it a try later tonight and report results in bugzilla also
If you think you know whats going on, you obviously have no idea whats going on!

Offline crazybob

  • ****
  • 894
  • +0/-0
    • Stalzer R&D
Re: cron not working
« Reply #17 on: April 17, 2018, 07:00:21 PM »
I had a minute, and tried the updated version, and the script that it generated was the same as the previous version.
I will report it in the bug tracker also.

Thanks
If you think you know whats going on, you obviously have no idea whats going on!

Offline ReetP

  • *
  • 3,738
  • +5/-0
Re: cron not working
« Reply #18 on: April 17, 2018, 07:13:23 PM »
Ok... at least we know.

Add it as a bug and we'll try & get it resolved PDQ
...
1. Read the Manual
2. Read the Wiki
3. Don't ask for support on Unsupported versions of software
4. I have a job, wife, and kids and do this in my spare time. If you want something fixed, please help.

Bugs are easier than you think: http://wiki.contribs.org/Bugzilla_Help

If you love SME and don't want to lose it, join in: http://wiki.contribs.org/Koozali_Foundation

Offline crazybob

  • ****
  • 894
  • +0/-0
    • Stalzer R&D
Re: cron not working
« Reply #19 on: April 17, 2018, 07:18:10 PM »
I posted to bug 9681 if that's ok
If you think you know whats going on, you obviously have no idea whats going on!

Offline ReetP

  • *
  • 3,738
  • +5/-0
Re: cron not working
« Reply #20 on: April 17, 2018, 07:20:21 PM »
I posted to bug 9681 if that's ok

Yes that's fine. I saw.

Note I had changed the default Option to Test.

We'll take a look at try and get it working correctly.
...
1. Read the Manual
2. Read the Wiki
3. Don't ask for support on Unsupported versions of software
4. I have a job, wife, and kids and do this in my spare time. If you want something fixed, please help.

Bugs are easier than you think: http://wiki.contribs.org/Bugzilla_Help

If you love SME and don't want to lose it, join in: http://wiki.contribs.org/Koozali_Foundation

Offline CharlieBrady

  • *
  • 6,918
  • +3/-0
Re: cron not working
« Reply #21 on: April 17, 2018, 10:29:14 PM »
Which ^M  or ^Ms should I eliminate?

All of them. You can use dos2unix.

Offline CharlieBrady

  • *
  • 6,918
  • +3/-0
Re: cron not working
« Reply #22 on: April 17, 2018, 10:30:38 PM »
Code: [Select]
{^M
  use esmith::config;^M
  use esmith::db;^M
^M
  local %dungog;^M
  tie %dungog, 'esmith::config', '/home/e-smith/db/dungog';^M
^M
...

Wow, that is really ancient code...

Offline ReetP

  • *
  • 3,738
  • +5/-0
Re: cron not working
« Reply #23 on: April 18, 2018, 01:06:24 AM »
Wow, that is really ancient code...

LOL - it certainly is ;-)
...
1. Read the Manual
2. Read the Wiki
3. Don't ask for support on Unsupported versions of software
4. I have a job, wife, and kids and do this in my spare time. If you want something fixed, please help.

Bugs are easier than you think: http://wiki.contribs.org/Bugzilla_Help

If you love SME and don't want to lose it, join in: http://wiki.contribs.org/Koozali_Foundation

Offline crazybob

  • ****
  • 894
  • +0/-0
    • Stalzer R&D
Re: cron not working
« Reply #24 on: April 18, 2018, 01:39:35 AM »
I did clean it up with dos2unix, and it got rid of the error, but it still will not trigger the transfer. I can trigger it manually from within server-manager screen, or from the command line.
I am still playing with the original dungog version, but with the cleaned up template.
If you think you know whats going on, you obviously have no idea whats going on!

Offline ReetP

  • *
  • 3,738
  • +5/-0
Re: cron not working
« Reply #25 on: April 18, 2018, 03:17:19 AM »
I did clean it up with dos2unix, and it got rid of the error, but it still will not trigger the transfer. I can trigger it manually from within server-manager screen, or from the command line.
I am still playing with the original dungog version, but with the cleaned up template.

OK, but see my notes on the bug.

Simply cleaning the template is not the end of the problem. It might be a quick fix, but not a long term solution, and isn't really a fix in any event.

I'll try and see if I can get something better over the next few days, work allowing. But you aren't ever going to get it working properly doing what you are at the minute. A lot of the code is EXTREMELY old and needs an axe through it.

Don't waste your time on it.

I'll do what I can - watch the bug.
...
1. Read the Manual
2. Read the Wiki
3. Don't ask for support on Unsupported versions of software
4. I have a job, wife, and kids and do this in my spare time. If you want something fixed, please help.

Bugs are easier than you think: http://wiki.contribs.org/Bugzilla_Help

If you love SME and don't want to lose it, join in: http://wiki.contribs.org/Koozali_Foundation

Offline ReetP

  • *
  • 3,738
  • +5/-0
Re: cron not working
« Reply #26 on: May 18, 2018, 08:55:42 PM »
As a further FYI I have recoded the web panel which basically seems to work but will need testing.

I have a weeks holiday and will try and spend a little time trying to finish the other parts so we can build a complete rpm for testing.

Sorry for the delays - earning a crust has got in the way of playtime :-)
...
1. Read the Manual
2. Read the Wiki
3. Don't ask for support on Unsupported versions of software
4. I have a job, wife, and kids and do this in my spare time. If you want something fixed, please help.

Bugs are easier than you think: http://wiki.contribs.org/Bugzilla_Help

If you love SME and don't want to lose it, join in: http://wiki.contribs.org/Koozali_Foundation