LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Time based script (https://www.linuxquestions.org/questions/linux-newbie-8/time-based-script-761768/)

Black187 10-14-2009 03:51 AM

Time based script
 
Hello,

How can I make a script which will run every day at 3 oclock, and will modify content of one specific file.

The modify script must be like this:

Edit a txt file, check for timestamp and replace it with today's timestamp

How can I make this kind of modify script?

Poetics 10-14-2009 03:58 AM

You'd first want to check out the `cron` feature -- it lets you run a script or command at a specified time/interval (every Wednesday at 4pm, or every 7 minutes, or almost whatever configuration you'd like).

As for the script itself, what have you tried so far, and in what programming/scripting languages (including sed)?

Black187 10-14-2009 04:07 AM

Regarding sed, I tried with this:

Shell script:

#!/bin/bash

TODAY=$(date +%D)

echo $TODAY

sed -s ??? file


The sed is bothering me :(

smus 10-14-2009 05:03 AM

you can use bash script according to your distro and/or perl if you have programming skills.

Black187 10-14-2009 06:04 AM

I do not have a good programing skills.
Right now, all I need is to replace first line in my file with a my string.

How can this be done with sed?

The file test.txt looks like this

tee
teee2
dfsds
ddddd


How can I use sed, to edit the file and replace the first line with "bbbb"?

Black187 10-14-2009 06:56 AM

I've got it:

#!/bin/bash

sed -i -e "1c\\#`date`" test.txt


All times are GMT -5. The time now is 08:11 PM.