temporary file to file then move to directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting temporary file to file then move to directory
# 1  
Old 12-01-2011
temporary file to file then move to directory

Ok in my bash script i have 5 options to create a simple html script. I need to create a temporary file and whatever the user types will be stored in that file using html codes. And then I have another option in which that temporary file will be moved to the public_html directory in which the user gets to name the file like WEB.html.

Im not really sure how to create a temporary file and then move everything from the temporary file to a file.

This is what i have so far

create temp file
Code:
htmlcode=$(mktemp ~/tmp/htmlcode.XXXXXXXXXX)
ls > $htmlcode

and this is what i use to move the users input to the temporary file
Code:
echo "$text" >> ~/tmp/htmlcode.XXXXXXXXXX

but when i do this its creating a temp file and a file called htmlcode. It doesnt store in the temp file only in htmlcode?

Last edited by gangsta; 12-01-2011 at 12:16 PM..
# 2  
Old 12-01-2011
Try
Code:
htmlcode=$(mktemp -t htmlcode.XXXXXXXXXX)
...
echo "$text" >> $htmlcode

This User Gave Thanks to CarloM For This Post:
# 3  
Old 12-01-2011
Quote:
Originally Posted by CarloM
Try
Code:
htmlcode=$(mktemp -t htmlcode.XXXXXXXXXX)
...
echo "$text" >> $htmlcode

so this line is to create the temp file? Where is it being created?
Code:
htmlcode=$(mktemp -t htmlcode.XXXXXXXXXX)

and this is to forward the text into the temp file
Code:
echo "$text" >> $htmlcode

# 4  
Old 12-01-2011
It's created in (probably) /tmp - check the man page.
# 5  
Old 12-01-2011
yea its stored in temp, how would i cat the file like

Code:
cat ~/tmp/$WEB

?
# 6  
Old 12-01-2011
Yes (but note that /tmp and ~/tmp are usually not the same thing).
# 7  
Old 12-01-2011
it doesnt work, i tried to add the -> .XXXXXXXXX
didnt work

Code:
cat /tmp/$WEB

its option 2 in my loop, when i enter 2 nothing happens

edit i changed the ;; to break;;

but i get this error

Code:
cat: /tmp//tmp/WEB.DHiVwTnhVc: No such file or directory

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Move file from one directory and update the list file once moved.

Dears, I have a listfile contains list of files path. i need to read the line of the listfile mv the file to other directory and update the listfile by deleting the lines of the listfile. #!/bin/bash target=/fstest/INVESTIG/Sadiq/TEST_ARCH while read -r line || ]; do mv $line... (19 Replies)
Discussion started by: sadique.manzar
19 Replies

2. Shell Programming and Scripting

Shell script cannot create directory and move the file to that directory

I have a script, which is checking if file exists and move it to another directory if then mkdir -p ${LOCL_FILES_DIR}/cool_${Today}/monthly mv report_manual_alloc_rpt_A_I_ASSIGNMENT.${Today}*.csv ${LOCL_FILES_DIR}/cool_${Today}/monthly ... (9 Replies)
Discussion started by: digioleg54
9 Replies

3. Shell Programming and Scripting

How I can find the last file created and move it to a directory?

I have this situation /u03/app/banjobs> ls -ltr icg* 82 Jun 12 10:37 iicgorldi_2419186.log 56810484 Jun 17 10:35 icgorldi_2421592.xml 2859 Jun 17 10:35 icgorldi_2421592.lis - 125 Jun 17 10:35 icgorldi_2421592.log 82 Jun 12 10:37 iicgorldi_2419187.log ... (8 Replies)
Discussion started by: Bernardo Jarami
8 Replies

4. Shell Programming and Scripting

Move file in to directory- script

Hi In directory /mnt/upload I have about 100 000 files (*.png) that have been created during the last six months. Now I need to move them to right folders. eg: file created on 2014-10-10 move to directory /mnt/upload/20141010 file created on 2014-11-11 move to directory /mnt/upload/20141111... (6 Replies)
Discussion started by: primo102
6 Replies

5. UNIX for Dummies Questions & Answers

Mailx - temporary mail message file: No such file or directory

How would I go about resolving this error temporary mail message file: No such file or directory Can anybody tell me where the default location is for the temporary mail message file is for mailx? It appears that it doesn't exist. Thanks (1 Reply)
Discussion started by: joen
1 Replies

6. UNIX for Dummies Questions & Answers

How to move file from one directory to other of only particular user?

I written unix script where a pdf file generates. But if the script is used by multiple people at a time it generates same pdf with two different owner names and creating a problem with permission while moving the file. is there a way where i can move the file filtering with the user? (4 Replies)
Discussion started by: lakers646
4 Replies

7. UNIX for Dummies Questions & Answers

move a file content to another directory

my script is: /u/user/orginal/:#! /bin/ksh find . -name "aur_prog*" -exec grep -il "error" > test.out #awk command to destination directory exit test.out file contain: ./aur_prog1.log ./aur_prog2.log ... (5 Replies)
Discussion started by: roughwal
5 Replies

8. Shell Programming and Scripting

Move the latest or older File from one directory to another Directory

I Need help for one requirement, I want to move the latest/Older file in the folder to another file. File have the datetimestamp in postfix. Example: Source Directory : \a destination Directory : \a\b File1 : xy_MMDDYYYYHHMM.txt (xy_032120101456.txt) File2: xy_MMDDYYYYHHMM.txt... (1 Reply)
Discussion started by: pp_ayyanar
1 Replies

9. Shell Programming and Scripting

A script that will move a file to a directory with the same name and then rename that file

Hello all. I am new to this forum (and somewhat new to UNIX / LINUX - I started using ubuntu 1 year ago).:b: I have the following problem that I have not been able to figure out how to take care of and I was wondering if anyone could help me out.:confused: I have all of my music stored in... (7 Replies)
Discussion started by: marcozd
7 Replies

10. Shell Programming and Scripting

Move a file from windows directory to unix directory

Move a file from windows directory to unix directory, is this possible? if it is, can someone help me on this? Thanks! God bless! (1 Reply)
Discussion started by: kingpeejay
1 Replies
Login or Register to Ask a Question