How to create temp file in remote directory?

How am I going to create temp file in a remote rather than current directory when executing a script because I don't want my directory to look messy with lots of temp file.

For example:

When executing a script in /home/bin, lots of temp files are created here. My quetion is how to create them in a remote directory such as /tmp/garbbage and yet they won't exist in the /home/bin directory.

Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

tel2Connect With a Mentor Commented:

So, I'm assuming you are happy that my_script is run from /home/garbbage, but you don't want to go there to run it - right?  If so...


1. Edit my_script so the first thing it does is:
  cd /home/garbbage
This should not effect YOUR pwd - just that of the script's environment as it executes.

2. If you don't want to change my_script, create another script (eg: /home/bin/my_script2), which consists of:
  cd /home/garbbage
Then run my_script2 instead.

Let me know how you get on.

a) If you are saying, the script creates temporary files in the present-working-directory (pwd) of the user, then can you just:
  cd /home/garbbage

b) If you are saying, the script creates temporary files in the directory where it resides, can't you just:
  cd /home/bin
  mv the_script /home/garbbage
However, this might cause problems for other users of the script, or it might not "like" being run from elsewhere.
Perhaps create a link to the script, from /home/garbbage:
  cd /home/garbbage
  ln -s /home/bin/the_script the_script

c) If you are saying, the script contains explicit references to /home/bin, for it's temporary files, then you would have to change the script.

d) Maybe you could append the script with some lines which delete the temporary files apon completion.

1. Which of the above are the case?
2. Are the temporary files a problem to you just for the duration of the script, or do they hang around after it's finished running?
3. Can they be deleted after it's finished running?
qiang8Author Commented:
My_script resides in /home/bin. When executing the script, some temp files are created and of course these temp files will be deleted (written in the scripts to remove all these temp files after finishing ). During the period of execution, temp files are created within the working directory. During this time, this directory looks messy with all these tenp files.  

/home/bin  ttime
tmpf          tmpp1         ttime*  tmpf1         tmppfile      

My question is how to make these temp files created/appear only in the /home/garbage but not in the current directory.

/home/bin  ttime
ttime*   ( No temp files created here while executing the scripts )

tmpf          tmpp1         tmpf1         tmppfile      
( temp files were created here )

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


I think I understand your question, but I need some more detail before I can answer it.

1. If you run the script when your pwd is /home/garbbage, where do the temp files appear?  If they still appear in /home/bin, then answer question 2.

2. In order to find out if my item c) is the case, could you please temporarily (at least) move the script to /home/garbbage:
  mv /home/bin/my_script /home/garbbage
  cd /home/garbbage
then run it again:
and see where the temp files appear.
If they still appear in /home/bin, then we can be pretty sure that there are hardcoded references to /home/bin in the script, and we will know that the script itself has to be changed.

I await your reply.
qiang8Author Commented:
No, they only appear in the pwd. They are not hardcoded references to /home/bin in the script.

.... I want them(temp files) to be hardcoded to /home/garbage ....... so that when I try to do other things in the pwd, I won't get irritated by those garbage temp files.

Pls advise and thanks a lot .......
qiang8Author Commented:
Thank you very much ...... and is there any way to say set the temp file like this:

set tmp=/home/garbage/temp
(so that temp file are created there )


I think so.  Then instead of having:
  cd /home/garbbage
you could have:
  cd $tmp
but I think you would have to "set tmp=..." AND "export tmp" before running the script.
All Courses

From novice to tech pro — start learning today.