File increase


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers File increase
# 1  
Old 11-22-2006
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  
Old 11-22-2006
this would help you Smilie Smilie

Code:
i=1

while [ $i -le 3 ]
do
echo "abcd" > log$i.txt
i=$(($i + 1))
done

# 3  
Old 11-22-2006
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  
Old 11-22-2006
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  
Old 11-22-2006
what do you mean by "each time"?
# 6  
Old 11-23-2006
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  
Old 11-23-2006
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 Smilie
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.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Procedure to increase file system

Hi, How/what is the procedure to increase file system in linux server ? Regards, Maddy (6 Replies)
Discussion started by: Maddy123
6 Replies

2. Solaris

Not able to increase ZFS file system on NGZ

I have Solaris-10 server running ZFS file-system. ctdp04_vs03-pttmsp01 is one of the non global zone. I wanted to increase a /ttms/prod file-system of zone, which is actually /zone/ctdp04_vs03-pttmsp01/ttms/prod on global server. I have added a new disk of 9 GB, which is emcpower56a and now I can... (16 Replies)
Discussion started by: solaris_1977
16 Replies

3. Solaris

increase SWAP on ZFS file system

Hi All, I am using this commands to dynamically increase ZFS swap space on Solaris my question is: 1- after i make these commands it will permanent or it will remove after restart 2- how to make it permanent # swap -l swapfile dev swaplo bloques libre /dev/zvol/dsk/rpool/swap... (4 Replies)
Discussion started by: osmanux
4 Replies

4. Red Hat

Increase root file system size ...

Hello Admins, I am running a redhat linux 5 on vmware workstation. I need to increase or add some more space to my root (/) partition. I don't have any LVM configured.. Please suggest. # df -kh Filesystem Size Used Avail Use% Mounted on /dev/sda2 3.8G 3.1G ... (4 Replies)
Discussion started by: snchaudhari2
4 Replies

5. Solaris

how to increase file size in solaris 10 os

hi, let me know how to increase file size in solaris 10 OS (4 Replies)
Discussion started by: meet2muneer
4 Replies

6. AIX

increase the size of file system

Hi all, we are usig aix 4.3 and i need to increase the size of "/u01" file sytem which is mounted on logical volume "lv00", but "/u01" file system size is 9 GB and logical volume "lvoo" size 9 GB.how do i increase the size of /u01.do i increase the size of logical volume "lv00" and then... (2 Replies)
Discussion started by: younusdba
2 Replies

7. Shell Programming and Scripting

how to increase the integer in a xml file

Hi Need a Script. Problem is I want to increase the integer in a xml file example the xml file is <name> <school> Public School <label>01 </label> </school> </name so when every time when it gets <label> it will increase the value 01 to 02 and store the total increased valued... (7 Replies)
Discussion started by: pranabrana
7 Replies

8. Shell Programming and Scripting

Automatic name file with increase

Hello, A file named c15a is registered on my disc all 10 minutes. I must rename that file with the actually Date and with an automatic increase number on 5 digits, so as : c15a.20070528.00001 and the next file will be : c15a.20070528.00002. The next day so tomorrow the five digits must be... (6 Replies)
Discussion started by: steiner
6 Replies

9. UNIX for Dummies Questions & Answers

Increase space in the solaris file system

How can I check how much space is left in the solaris file system? and how can I increase those space in the file system?. I am trying to install Oracle Database on Solaris 8.But, it keep giving me error message says that"There is not enough space on the volume you have specified". Thanks ... (1 Reply)
Discussion started by: jung1975
1 Replies

10. UNIX for Dummies Questions & Answers

Increase width of Spool file

Hi All This may not be entirely Unix related but I'll just have to try my luck and see if you know how to do this: I need to spool the results of my SQL query into a file but as there are too many fields in the query the resultant spool file put the last few fields on the next line. May I... (2 Replies)
Discussion started by: handynas
2 Replies
Login or Register to Ask a Question