Cron and cron log problem

Discussion in 'Installation/Configuration' started by VaKvas, Nov 12, 2013.

  1. VaKvas

    VaKvas New Member

    Hi all,

    I would like to find out, why my sh script won´t work, because I can´t see any message in cron log.

    In syslog I see this part and it doesn´t look like correct or?


    Code:
    Nov 12 03:41:01 vm8788 /USR/SBIN/CRON[30798]: (root) CMD (/usr/local/ispconfig/server/server.sh 2>&1 > /dev/null | while read line; do echo `/bin/date` "$line" >> /var/log/ispconfig/cron.log; done)
    Nov 12 03:42:01 vm8788 /USR/SBIN/CRON[30807]: (root) CMD (/usr/local/ispconfig/server/server.sh 2>&1 > /dev/null | while read line; do echo `/bin/date` "$line" >> /var/log/ispconfig/cron.log; done)
    Nov 12 03:43:01 vm8788 /USR/SBIN/CRON[30816]: (root) CMD (/usr/local/ispconfig/server/server.sh 2>&1 > /dev/null | while read line; do echo `/bin/date` "$line" >> /var/log/ispconfig/cron.log; done)
    Nov 12 03:44:01 vm8788 /USR/SBIN/CRON[30825]: (root) CMD (/usr/local/ispconfig/server/server.sh 2>&1 > /dev/null | while read line; do echo `/bin/date` "$line" >> /var/log/ispconfig/cron.log; done)


    I create backup.sh. Backup my data to ftp. IF I run script like
    sh /var/backup/backup.sh works correct.

    I put file backup to /etc/cron.d with :

    Code:
    # backup
    0 3 * * * root /var/backup/backup.sh

    Nothing happens. No info in log.
    Thanks for suggestion..
     
  2. Croydon

    Croydon ISPConfig Developer ISPConfig Developer

    Is the bash file executable? (chmod u+x)
    Otherwise the command in the cron has to be
    Code:
    /bin/sh /var/backup/backup.sh
     
  3. VaKvas

    VaKvas New Member

    The same :(

    What do you mean "executable" ?
    With sh /var/backup/backup.sh works correct ..

    And please, can you explain me chmod?

    And what about log? Why I Can´t see something in log file ?

    Thank you !
     
  4. Croydon

    Croydon ISPConfig Developer ISPConfig Developer

    This would be the correct crontab content, if the file is not executable
    Code:
    # backup
    0 3 * * * root /bin/sh /var/backup/backup.sh
    If a file is executable, you can call it without the corresponding program (e. g. sh or bash or php):
    Code:
    /var/backup/backups.sh
    If it is not executable you have to use
    Code:
    sh /var/backup/backups.sh
    chmod changes the permissions on a file (you can google for this).
    Code:
    chmod u+x /var/backup/backup.sh
    adds execution rights for the file owner.

    You can write the output of the script to a log file if you change the cron like this:
    Code:
    # backup
    0 3 * * * root /bin/sh /var/backup/backup.sh > /var/backup/backup.log 2>&1
    The log will be in /var/backup/backup.log then.
     
  5. VaKvas

    VaKvas New Member

    Thank you for your answer !

    This doesn´t help .. no backup runs, no log created :-(


    this is content of backup file in /etc/cron.d/backup
    Code:
    # záloha webu a db
    chmod u+x /var/backup/zaloha.sh
    40 * * * * root sh /var/backup/zaloha.sh > /var/backup/zaloha.log 2>&1
    
    And what about this strange lines in syslog?
    Code:
    Nov 15 18:41:01 vm8788 /USR/SBIN/CRON[12960]: (root) CMD (/usr/local/ispconfig/server/server.sh 2>&1 > /dev/null | while read line; do echo `/bin/date` "$line" >> /var/log/ispconfig/cron.log; done)
    Nov 15 18:42:01 vm8788 /USR/SBIN/CRON[12969]: (root) CMD (/usr/local/ispconfig/server/server.sh 2>&1 > /dev/null | while read line; do echo `/bin/date` "$line" >> /var/log/ispconfig/cron.log; done)
    Nov 15 18:43:01 vm8788 /USR/SBIN/CRON[12978]: (root) CMD (/usr/local/ispconfig/server/server.sh 2>&1 > /dev/null | while read line; do echo `/bin/date` "$line" >> /var/log/ispconfig/cron.log; done)
    Nov 15 18:44:01 vm8788 /USR/SBIN/CRON[12987]: (root) CMD (/usr/local/ispconfig/server/server.sh 2>&1 > /dev/null | while read line; do echo `/bin/date` "$line" >> /var/log/ispconfig/cron.log; done)
    

    BUT .. a found, that a don´t have any log in default
    /var/log/ispconfig/cron.log since I install ispconfig. (two months)

    Should by problém in backup.sh location? It is default directory for web backups...

    Any suggestions? Please help...

    Thank you !
     
    Last edited: Nov 15, 2013
  6. Croydon

    Croydon ISPConfig Developer ISPConfig Developer

    uhm... don't see any errors in these files.

    The entries in syslog are correct, they are created by the ispconfig main cronjob.

    Have you checked if your cron appears in syslog?
    Have you tried restarting cron service (service cron restart or /etc/init.d/cron restart)?
     
  7. VaKvas

    VaKvas New Member

    Cron backup or file zaloha.sh .. no.. no messages in syslog.

    First commad:
    cron: can´t lock /var/run/crond.pid, otherpid may be 15457: resource temporarily unavailable.

    Second commad:
    Restarting periodic command scheduler: cron.

    Still nothing in syslog.

    Seem to, that cron doesn´t know about backup cron in crond.d :-(

    I found some setting about cron in IPSCONFIG.. shoud I allow something in there? (sh .. ?)

    Using Debian 6 (superserver) .
     
    Last edited: Nov 15, 2013
  8. VaKvas

    VaKvas New Member

    Any sugestions ?
    Or can sb tell me how do I setup cron sh script right way ?

    Thank you!
     
  9. VaKvas

    VaKvas New Member

    So,

    If I put line to etc/crontab
    Code:
    0 3 * * * sh /var/scripts/zaloha.sh > /var/scripts/zaloha.log 2>&1
    
    it works correct !!!

    Why it doen´t accept file in etc/cron.d ???

    And this line put to log only errors? Because log is empty...

    Thanks !
     
  10. Croydon

    Croydon ISPConfig Developer ISPConfig Developer

    Maybe you forgot making the file executable in cron.d?

    This command logs all output from the command sent to STDOUT and STDERR.
     
  11. VaKvas

    VaKvas New Member

    How I do script executable? What is the different in this case?

    Thank you !
     
  12. Croydon

    Croydon ISPConfig Developer ISPConfig Developer

    My fault. The scripts in there don't have to be executable.
    I can't see an error inside the script you posted, maybe someone else has an idea why it only works when put into crontab.
     

Share This Page