Start crontab

boby87000 Posted messages 132 Status Member -  
dubcek Posted messages 18627 Registration date   Status Contributor Last intervention   -
Hello,
here is my crontab command that is not executing

*/5 * * * * /usr/local/bin/purge_db.sh
// my script that crontab should run every 5 minutes
#!/bin/bash
mysql SERVER -pstaines < SQL1.txt
// the content of SQL1.txt
DELETE FROM LOG_FILE WHERE DATE < SUBDATE(NOW(), INTERVAL 1 DAY)
Configuration: Windows XP Firefox 3.0.6

22 answers

  • 1
  • 2
  1. dubcek Posted messages 18627 Registration date   Status Contributor Last intervention   5 659
     
    Is cron running?
    ps -ef | grep cron
    Is the script executable?
    chmod u+x /usr/local/bin/purge_db.sh
    Is it running as root?
    1
  2. PeJo309
     
    Hello,

    Be careful because on some platforms like HP-UX it is not possible to use */n in the crontab.
    You then have to type out 5,10,15....

    Have a good day.
    0
  3. boby87000 Posted messages 132 Status Member
     
    ok
    I'll try
    thank you
    0
  4. dubcek Posted messages 18627 Registration date   Status Contributor Last intervention   5 659
     
    hello
    the script runs without environment, .bashrc is not executed by cron
    put
    source ~/.bashrc
    at the beginning of the script
    0
  5. boby87000 Posted messages 132 Status Member
     
    It still doesn't work
    I added
    #!/.bashrc
    #!/bin/bash
    mysql SERVER -pstaines < SQL1.txt
    // the content of SQL1.txt
    DELETE FROM LOG_FILE WHERE DATE < SUBDATE(NOW(), INTERVAL 1 DAY)
    0
  6. dubcek Posted messages 18627 Registration date   Status Contributor Last intervention   5 659
     
    non, like this:

    #!/bin/bash
    source ~/.bashrc
    mysql SERVER -pstaines < SQL1.txt
    0
  7. boby87000 Posted messages 132 Status Member
     
    ok I'm trying
    thank you
    0
  8. boby87000 Posted messages 132 Status Member
     
    Here is the translation: ```html Here is my script and it still doesn't work, that is to say, nothing happens!!!
    #!/bin/bash
    source ~/.bashrc
    mysql SERVER -pstaines < SQL1.txt
    thank you ```
    0
  9. boby87000 Posted messages 132 Status Member
     
    when I run the command ps -ef | grep cron

    root 4536 1 0 Feb03 ? 00:00:00 /usr/sbin/cron
    root 8530 6953 0 16:16 pts/0 00:00:00 grep cron

    I am logged in as root
    0
  10. dubcek Posted messages 18627 Registration date   Status Contributor Last intervention   5 659
     
    is mysql in the root PATH?
    0
  11. boby87000 Posted messages 132 Status Member
     
    yes, because when I run it manually without the crontab, it works.
    0
  12. dubcek Posted messages 18627 Registration date   Status Contributor Last intervention   5 659
     
    see what’s happening in a file
    */5 * * * * /usr/local/bin/purge_db.sh > /tmp/log 2>&1
    also check in /var/log
    0
  13. boby87000 Posted messages 132 Status Member
     
    In my log I have:

    apache2 auth.log.3.gz daemon.log.2.gz dist-upgrade dpkg.log kern.log.0 mail.info messages.3.gz mysql.log.4.gz syslog.0 udev
    apparmor boot daemon.log.3.gz dmesg dpkg.log.1 kern.log.1.gz mail.log mysql mysql.log.5.gz syslog.1.gz user.log
    apt btmp debug dmesg.0 dpkg.log.2.gz kern.log.2.gz mail.warn mysql.err mysql.log.6.gz syslog.2.gz wtmp
    auth.log btmp.1 debug.0 dmesg.1.gz faillog kern.log.3.gz messages mysql.log mysql.log.7.gz syslog.3.gz wtmp.1
    auth.log.0 daemon.log debug.1.gz dmesg.2.gz fsck lastlog messages.0 mysql.log.1.gz news syslog.4.gz
    auth.log.1.gz daemon.log.0 debug.2.gz dmesg.3.gz installer lpr.log messages.1.gz mysql.log.2.gz pycentral.log syslog.5.gz
    auth.log.2.gz daemon.log.1.gz debug.3.gz dmesg.4.gz kern.log mail.err messages.2.gz mysql.log.3.gz syslog syslog.6.gz
    0
  14. dubcek Posted messages 18627 Registration date   Status Contributor Last intervention   5 659
     
    The cron configuration varies depending on the systems. Use man cron to see how to create a log of jobs running by cron.
    0
  15. boby87000 Posted messages 132 Status Member
     
    ok!
    when I run cron -f I have
    cron: can't lock /var/run/crond.pid, otherpid may be 4536: Resource temporarily unavailable

    how do I make it active
    0
  16. dubcek Posted messages 18627 Registration date   Status Contributor Last intervention   5 659
     
    It means that cron is already running.
    0
  17. boby87000 Posted messages 132 Status Member
     
    I'm in a bad situation because it’s overwhelming me now
    I don't understand anything anymore!!
    0
  18. dubcek Posted messages 18627 Registration date   Status Contributor Last intervention   5 659
     
    Is there a file /tmp/log?
    0
  19. boby87000 Posted messages 132 Status Member
     
    When I go to /tmp and I type vim log, I get:

    /usr/local/bin/purge_db.sh: line 3: SQL1.txt: No such file or directory
    0
  20. dubcek Posted messages 18627 Registration date   Status Contributor Last intervention   5 659
     
    When your script starts as root, it is in / so it cannot find the file /SQL1.txt.
    0
  • 1
  • 2