Platform: AIX
Shell: KSH
Does anyone have a good way of warning users that when they do a 'vi' in a certain directory that they cannot save any changes in that directory.
For instance, if I have a production id that has all scripts in /myprod/dir, and if anyone comes to this directory and does a 'vi' to edit/view any files there, a message will remind them that they cannot make updates (unless they are logged on as the production id that owns all these files so no warning is shown)?
I don't want to just warn everytime they cd to the prod directory b/c it can be annoying...but if this is the only option then how would you approach it. Some ideas would be nice.
Cheers!
Gianni
You could write a script that would act as a wrapper to vi. Then move the vi binary to some other name such as vi.org. Link the /usr/bin/vi to your script - say /usr/local/bin/vi.wrapper.
Here's a sample vi.wrapper script. It is very simplistic and has no checks for directory permissions. It assumes that all directory permissions will be 775 and works on that.
#!/bin/sh
filetoedit=$1
user=`ls -ld |awk '{print $3}'`
group=`ls -ld |awk '{print $4}'`
curruser=`whoami`
currgrps=`groups $curruser`
echo $user | grep $curruser > /dev/null 2> /dev/null
if [ $? -ne 0 ]
then
echo $currgrps | grep $group
if [ $? -ne 0 ]
then
echo you dont have perms to edit files in this directory
fi
fi
vi.org $filetoedit