Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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.
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".
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.