LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Need help in scripting (https://www.linuxquestions.org/questions/linux-newbie-8/need-help-in-scripting-4175442958/)

azheruddin 12-26-2012 01:34 AM

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

sharadchhetri 12-26-2012 02:07 AM

Quote:

Originally Posted by azheruddin (Post 4856865)
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

markush 12-26-2012 03:41 AM

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

asimba 12-26-2012 08:43 AM

Cron ?

shivaa 12-26-2012 11:50 AM

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

David the H. 12-26-2012 04:01 PM

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/


All times are GMT -5. The time now is 05:15 PM.