Results 1 to 5 of 5

Thread: Execute a batch file every hour

  1. #1
    Join Date
    Sep 2015
    Location
    Italia
    Beans
    87
    Distro
    Ubuntu 16.04 Xenial Xerus

    Execute a batch file every hour

    Dear users,

    I created a batch file. I want to execute it every hour as root user.

    The batch file is in /srv/cmd/, I created a symbolic link in /etc/cron.hourly but it doesn't work.

    How can I fix?

    Thanks

  2. #2
    Join Date
    Jul 2007
    Location
    Magic City of the Plains
    Beans
    Hidden!
    Distro
    Xubuntu 17.10 Artful Aardvark

    Re: Execute a batch file every hour

    Do you mean a bash script? I haven't heard the term batch file in quite a long time.

  3. #3
    Join Date
    Feb 2009
    Location
    Dallas, TX
    Beans
    7,766
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: Execute a batch file every hour

    Hi dam034.

    I would start checking the permissions. Could you run these commands and post back the results? (You can copy/paste the text. Please use CODE tags)
    Code:
    ls -l /srv/cmd/your_script
    
    ls -ls  /etc/cron.hourly/link_to_your_script
    Then I would double check (1) you have the proper shebang, (2) that the commands you are executing are in the PATH (which is usually not the same that the default you use for regular users), and finally (3) revise if you have interactive content that won't work on a cron script.

    The easiest way to help you would be to post the script.

    Regards.

  4. #4
    Join Date
    Sep 2015
    Location
    Italia
    Beans
    87
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: Execute a batch file every hour

    These are the commands:

    Code:
    root@ubrouter:/srv/cmd# ls -l
    totale 8
    -rwxrwx--- 1 dam034 apgr 445 feb 12 18:36 aggiornamento.sh
    -rwxrwx--- 1 dam034 apgr 320 feb 13 00:54 registro.log
    Code:
    root@ubrouter:/etc/cron.hourly# ls -l
    totale 0
    lrwxrwxrwx 1 root root 33 feb 12 18:35 ddns.sh -> /srv/cmd/aggiornamento.sh
    As you can see, I want to execute the command as root user.


    What is the matter?

    Thanks

  5. #5
    Join Date
    Apr 2012
    Beans
    7,159

    Re: Execute a batch file every hour

    Filenames (and I assume this applies to symlinks as well) in the /etc/cron.houly, /etc/cron.daily etc. directories have some particular requirements. Form the DEBIAN SPECIFIC section of `man cron`:

    Code:
           As  described  above, the files under these directories have to be pass
           some sanity checks including the following: be executable, be owned  by
           root,  not  be  writable  by  group or other and, if symlinks, point to
           files owned by root. Additionally, the file names must conform  to  the
           filename  requirements  of  run-parts: they must be entirely made up of
           letters, digits and can only  contain  the  special  signs  underscores
           ('_')  and  hyphens  ('-').  Any  file  that  does not conform to these
           requirements will not be executed by run-parts.  For example, any  file
           containing  dots  will  be  ignored.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •