LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 11-12-2008, 12:21 PM   #1
p_s_shah
Member
 
Registered: Mar 2005
Location: India
Distribution: RHEL 3/4, Solaris 8/9/10, Fedora 4/8, Redhat Linux 9
Posts: 237
Blog Entries: 1

Rep: Reputation: 34
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."

Any clues how can i set it up ?
 
Old 11-12-2008, 01:51 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
In Bash centrally source some alias like
Code:
cd() { [ "$@" = "/particular_directory" ] && echo "Gimme cluezzzz"; builtin cd "$@"; }
? Of course it'll be shell-specific and CLI only.
 
Old 11-12-2008, 02:04 PM   #3
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,994

Rep: Reputation: 76
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.

Hope that helps,

—Robert J Lee
 
Old 11-13-2008, 07:53 AM   #4
p_s_shah
Member
 
Registered: Mar 2005
Location: India
Distribution: RHEL 3/4, Solaris 8/9/10, Fedora 4/8, Redhat Linux 9
Posts: 237

Original Poster
Blog Entries: 1

Rep: Reputation: 34
Thanks for your quick replies.

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.

Provide your suggestions.

Last edited by p_s_shah; 11-13-2008 at 07:56 AM.
 
Old 11-13-2008, 01:02 PM   #5
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by p_s_shah View Post
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 View Post
`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 View Post
Only reboot can resolve the issue.
Reboot of services you mean, right?


Quote:
Originally Posted by p_s_shah View Post
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).
 
Old 11-14-2008, 06:52 AM   #6
p_s_shah
Member
 
Registered: Mar 2005
Location: India
Distribution: RHEL 3/4, Solaris 8/9/10, Fedora 4/8, Redhat Linux 9
Posts: 237

Original Poster
Blog Entries: 1

Rep: Reputation: 34
Unspawn,
Quote:
Reboot of services you mean, right?
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.
 
  


Reply



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
Script that will auto erase specified files in users directory ocavid Linux - Security 5 08-10-2007 01:07 AM
Need script for changing DIRECTORY names only to upper case PaxRomana Programming 15 05-08-2007 05:04 AM
changing directory in bash (or other) script zefram Linux - General 2 09-16-2006 10:41 AM
script for changing a specific string in a directory irfanhab Programming 5 06-28-2005 01:27 PM
Auto-Executing Shell Script on boot benrose111488 Linux - Software 5 12-18-2004 12:52 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 04:14 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
Open Source Consulting | Domain Registration