The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Automatic name file with increase steiner Shell Programming and Scripting 6 05-29-2007 04:14 AM
Increase size of /tmp swap File cmackin SUN Solaris 2 06-01-2006 03:14 PM
HELP! The '/var/adm/message' file increase every few seconds??? cloudsmell UNIX for Dummies Questions & Answers 3 09-17-2002 03:04 PM
HELP! The '/var/adm/message' file increase every few seconds??? cloudsmell Filesystems, Disks and Memory 1 09-16-2002 10:31 PM
Increase width of Spool file handynas UNIX for Dummies Questions & Answers 2 11-20-2001 09:24 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-22-2006
chapmana chapmana is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 23
File increase

Sorry im really new here this is my second post today!

My question is, im trying to write a script and i want to output to a text file but i want each text file to be different so for instance log.txt, log1.txt, log2.txt ect how would i do that?
  #2 (permalink)  
Old 11-22-2006
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,953
this would help you

Code:
i=1

while [ $i -le 3 ]
do
echo "abcd" > log$i.txt
i=$(($i + 1))
done
  #3 (permalink)  
Old 11-22-2006
grial's Avatar
grial grial is offline Forum Advisor  
El UNIX es como un toro
  
 

Join Date: Jun 2006
Location: Madrid (Spain)
Posts: 531
Sometimes, you need to have one log file for each call to your script. If this is your case, some people usually add a suffix to the filename with a timestamp. For instance:

Code:
(...)
TIMESTAMP=$(date +"%d%m%Y%H%M%S")
LOGFILE=/path/to/logfile/file_${TIMESTAMP}.log
(...)
echo "This is me adding a new line!" >> $LOGFILE
(...)
Hope this helps!
Regards.
  #4 (permalink)  
Old 11-22-2006
chapmana chapmana is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 23
Hi,

This is the code im running, now where it says log.txt i want to put a line of code in to create a new file each time and adjust the other log entries

#!/bin/sh
echo STARTING......
date
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
w >>log.txt
echo
echo
echo
echo
echo
"UNZIP FILES"
unzip \*.zip >>log.txt
echo
echo
echo
echo
date >>log.txt
whoami >>log.txt
quota >>log.txt
echo "the task was performed correctly" >>log.txt
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo FINISHED...
  #5 (permalink)  
Old 11-22-2006
grial's Avatar
grial grial is offline Forum Advisor  
El UNIX es como un toro
  
 

Join Date: Jun 2006
Location: Madrid (Spain)
Posts: 531
what do you mean by "each time"?
  #6 (permalink)  
Old 11-23-2006
jam_prasanna jam_prasanna is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 21
i think instead of hardcoding the file name u can parameterize the same by writing a code to take the file name from standard i/p each time u run the script.

here it goes.

#!/bin/sh
echo " enter the file name "
read name
echo STARTING......
date
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
w >> $name
echo
echo
echo
echo
echo
"UNZIP FILES"
unzip \*.zip >>$name
echo
echo
echo
echo
date >>$name
whoami >>$name
quota >>$name
echo "the task was performed correctly" >>$name
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo FINISHED...

i think it works...please reply if it works......as i am also new to scripting

rgds,
jam
  #7 (permalink)  
Old 11-23-2006
grial's Avatar
grial grial is offline Forum Advisor  
El UNIX es como un toro
  
 

Join Date: Jun 2006
Location: Madrid (Spain)
Posts: 531
Now that I see your last post, I guess you didn't understand one of my answers.
I'm going to modify your code to see if you understand it now
Code:
#!/bin/sh
TIMESTAMP=$(date +"%d%m%Y%H%M%S")
name=/path/to/logfile/file_${TIMESTAMP}.log
echo STARTING......
date
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
w >> $name
echo
echo
echo
echo
echo
"UNZIP FILES"
unzip \*.zip >>$name
echo
echo
echo
echo
date >>$name
whoami >>$name
quota >>$name
echo "the task was performed correctly" >>$name
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo
echo FINISHED...
Now, each time you call this script, a new file with a different name will be created.

Regards.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:00 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0