execute shell file in Ubuntu by crontab

Asked

Viewed 1,801 times

2

I’m trying to make a task schedule on linux to run a file sh, does not, however, implement the crontab, but execute when I do it in hand.

I did a scheduling test to create a text file, it works, but to run the sh nay.

Follow the settings:

Settings of /etc/crontab:

*/1 * * * * root /home/user/selamat.sh

I’ve tried it like this:

*/1 * * * * root sh /home/user/selamat.sh

And so:

 */1 * * * * root (cd/home/user/ && ./selamat.sh >> Script.log 2>&1)

The shell script settings:

#!/bin/bash

zenity --info --text "SELAMAT";

This script opens a popup.

  • 1

    Does the file have execution permission? If not, give the command chmod +x filename.

  • Already consulted the logs?

  • 1

    There is a chance that zenity is not being found either. It’s usually a good idea to use absolute paths in commands within shell scripts.

  • In some distros, there is an option to put a kind of cron per user, with a file cron somewhere in the HOME user’s

1 answer

1

First, you should be given permission to run the script (you may already have).

chmod +x /home/user/selamat.sh

Put in crontab:

*/1 * * * * /home/user/selamat.sh

If you want to edit the current crontab user file. It can be allowed tbm.

crontab -e

After this, execute the command: crontab /etc/crontab

Then I restarted the cron

/etc/init.d/cron restart

Call us when you can. ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.