Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

unix files

Status
Not open for further replies.

kgiber

MIS
Jun 12, 2001
8
US
Hello,

I need to creat a script that will run in cron that emptys a file with out removing it and transferes to a new sequenced file. Can anyone help?

Thanks
 
hi there

this is what I normally do

--snip--
f=/path/to/the/log/file.txt
mv $f $f.$(date '+%Y%m%d')
cat > $f <<!
!
--snip--

Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Thank you so much for the fast reply!

Would the mv command move the whole file? I have a reference to the file in an application that will not allow me to move or delete the actual file

Thanks Kat
 
I tried it and it worked, I had a problem with the date part. I still have the question about the file. Is it moved or only emptied?

Thanks Kat
 
yea, mv moves the whole file. What I normaly do is essentially the same appending of date to the name and then doing an:
echo &quot;&quot;>filenamehere
This will overwrite existing text with a blank line. HTH.

Mike
 
Actually the command:

[tt]>filename[/tt]

on its own will create the empty file, it's just habit that I use the cat [tt]>filename <<![/tt] trick. Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Mike

I have problelms with the following
It looses it somewhere after the first statement.
And all I get is the forst log.

Can you suggest what I need to do?

Thanks
Kat
f=/home/rm35430/kat/ods00000_sql.log
cp -p $f $f.`date +%y%m%d%H%M`
cat >$f<<!
g=/home/rm35430/kat/ods00100_sql.log
cp -p $g $g.`date +%y%m%d%H%M`
cat >$g<<!
h=/home/rm35430/kat/ods00200_sql.log
cp -p $h $h.`date +%y%m%d%H%M`
cat >$h<<!
mv ods00000_sql.log.* old*
mv ods00100_sql.log.* old*
mv ods00200_sql.log.* old*
 
Hi Kat,

You need to finish the &quot;here-document&quot; thingy (the <<) with whatever characters you put right after that - on a line of its own.

This is a little wierd until you get the hang of it.

These three examples do *EXACTLY* the same thing.

cat > f.txt <<!
hello
!

cat > f.txt <<END
hello
END

cat > f.txt <<SOMETHING_ANYTHING
hello
SOMETHING_ANYTHING

I notice that in the short script you posted that you're not terminating *any* of the here-document things. You need to finish them with a ! on a line of its own.

What is your aim here? To create a log of everything you've done? Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top