LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 10-14-2009, 04:51 AM   #1
Black187
LQ Newbie
 
Registered: Nov 2005
Posts: 26

Rep: Reputation: 0
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?
 
Old 10-14-2009, 04:58 AM   #2
Poetics
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, 05:07 AM   #3
Black187
LQ Newbie
 
Registered: Nov 2005
Posts: 26

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

Shell script:

#!/bin/bash

TODAY=$(date +%D)

echo $TODAY

sed -s ??? file


The sed is bothering me
 
Old 10-14-2009, 06:03 AM   #4
smus
Member
 
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, 07:04 AM   #5
Black187
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

tee
teee2
dfsds
ddddd


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

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

#!/bin/bash

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


Reply


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 11:01 PM
Linux based gateway for time-based wireless service. TotalDefiance Linux - Software 0 10-03-2005 07:06 PM
Time Based Nat roopunix Linux - Networking 2 07-03-2005 09:59 AM
Time Based Nat roopunix Linux - Networking 1 07-03-2005 08:32 AM
Time based applicatioon qmon2002 Programming 7 02-05-2003 12:48 PM


All times are GMT -5. The time now is 10:10 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration