Auto Executing script while changing to a directory
Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
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.
Auto Executing script while changing to a directory
Hello all,
Whenever a user changes to a particular directory, I want to display a customized message like "This Directory contains log files. Do not delete .xyz folder. It will stop functioning of XYZ application."
Prompting the user could have some rather odd side-effects, since it may change the behaviour of built-in scripts.
You would need to limit CLI prompts to logged-in sessions only, and you could even have dialogs open when you tried to open the folder in the GUI (depending on what GUI command they use), and in file management programs such as midnight commander, and so on. You may need to modify quite a few programs to make this work properly.
I suspect the effect of this would just be a lot of people ignoring a lot of messages, so I think you should re-think your approach.
Your question appears to suggest that you want to discourage users from deleting particular files; if so, it would be much easier to simply mark the directories the files are in as un-writable by the users in question. If a directory cannot be written to by a user (or group), then files inside it cannot be deleted by that user (or group).
You may also want to look at programs like sudo, which will give you very fine-grained control over what commands individual users are allowed to use.
UnSpawn,
I tried out your code, but it was giving some error. But I got your idea and it will resolve my problem.
Two questions:
1. Here we are using $@. So, if someone will run `cd /var/log`, this will work fine. But what if someone runs `cd /var ; ls ; cd log`. I don't think this will work in second case.
2. `cd` is builtin bash command, does it mean that i won't be able to find its binary on system ? Actually, i tried to locate binary, but was not able to.
Robert,
I agreed with your opinion. But I am having below scenario:
1. There is no GUI. Everything is done through CLI only.
2. For eg, in Oracle RAC environment, if someone deleted /var/tmp/.oracle then, oracle RAC stops functioning. Only reboot can resolve the issue. /var/tmp/.oracle is owned by oracle. And this type of things are not known to most of the administrator also until you face by yourself.
So, Root,Oracle and some Sudo users have rights to delete /var/tmp/.oracle.
In this can, I can't make this directory unwriteable. I hope it answers most of your concerns.
if someone will run `cd /var/log`, this will work fine. But what if someone runs `cd /var ; ls ; cd log`. I don't think this will work in second case.
True.
Quote:
Originally Posted by p_s_shah
`cd` is builtin bash command, does it mean that i won't be able to find its binary on system
Yes.
Quote:
Originally Posted by p_s_shah
Only reboot can resolve the issue.
Reboot of services you mean, right?
Quote:
Originally Posted by p_s_shah
Root,Oracle and some Sudo users have rights to delete /var/tmp/.oracle. In this can, I can't make this directory unwriteable.
Oracle and Root shouldn't be used by most humans. You could set a "watch" on the dir (Monit, cron, inotify) and act on it. You could also audit users (Rootsh, Sudosh) and act on it (the human I mean).
No. Reboot of server. We faced this issue with Oracle RAC envrionment on Solaris server. Deleting /var/tmp/.oracle totally messed up RAC environment. Confirmed the same with Oracle Metalink.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.