Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I made a script to copy an image to a temporary directory, convert it to an another format, then move it to a final directory. But i can't get the chmod command to work, the file is copied to the temporary directory but it's chmod is stuck on -rw------- (the original chmod of the file).

If i apply a 777 chmod on the original file, the copied one get a -rwx------ instead of a -rwxrwxrwx

The copied and orignal files have the same user.

TS=$(date +"%Y")/$(date +"%m")/$(date +"%d")/$(date +"%Hh%Ms%S")
PATHTMP="/tmp/faxtiff"

mkdir -p $PATHTMP
chmod 777 $PATHTMP
cp $FILE $PATHTMP
chmod 777 $PATHTMP/$FILE
convert $PATHTMP/$FILE -scale '50%x100%!' $PATHTMP/fax.jpg
chmod 777 $PATHTMP/fax.jpg
mkdir -p /home/argent/faxes-recus/$TS
chmod 777 /home/argent/faxes-recus/$TS
#rm $PATHTMP/$FILE
mv $PATHTMP/*.jpg /home/argent/faxes-recus/$TS
share|improve this question

2 Answers 2

up vote 1 down vote accepted

mdpc is correct. I don't know why somebody downvoted your question, but...

If root owns the file, you should be able (assuming you have access of course) to do a sudo chmod..., and that should work.

If, however, you don't want root to own the file anymore, you'll need to do a sudo chown $USER <filename> to cause the file to be owned by the user you are logged in as.

I haven't tried your script, but go ahead and try the following, noting 2 things:

1) Don't go around chowning things that you shouldn't. I don't know the context of this question, and it may be bad, very bad, or extremely extremely bad to chown the files in question (read: abuse of power). However, if you are creating this content and are implicitly (or explicitly) being given permission to mod these files, then it shouldn't be a problem.

2) I commented out a couple chowns that you shouldn't need. Remember, you can always do a ls -l to see the ownership of a given file.

TS=$(date +"%Y")/$(date +"%m")/$(date +"%d")/$(date +"%Hh%Ms%S")
PATHTMP="/tmp/faxtiff"

mkdir -p $PATHTMP
#sudo chown -R $USER $PATHTMP 
chmod 777 $PATHTMP
cp $FILE $PATHTMP
sudo chown $PATHTMP/$FILE
chmod 777 $PATHTMP/$FILE
convert $PATHTMP/$FILE -scale '50%x100%!' $PATHTMP/fax.jpg
#shouldn't need to chown here if the script is being run as the logged in user.
chmod 777 $PATHTMP/fax.jpg
mkdir -p /home/argent/faxes-recus/$TS
#chown $USER /home/argent/faxes-recus/$TS
chmod 777 /home/argent/faxes-recus/$TS
#rm $PATHTMP/$FILE
mv $PATHTMP/*.jpg /home/argent/faxes-recus/$TS
share|improve this answer
    
Thank you, i applied your methods and i made my script work as i wanted to. –  DoesNotCompute Jan 9 '13 at 14:27

If you are NOT the owner of the file in question, you cannot do a chmod operation on the file.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.