Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 10-14-2009, 03:51 AM   #1
LQ Newbie
Registered: Nov 2005
Posts: 26

Rep: Reputation: 0
Time based script


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?
Old 10-14-2009, 03:58 AM   #2
Senior Member
Registered: Jun 2003
Location: California
Distribution: Slackware
Posts: 1,181

Rep: Reputation: 49
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)?
Old 10-14-2009, 04:07 AM   #3
LQ Newbie
Registered: Nov 2005
Posts: 26

Original Poster
Rep: Reputation: 0
Regarding sed, I tried with this:

Shell script:


TODAY=$(date +%D)

echo $TODAY

sed -s ??? file

The sed is bothering me
Old 10-14-2009, 05:03 AM   #4
Registered: Nov 2005
Location: Turkey
Distribution: Suse
Posts: 104

Rep: Reputation: 16
you can use bash script according to your distro and/or perl if you have programming skills.
Old 10-14-2009, 06:04 AM   #5
LQ Newbie
Registered: Nov 2005
Posts: 26

Original Poster
Rep: Reputation: 0
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


How can I use sed, to edit the file and replace the first line with "bbbb"?
Old 10-14-2009, 06:56 AM   #6
LQ Newbie
Registered: Nov 2005
Posts: 26

Original Poster
Rep: Reputation: 0
I've got it:


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


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
Help with a UNIX script: Need to grab information based on time from a file dba_guy Programming 13 05-28-2008 10:01 PM
Linux based gateway for time-based wireless service. TotalDefiance Linux - Software 0 10-03-2005 06:06 PM
Time Based Nat roopunix Linux - Networking 2 07-03-2005 08:59 AM
Time Based Nat roopunix Linux - Networking 1 07-03-2005 07:32 AM
Time based applicatioon qmon2002 Programming 7 02-05-2003 11:48 AM > Forums > Linux Forums > Linux - Newbie

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

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