Solved

Cron job to run .sh script

Posted on 2006-07-17
8
1,331 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 14

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 39

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
 
LVL 39

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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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 39

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Suggested Solutions

Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
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…
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.:

705 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now