LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-30-2004, 02:11 AM   #1
chrisfirestar
Member
 
Registered: Sep 2003
Location: Adelaide, Australia
Distribution: Fedora/RH
Posts: 231

Rep: Reputation: 30
SH SCRIPT +pulling information from a text file


Hi everyone,

I am writting a sh script to automatically copy my log files to another location and then clear the old ones.

the problem is that I dont want these scripts to overwrite each other so i need to add the date to the filename

the command I am using looks like this:
cp access.log history/access_$DATE.log (i have cut out the complete path)

but i want to be able to import the date information from a text file.. (or even better have the script discover the date for itself)

at the moment i have the command

date -d, --date= +%Y%m%d > date.txt

which works fine... however i dont know how to get the SH script to read the information from that file

any idea?

at the moment i have the DATE="date.txt"

which leave the filename access_date.txt.log

Thanks
Chris
 
Old 01-30-2004, 07:14 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
From within your shell script you can do this:

DATE="`date"+%Y%m%d"`"

If you want to use an outside file to get information inside your script (will use your date.txt for the example):

DATE="`cat /full/path/to/date.txt`"

This only gets the expected results if there is only 1 line of data in the date.txt file.

Hope this helps.
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
remove text from file with script paul_mat Linux - Software 3 11-17-2005 12:21 PM
How to find and change a specific text in a text file by using shell script Bassam Programming 1 07-18-2005 07:15 PM
Create text file with a script zael Programming 3 06-02-2004 03:27 AM
Script to read a simple text file ravykanth Linux - Newbie 9 10-22-2003 04:15 AM
how to convert a text file into shell script meng_en Linux - General 9 10-15-2002 10:46 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:05 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
Open Source Consulting | Domain Registration