Solved

Cron job to run .sh script

Posted on 2006-07-17
8
1,336 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

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…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
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…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

786 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