Solved

Cron job to run .sh script

Posted on 2006-07-17
8
1,337 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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 50 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

820 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