 |
 |
 |
 |
| Programming & Packaging A place to discuss programming and packaging. |

1st March 2012, 10:40 AM
|
 |
Registered User
|
|
Join Date: Jun 2011
Posts: 158

|
|
Automatic script execution !
Hello !
How to make an " Automatic script execution " time based.
For example: Execute automaticly " backup.sh " everyday at 00:00 o'clock.
Thanks !
|

1st March 2012, 11:10 AM
|
 |
Un-Retired Administrator
|
|
Join Date: Mar 2004
Location: Salem, Mass USA
Posts: 13,922

|
|
|
Re: Automatic script execution !
I created a cron job for a specific task that I want to run once a day. As I recall, after a bit of research, all I did was add to /etc/crontab, like this:
Code:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
* 1 * * * root /usr/bin/rkhunter --propupd
The red line is, probably most obvious, the line I added. Given my understanding I assume that this will run every day at 1AM. This is my server so it's up 24/7. I believe that I needed to restart the crond service.
PHP Code:
systemctl restart crond.service
My system logs tell me that this works as expected.
__________________
Glenn
The Bassinator © ®
Laptop: Toshiba Satellite / Intel Core 2 Duo 1.73 GHz / 2GB / 160GB / Intel Mobile 945GM/GMS/GME/943/940GML Integrated Graphics
Desktop: BioStar MCP6PB M2+ / AMD Phenom 9750 Quad Core / 4GB / 1TB SATA / 500GB SATA / EVGA GeForce 8400 GS 1GB
|

1st March 2012, 11:24 AM
|
 |
Registered User
|
|
Join Date: Apr 2006
Location: Ohio, USA
Posts: 8,298

|
|
|
Re: Automatic script execution !
Also check out 'anacron' which fits some applications better.
__________________
None are more hopelessly enslaved than those who falsely believe they are free.
Johann Wolfgang von Goethe
|

1st March 2012, 11:30 AM
|
 |
Registered User
|
|
Join Date: Mar 2009
Location: Lancaster, UK
Posts: 883

|
|
|
Re: Automatic script execution !
You could also use crontab. This is user based.
to add/ edit a crontab entry do
to list current ones do
syntax for the jobs is the same as for cron in @bobs post.
Also - bewarned - crontab is very scary at first due to the fact that it uses 'vi'. To change this, type:
Code:
EDITOR=nano #if you want nano
EDITOR='emacs -nw' #if you want emacs in terminal mode
EDITOR=emacs #if you want full emacs mode
EDITOR=vi # to change it back to vi
or any other editor you like.
|

2nd March 2012, 12:08 AM
|
 |
"Shells" (of a sub world)
|
|
Join Date: May 2011
Location: Helvetic Federation (Swissh)
Age: 33
Posts: 2,597

|
|
|
Re: Automatic script execution !
Oh crontab uses vi?
Never figured that one, as i simply did:
Code:
# Get current jobs:
tmpfile=/tmp/cronjobs
crontab -l > $tmpfile
# Edit the file
gedit $tmpfile
# Save it back
crontab $tmpfile
Replace gedit with any editor of your choice.
__________________
Fedora Manual: http://docs.fedoraproject.org
Script-Tools: https://sourceforge.net/projects/script-tools/
sudo st tweak repo toggle livna ; st iso dl-fed && st iso usb
|

2nd March 2012, 12:20 AM
|
|
Registered User
|
|
Join Date: Aug 2009
Location: Waldorf, Maryland
Posts: 6,089

|
|
|
Re: Automatic script execution !
I prefer having a backup of the crontab file anyway.
It works either way, but with a backup, I can restore the system and still not worry about loosing a crontab edit pass between backup and failure...
|

2nd March 2012, 09:46 AM
|
 |
Registered User
|
|
Join Date: Mar 2009
Location: Lancaster, UK
Posts: 883

|
|
|
Re: Automatic script execution !
Quote:
Originally Posted by sea
Oh crontab uses vi?
Never figured that one, as i simply did:
Code:
# Get current jobs:
tmpfile=/tmp/cronjobs
crontab -l > $tmpfile
# Edit the file
gedit $tmpfile
# Save it back
crontab $tmpfile
Replace gedit with any editor of your choice.
|
Oh sea. My oppinion of you just dropped a little - you wriet all those scripts and use gedit? Im not saying it has to be emacs, nano or vi. (cat and sed are acceptable editors!!!)
|

2nd March 2012, 11:44 AM
|
 |
"Shells" (of a sub world)
|
|
Join Date: May 2011
Location: Helvetic Federation (Swissh)
Age: 33
Posts: 2,597

|
|
|
Re: Automatic script execution !
Well to write scripts, i prefer easy marking and copy-paste.
And honestly, i cant friendly with emacs, tried a few times, but gedit is just much less than 1 minute setup and fits all my needs.
But hey, everyone has his own choice preferences.
__________________
Fedora Manual: http://docs.fedoraproject.org
Script-Tools: https://sourceforge.net/projects/script-tools/
sudo st tweak repo toggle livna ; st iso dl-fed && st iso usb
|

3rd March 2012, 06:27 PM
|
 |
Registered User
|
|
Join Date: Nov 2006
Location: Detroit
Posts: 4,612

|
|
|
Re: Automatic script execution !
Quote:
Originally Posted by Adunaic
cat and sed are acceptable editors!!!
|
Bah, real programmers use ed; it's the standard text editor!
Like you I'm surprised that sea writes his scripts in gedit. I just assumed he used Microsoft Word with the Comic Sans font.
Actually that might be an interesting thread: what editor and font people use for programming. Emacs and DejaVu Sans Mono are of course the only correct answers, but it would be fun to see all the incorrect ones!
__________________
OS: Fedora 18 x86_64 | CPU: AMD64 3700+ 2.2GHz | RAM: 2GB PC3200 DDR | Disk: 160GB PATA | Video: ATI Radeon 7500 AGP 64MB | Sound: Turtle Beach Santa Cruz CS4630 | Ethernet: Realtek 8110SC
|

3rd March 2012, 07:21 PM
|
 |
Registered User
|
|
Join Date: Mar 2009
Location: Lancaster, UK
Posts: 883

|
|
|
Re: Automatic script execution !
Quote:
Originally Posted by RupertPupkin
Bah, real programmers use ed; it's the standard text editor!
Like you I'm surprised that sea writes his scripts in gedit. I just assumed he used Microsoft Word with the Comic Sans font.
Actually that might be an interesting thread: what editor and font people use for programming. Emacs and DejaVu Sans Mono are of course the only correct answers, but it would be fun to see all the incorrect ones! 
|
No. Proper programmers use echo and get it right first time!!
|

3rd March 2012, 08:53 PM
|
|
Registered User
|
|
Join Date: Aug 2009
Location: Waldorf, Maryland
Posts: 6,089

|
|
|
Re: Automatic script execution !
Of course, those using echo have to deal with various keyboard issues as well...
But then, they also know how to use head/tail commands to delete lines too
|

4th March 2012, 12:33 AM
|
 |
Registered User
|
|
Join Date: Mar 2009
Location: Lancaster, UK
Posts: 883

|
|
|
Re: Automatic script execution !
I had not thought about using head and tail to delete lines.
|

4th March 2012, 02:37 AM
|
|
Registered User
|
|
Join Date: Aug 2009
Location: Waldorf, Maryland
Posts: 6,089

|
|
|
Re: Automatic script execution !
One random puzzle challenge that came up at work (not a real problem) was how to do random record reads using the bourn shell.
The easy solution was "head -<number> file | tail -1" and that would be the record. The tail utility on Linux has the ability to do both at once, and simplifies the command considerably.
But editing a file still requires separate head/tail unless you use a rather complex awk script to insert the new data.
At one time, I had a cross reference tool for fortran that generated a "call by" table, and a "called by" table. The simplified parser only had to recognize subroutine calls (first pass identified function/subroutine names, then a second passes generated the lists. A third pass would collate the tables and generate the output, all using bourn shell scripts, awk, comm, and sort. Much faster than doing it by hand for required documents for a porting operation on an old HP3000 system.
|

4th March 2012, 07:24 AM
|
 |
Registered User
|
|
Join Date: Apr 2006
Location: Ohio, USA
Posts: 8,298

|
|
|
Re: Automatic script execution !
Quote:
Originally Posted by jpollard
One random puzzle challenge that came up at work (not a real problem) was how to do random record reads using the bourn shell.
The easy solution was "head -<number> file | tail -1" and that would be the record. The tail utility on Linux has the ability to do both at once, and simplifies the command considerably.
|
NO doesn't. 'tail' always prints the last N lines. N can be distance from the bottom or top, but it can't select a middle line.
Quote:
|
But editing a file still requires separate head/tail unless you use a rather complex awk script to insert the new data.
|
sed -n 5,+0p /etc/fstab # print line 5
sed -n 5,7p /etc/fstab # print lines 5-7 inclusive
__________________
None are more hopelessly enslaved than those who falsely believe they are free.
Johann Wolfgang von Goethe
|

4th March 2012, 12:12 PM
|
|
Registered User
|
|
Join Date: Aug 2009
Location: Waldorf, Maryland
Posts: 6,089

|
|
|
Re: Automatic script execution !
Steve, you missed the word "insert". Also that sed is an editor.
And from the manpage on tail:
Quote:
-n, --lines=K
output the last K lines, instead of the last 10; or use -n +K
to output lines starting with the Kth
|
Granted, I haven't tried it as that would seem a bit obscure.
BTW, "head -n" prints the first n lines of a file, "tail -1" prints the last line of the input. So "head -n | tail -1" prints only one line.
... seems the manpage for tail is flat out wrong. All it gives is a "invalid context" for the "or use" entry.
Last edited by jpollard; 4th March 2012 at 01:03 PM.
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
Current GMT-time: 09:11 (Saturday, 18-05-2013)
|
|
 |
 |
 |
 |
|
|