On Thu, Feb 02, 2006 at 03:28:49PM -0800, James G. Sack (jim) wrote:
>George Georgalis wrote:
>>..
>>>>..script needs to generate files with the same umask
>>>>of $USER which is different from the system umask, and can change
>>>>from user to user.
>>>>Situation, when that is run as tested (login shell), all is fine.
>>>>a umask of 007 is applied to files created. But when it's deposited
>>>>in the $PATH directory and run as "doit.sh" it uses the system umask.
>
>
>>..just a utility to change dos <-> unix text files
>>and accepts $1, so 
>>
>>  doit.sh file.txt
>>
>>replaces that file
>
>
>ok, _beginning_ to understand the question a little better, but I still 
>don't see how to reproduce the problem -- maybe there's still something 
>missing?
>
>
>Whether you run ./doit.sh via (#!/usr/bin/sh), or sh doit.sh or even sh 
>-c ./doit.sh, that's an non-interactive shell in all cases, I believe. 
>Even if there were, on FC4, there should still be no difference in umask 
>(see following discussion).

on this particular host (debian), "users" is the default group. the default
umask (somewhere in etc) is 022 but per user rc files a umask of
002 is set (not sure if .bash_profile or .bashrc); this is so
they can all change files on a community directory with mode 775,
without issuing a chmod.

when I tested the program (sh doit.sh file.txt) it used "sed ...
$1 >$1-tmp && mv $1-tmp $1" and the user's umask was applied. when
moved to a path directory the default umask, not the user's set
umask applied to the created files -- in fact that's why I wrote
it, dos2unix changed the mode.

So, I changed it to do "sed ... $1 >$1-tmp && cat $1-tmp >$1 && rm
$1-tmp" which just retains the original mode which is good enough.

>I note that in FC4, my /etc/bashrc contains
>-------------------------------------------------------
># by default, we want this to get set.
># Even for non-interactive, non-login shells.
>if [ $UID -gt 99 ] && [ "`id -gn`" = "`id -un`" ]; then
>        umask 002
>else
>        umask 022
>fi
>
># are we an interactive shell?
>if [ "$PS1" ]; then
><snip.. nothing affecting umask>
>--------------------------------------------------------
>
>Now, again on my unmodified FC4, /etc/bashrc gets invoked from my ~/.bashrc
>
>
>
>Hmmm, maybe your /etc/bashrc or ~/.bashrc is different?


the key is setting a umask before running from $PATH ...why isn't
it applied?


>Here's another test script you may find useful
>--------------------------------------------------------
>#!/bin/sh
>UMASK=`umask`
>echo "$0 entry: ps1='$PS1' user=='$USER' shlvl='$SHLVL' umask='$UMASK' 
>args='$*'"
>#in case of wrap, 'echo' above is one line
>
>[ 0 -eq $UID ] && exec su - jsack -c "$0 $*"
>echo "==="
>--------------------------------------------------------

when I edited my file in place I threw a umask in the script and verified 
it was not the umask set immediately before the command, which I found odd.

// George 


-- 
George Georgalis, systems architect, administrator <IXOYE><
http://galis.org/ cell:646-331-2027 mailto:[EMAIL PROTECTED]


-- 
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-list

Reply via email to