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
  • After the suggested corrections, are you getting any email from cron? Anything appearing in the files in /tmp ? – Mark Plotnick Oct 15 '15 at 21:52
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.

3

You need another * before command

The columns are

mins, hrs, day of month, month of year, day of week, command
  • 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 – Federi Oct 15 '15 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

  • 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 – Federi Oct 15 '15 at 19:04
  • Are /etc/my_scripts/telnet.sh and /etc/my_scripts/telnet_lab.sh executable? – Thomas Weinbrenner Oct 15 '15 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. – Josh The Geek Oct 15 '15 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)
  • 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 – Federi Oct 15 '15 at 19:04
  • In this case I think you should give us more informations : ) why you pipe telnet? what does your script do? – lese Oct 15 '15 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 – lese Oct 15 '15 at 19:17
-1

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

  • 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 – Federi Oct 15 '15 at 19:04
  • Cron usually sends you a mail with the status report for failing commands. Did you get such a mail? – schily Oct 15 '15 at 20:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.