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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


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 )


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.
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

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 .......

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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.