LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-10-2009, 10:25 PM   #1
ling_ss
LQ Newbie
 
Registered: Mar 2009
Posts: 3

Rep: Reputation: 0
Redirect path in csh script


Hi All,

I have lots of csh script that refers to "/tmp" path.
How can I change the "/tmp" to refer to another path.

Eg. ling_test.csh - will copy Test1.csh in /tmp. Instead of copying it to /tmp, how can i copy it to eg."/home/ling/mytmp" without replacing the string "/tmp". Can I have "/tmp" refer to "/home/ling/mytmp" instead?

---ling_test.csh---
#!/bin/csh
cp Test1 /tmp
--------------------

Thank Q
Jess
 
Old 03-11-2009, 10:49 AM   #2
emi_ramo
Member
 
Registered: Apr 2007
Location: Barcelona, Spain
Distribution: Debian, KUbuntu
Posts: 213

Rep: Reputation: 36
May be something like:
Code:
#!/bin/csh
cp Test1 /home/ling/mytmp
I suppose it's not what you're looking for (so obvious), but we need more info to know what exactly you are looking for.
 
Old 03-11-2009, 11:55 AM   #3
bgoodr
Member
 
Registered: Dec 2006
Location: Oregon
Distribution: RHEL[45] {x86,x86_64}, Debian "testing" {x86,x86_64}
Posts: 219

Rep: Reputation: 36
Ditto what emi_ramo said, but also you will be better off going through all scripts and changing the hardcoded reference to "/tmp" to reference a configurable environment variable such as $XYZ_TEMP_DIR (stay away from variables named $TMP_DIR or $TEMP_DIR since they may be used for other programs, and you will probably want to have that change independently). Using a environment variable allows you to change it later without modifying all of your scripts.

Since it sounds like there are truly a lot of scripts to edit, and editing them by hand can be error-prone, you can use sed's edit-in-place mode. If you have some script called "some_script.csh" that contains:
Code:
echo some output >/tmp/logfile.log
Then running this command:
Code:
sed -i 's%/tmp/%${XYZ_TEMP_DIR}/%g' some_script.csh
Edits the file with this result:
Code:
echo some output >${XYZ_TEMP_DIR}/logfile.log
Of course, change the "XYZ" to something specific to your application and not other apps.
 
Old 03-12-2009, 02:02 AM   #4
ling_ss
LQ Newbie
 
Registered: Mar 2009
Posts: 3

Original Poster
Rep: Reputation: 0
The reason for this: I am sharing the machine with another user and will run the same script, writing files to "/tmp". If I were to run the same scripts writing files to "/tmp", it will fail with files already exists.

Therefore I was thinking if I could set "/tmp" in my env to refer to another "Path", so as not to modify all the scripts.

Thanks to bgoodr for the suggestions. However, I have some library files that writes to "/tmp" as well which I do not know which are the ones, until it fails.

Current workaround: Ask the other user to remove the files in "/tmp".
 
Old 03-12-2009, 10:01 AM   #5
bgoodr
Member
 
Registered: Dec 2006
Location: Oregon
Distribution: RHEL[45] {x86,x86_64}, Debian "testing" {x86,x86_64}
Posts: 219

Rep: Reputation: 36
Quote:
Originally Posted by ling_ss View Post
However, I have some library files that writes to "/tmp" as well which I do not know which are the ones, until it fails.
By "library files" I presume you mean executables that are not scripts? Do you have source code corresponding to those files? If not, do a man on the strace program which dumps out system calls such as opening and closing files, sockets, etc., to give you an idea as to when the app writes out files into /tmp.

And perhaps a more basic question: Why isn't /tmp available for the other user? I would think that a Linux session that does not have access to a /tmp would cause many other programs to fail, as many applications have to have a scratch file system to write temporary files too.
 
Old 03-14-2009, 01:58 PM   #6
ling_ss
LQ Newbie
 
Registered: Mar 2009
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by bgoodr View Post
By "library files" I presume you mean executables that are not scripts? Do you have source code corresponding to those files?
Yes, refer to executables. And I don't have the source code.

Quote:
And perhaps a more basic question: Why isn't /tmp available for the other user? I would think that a Linux session that does not have access to a /tmp would cause many other programs to fail, as many applications have to have a scratch file system to write temporary files too.
"/tmp" is available to all user and Linux session should be able to write temporary files too. Problem is, if the files eg. Test1 already written in "/tmp" by user1, user2 is not able to write the same file "Test1" to "/tmp". This lies in the way the script is being written, sadly, not by me.
 
Old 03-15-2009, 01:34 PM   #7
emi_ramo
Member
 
Registered: Apr 2007
Location: Barcelona, Spain
Distribution: Debian, KUbuntu
Posts: 213

Rep: Reputation: 36
Hi again!
You can do a chroot to change normal /tmp behaviour... but first you'll need to prepare the jails (I suppose one for each user going to use scripts and executables) or preparing something still better, with a union between a readonly (pseudo)partition and a writeable memory only one. I don't know how to do this last solution, but all live CDs as Ubuntu, knoppix, etc do that so it couldn't be so difficult.

Hope it helps.
emi
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
set path for solaris 10 csh shell mfstree Solaris / OpenSolaris 2 05-08-2008 04:43 PM
csh script stellafrank Linux - Newbie 3 11-15-2006 07:11 PM
default path and csh jmickens Linux - Enterprise 1 08-24-2005 10:56 AM
Path in csh sstrause Linux - Newbie 2 03-10-2003 03:56 PM


All times are GMT -5. The time now is 04:50 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration