Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Cron job to run .sh script

Posted on 2006-07-17
8
Medium Priority
?
1,343 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
  • 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
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
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 several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month8 days, 8 hours left to enroll

876 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