2

I'm running these commands on crontab and it seems that the script are not running every 5 minutes

5 * * * /etc/my_scripts/telnet.sh | telnet >> /tmp/top_Jay.txt
5 * * * /etc/my_scripts/telnet_lab.sh | telnet >> /tmp/top_Lab.txt
1
  • After the suggested corrections, are you getting any email from cron? Anything appearing in the files in /tmp ? Commented Oct 15, 2015 at 21:52

5 Answers 5

4

5 * * * * .../script means to run .../script at 5 mins past every hour.

*/5 * * * * .../script means to run the script every 5 minutes.

Also, I'm not entirely sure whether the pipe to telnet will work in cron (it depends on whether your cron forks a shell to run your command or not). You'd be better off rewriting your script so that the pipe to telnet occurs inside the script (which can be as simple as wrapping it in ( ... ) | telnet....and you'd certainly be better off rewriting your script as an expect script rather than a shell script - expect is designed for exactly this kind of job.

2
  • here's an example of a telnet expect script: unix.stackexchange.com/questions/184666/… Commented Oct 15, 2015 at 22:31
  • This is the correct answer, and yet it is at the bottom of the thread. Commented Oct 15, 2015 at 23:32
3

You need another * before command

The columns are

mins, hrs, day of month, month of year, day of week, command
1
  • error corrected but still doesn't work. Any suggestion? 5 * * * * /etc/my_scripts/telnet.sh | telnet >> /tmp/top_Jay.txt 5 * * * * /etc/my_scripts/telnet_lab.sh | telnet >> /tmp/top_Lab.txt Commented Oct 15, 2015 at 19:05
2

You need one more *

The format is:

  1. minute
  2. hour
  3. day-of-month
  4. month
  5. day-of-week
  6. command

Update

Also if you just put 5 in the first field, your command will only be executed 5 minutes after the full hour. To have it executed every 5 minutes it should be */5

3
  • error corrected but still doesn't work. Any suggestion? 5 * * * * /etc/my_scripts/telnet.sh | telnet >> /tmp/top_Jay.txt 5 * * * * /etc/my_scripts/telnet_lab.sh | telnet >> /tmp/top_Lab.txt Commented Oct 15, 2015 at 19:04
  • Are /etc/my_scripts/telnet.sh and /etc/my_scripts/telnet_lab.sh executable? Commented Oct 15, 2015 at 19:07
  • 1
    See unix.stackexchange.com/a/236521/47864: 5 *... means to run it at five minutes past the hour. */5 * ... means to run it every five minutes. Commented Oct 15, 2015 at 23:33
1

The syntax should have 5 fields :

*     *     *   *    *        command to be executed
-     -     -   -    -
|     |     |   |    |
|     |     |   |    +----- day of week (0 - 6) (Sunday=0)
|     |     |   +------- month (1 - 12)
|     |     +--------- day of        month (1 - 31)
|     +----------- hour (0 - 23)
+------------- min (0 - 59)
3
  • error corrected but still doesn't work. Any suggestion? 5 * * * * /etc/my_scripts/telnet.sh | telnet >> /tmp/top_Jay.txt 5 * * * * /etc/my_scripts/telnet_lab.sh | telnet >> /tmp/top_Lab.txt Commented Oct 15, 2015 at 19:04
  • In this case I think you should give us more informations : ) why you pipe telnet? what does your script do? Commented Oct 15, 2015 at 19:11
  • Did you tried to forget cron for a while and execute your script manually? It would make simpler to localize the problem Commented Oct 15, 2015 at 19:17
-1

You need to add one star. The crontab spec says that there are 5 fields for the time specification.

2
  • error corrected but still doesn't work. Any suggestion? 5 * * * * /etc/my_scripts/telnet.sh | telnet >> /tmp/top_Jay.txt 5 * * * * /etc/my_scripts/telnet_lab.sh | telnet >> /tmp/top_Lab.txt Commented Oct 15, 2015 at 19:04
  • Cron usually sends you a mail with the status report for failing commands. Did you get such a mail? Commented Oct 15, 2015 at 20:22

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.