Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Cron job to run .sh script

Posted on 2006-07-17
8
Medium Priority
?
1,342 Views
Last Modified: 2013-12-16
Hi All,

I need to run "voice.sh"

Location = /var/spool/asterisk/

I want it too run every 30 seconds.

How do I do this,

crontab - e

30 * * * * /var/spool/asterisk/voice.sh

Would this work???
0
Comment
Question by:joe90kane
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 15

Expert Comment

by:DonConsolio
ID: 17122268
yes and no :-)

no - cron's smallest time slot is 1 minute (see man crontab)
yes - your can run any program from cron if
- the program runs without any user interaction/gui/terminal
- does not "expect anything" (path, current directory, envirnment variables, etc) set to specific values

0
 
LVL 40

Expert Comment

by:noci
ID: 17122288
Do you need it every 30 seconds?,

cron is done by minutes...

Your example would be once per hour, at 30 minutes...

To have it every 30 seconds may be run another job that does:

File /usr/local/bin/run_voice_twice.sh
---8<---
#!/bin/bash
/var/spool/asterisk/voice.sh
sleep 30
/var/spool/asterisk/voice.sh
---8<---
and be sure that it can be run by the owner of the run_voice_twice.sh

and in cron use:
* * * * * /usr/local/bin/run_voice_twice.sh

Then again if running the voice.sh  script might take more then 30 seconds you may get into trouble because
jobs overwrite something that belongs to an olde still runing job....


btw. /usr/local/bin might be a beter place to store scripts then /var/spool/asterisk....
0
 
LVL 1

Author Comment

by:joe90kane
ID: 17122819
1 minute would be ok,

so it would be

1 * * * * /var/spool/asterisk/voice.sh

The script says

"find ./voicemail/default yada,yada,yada"

would this work???


0
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 
LVL 40

Expert Comment

by:noci
ID: 17124487
No it would be * * * * *,
1 * * * * run every X:01  (1:01, 2:01 etc)

probably the script expects to have a certain default directory ( a common mistake
with script to be cronified...;)

I think you need to make it one of the first things within then voice.sh script
to setup the expected environment:

setup current directory, setup expected variables (your .profile hasn't been run)
setup path if needed.

You can also write a wrapper script that does all that and then runs your
voice.sh

ie.
---8<---
#!/bin/bash

set PATH=$PATH:/whatever/is/needed
set VAR=xxxx
cd /the/directory/that/is/parent/to/voicemail
/var/spool/asterisk/voice.sh
---8<---
0
 
LVL 48

Expert Comment

by:Tintin
ID: 17135606
To run every minute, you need:


* * * * * /var/spool/asterisk/voice.sh
0
 
LVL 1

Author Comment

by:joe90kane
ID: 17137138
Ok how do I know if the script is running every minute??????
0
 
LVL 40

Accepted Solution

by:
noci earned 200 total points
ID: 17139972
Add a line in the script

"date >>/tmp/runlog"

then review the /tmp/runvoice.log
a new line should be added every minute to the /tmp/runvoice.log


---8<---
#!/bin/bash

date >>/tmp/runvoice.log
set PATH=$PATH:/whatever/is/needed
set VAR=xxxx
cd /the/directory/that/is/parent/to/voicemail
/var/spool/asterisk/voice.sh
---8<---

If the script produces any output it will send a mail

btw, please remove the date line afterwards, or your /tmp file system run fillup.

0
 
LVL 48

Expert Comment

by:Tintin
ID: 17141854
To check the status of your cronjobs look in /var/log/cron
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

rdate is a Linux command and the network time protocol for immediate date and time setup from another machine. The clocks are synchronized by entering rdate with the -s switch (command without switch just checks the time but does not set anything). …
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question