LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 12-26-2012, 01:34 AM   #1
azheruddin
Member
 
Registered: Dec 2011
Posts: 91
Blog Entries: 1

Rep: Reputation: Disabled
Need help in scripting


Hi All,
Situation Like this.

iam runnning one script for every hour for sometask
iam doing it through date variable

so like this..

if time=12:00 |some task >infile
if time=1:00 |some task >infile
if time=2:00 |some task >infile

so here i want to change time variable automatic for every after an hour and result should append.

now iam running script for every hour manually..
i want to make it auto
 
Old 12-26-2012, 02:07 AM   #2
sharadchhetri
Member
 
Registered: Aug 2008
Location: INDIA
Distribution: Redhat,Debian,Suse,Windows
Posts: 179

Rep: Reputation: 23
Quote:
Originally Posted by azheruddin View Post
Hi All,
Situation Like this.

iam runnning one script for every hour for sometask
iam doing it through date variable

so like this..

if time=12:00 |some task >infile
if time=1:00 |some task >infile
if time=2:00 |some task >infile

so here i want to change time variable automatic for every after an hour and result should append.

now iam running script for every hour manually..
i want to make it auto
try with while true loop
eg.

#!/bin/bash

# This generates a file every 5 minutes

while true; do
touch pic-`date +%s`.jpg
sleep 300
done

for ref. http://tldp.org/LDP/Bash-Beginners-G...ect_09_02.html
 
Old 12-26-2012, 03:41 AM   #3
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: Disabled
You should use cron, read the manpage for crond. With cron you can make a job done every hour.

As for the time variable, if you want to set a variable to the time you could use for example
Code:
time=$(date +%F_%H)
where %F displays the date and %H is the hour.
Code:
markus@samsung:~$ time=$(date +%F_%H)
markus@samsung:~$ echo $time
2012-12-26_10
Markus
 
2 members found this post helpful.
Old 12-26-2012, 08:43 AM   #4
asimba
Member
 
Registered: Mar 2005
Location: 127.0.0.0
Distribution: Red Hat / Fedora
Posts: 355

Rep: Reputation: 42
Cron ?
 
Old 12-26-2012, 11:50 AM   #5
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
If your purpose is only to run your script per hour, then you can add it to crontab as:
Code:
0 */1 * * * /path/to/script
 
Old 12-26-2012, 04:01 PM   #6
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
cron is a program (one of several, but the most commonly-used because it's available on almost all systems) that schedules the running of other programs.

Instead of trying to handle the timing inside your script, so that it would have to be always running, make the script do the job only once, but set cron to run it when you need it to.


Here are a couple of useful-looking links I just grabbed off the web:
http://www.cyberciti.biz/faq/how-do-...-or-unix-oses/
http://kvz.io/blog/2007/07/29/schedu...using-crontab/
 
  


Reply



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
Scripting Help thudpuppy Linux - Newbie 4 06-23-2012 03:00 PM
LXer: Scripting the Linux desktop, Part 2: Scripting Nautilus LXer Syndicated Linux News 0 02-17-2011 04:02 AM
Firefox Scripting Add-on (Scripting HTML / Javascript inside Firefox) linuxbeatswindows Programming 1 09-18-2009 10:09 PM
new in scripting bob4linux Programming 10 10-27-2007 05:54 PM
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 04:29 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:23 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration