LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 08-07-2011, 12:48 PM   #1
DuskFall
LQ Newbie
 
Registered: Aug 2011
Posts: 18

Rep: Reputation: Disabled
Make a bash script into a daemon


So i've written a script that will move some files from one directory to another, i dont know if this is the right place to ask but, this is on my ipod touch and i'm wondering how to make it run periodicaly
Thanks in advance
 
Old 08-07-2011, 01:53 PM   #2
paulmarc
LQ Newbie
 
Registered: Jul 2011
Distribution: Fedora
Posts: 11

Rep: Reputation: 4
Post Crontab is used to run scripts periodically

You can have it run periodically by adding your script in a crontab.
To do that, execute the following:
Code:
[username@hostname ~]$ crontab -e
That should open your default shell editor, where you can specify crontabs, which are commands run periodically.
To make your script run periodically, add the following line:
Code:
MM HH dd mm ww /the/full/path/to/your/script
Where:
  • MM: Minutes (0-59)
  • HH: Hours (0-23)
  • dd: Day of month (1-31)
  • mm: Month (1-12)
  • ww: Day of the week (0-7), 0=7=Sunday
  • Use '*' to denote 'any' or 'every'
You can check if your crontab was stored by executing:
Code:
[username@hostname ~]$ crontab -l
For example, to have your script run each day, at 16:00, add the following line:
Code:
00 16 * * * /the/full/path/to/your/script
Note that it's important to include the full path of your script, to make sure it runs.
As a rule of thumb, to test if your script will run properly, go to your home directory and run your script by calling it using the full path.
If it runs correctly, you're good. You can always put a crontab that run in few minutes, and check if it does run properly.

Let me know if you need assistance in editing your crontab.

NOTE: Do you intend to run the script from your iPod, periodically? If yes, how do you access it? Via SSH or local terminal?

Last edited by paulmarc; 08-07-2011 at 01:58 PM. Reason: Misunderstood premise
 
1 members found this post helpful.
Old 08-07-2011, 02:58 PM   #3
DuskFall
LQ Newbie
 
Registered: Aug 2011
Posts: 18

Original Poster
Rep: Reputation: Disabled
I've written it and tested it in local terminal, and it works fine, but i dont know how to A) see if its running or functioning, and B) sorry but i dont think my ipod has crontab, i looked for it with ps -A but there was no reference to it. And yes i'm running it via local terminal on the device. Thank you for helping...
 
Old 08-07-2011, 04:01 PM   #4
paulmarc
LQ Newbie
 
Registered: Jul 2011
Distribution: Fedora
Posts: 11

Rep: Reputation: 4
Post Need cron on iPod, can use launchd

To see if your script is running, try outputting things to a file during its execution, and open that file to see if it's indeed running.
Now, "B" is the issue, and we can fix it in 2 ways:
  1. Install cron on iPod
  2. Use launchd
I don't know if there's yet a cron port to the iOS , so "1" might be a problem.
However, we can do "2", since launchd comes on iOS.
To use launchd, you need to create an XML plist file in [/Library/LaunchDaemons], do a couple of steps and that's it ...
Create the file [/Library/LaunchDaemons/com.scripts.myscript.plist] and have its content as follows (in bold what you need to change):
Code:
<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE plist PUBLIC “-//Apple//DTD PLIST 1.0//EN” “http://www.apple.com/DTDs/PropertyList-1.0.dtd”>
<plist version=”1.0″>
<dict>
    <key>Label</key>
    <string>scripts.myscript</string>
    <key>OnDemand</key>
    <true/>
    <key>Program</key>
    <string>/the/full/path/to/your/script.sh</string>
    <key>StartCalendarInterval</key>
    <dict>
        <key>Hour</key>
        <integer>16</integer>
        <key>Minute</key>
        <integer>0</integer>
    </dict>
</dict>
</plist>
The key tags for the cron are follows:
  • Minute
  • Hour
  • Day
  • Weekday
  • Month
They should be followed by an <integer> tag, to specify their value.
If you don't specify a tag, it will be as if you used '*' in cron.
The plist file name can be whatever you want, mind you, so use what you think is logical.
Now, you need to let launchd know about your plist entry, so execute:
Code:
iPod:~ mobile$ launchctl load /Library/LaunchDaemons/com.scripts.myscript.plist
And it's done (hopefully)!
You can always check the launchctl man page.
 
1 members found this post helpful.
Old 08-07-2011, 04:28 PM   #5
DuskFall
LQ Newbie
 
Registered: Aug 2011
Posts: 18

Original Poster
Rep: Reputation: Disabled
YES, thats exactly what I was after, thank you so much I'd pieced together parts of a launchdaemon but didnt know you have to let launchctl know its there... Thank you so much
 
Old 08-07-2011, 04:34 PM   #6
DuskFall
LQ Newbie
 
Registered: Aug 2011
Posts: 18

Original Poster
Rep: Reputation: Disabled
Thinking about it, how would I make it run every 5 minutes?
 
Old 08-08-2011, 04:46 AM   #7
paulmarc
LQ Newbie
 
Registered: Jul 2011
Distribution: Fedora
Posts: 11

Rep: Reputation: 4
Post Can have multiple time entries

You can have multiple <dict><key> time entries, like:
Code:
    <dict>
        <key>Minute</key>
        <integer>0</integer>
    </dict>
    <dict>
        <key>Minute</key>
        <integer>30</integer>
    </dict>
That would run each 30 minutes...
Now, I don't know how to make it in another way, but if you want to have it each 5 minutes using this method, you need 12 entries ...
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script running as daemon Satriani Programming 12 03-29-2011 06:23 PM
Run my bash script as a daemon. jaimese Linux - Newbie 12 02-10-2011 04:28 PM
Bash script to toggle a daemon (here proftpd) dEM0nsTAr Programming 17 01-07-2010 10:17 PM
Bash script to verify the daemon is working if not, start the daemon kishoreru Linux - Newbie 7 09-23-2009 05:29 AM
how can I get/make a proper squid daemon startup script for boot time binkybuckle Debian 0 07-05-2003 08:58 PM


All times are GMT -5. The time now is 08:55 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration