4

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 

2 Answers 2

2

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 
1
  • Thank you, i applied your methods and i made my script work as i wanted to. Commented Jan 9, 2013 at 14:27
0

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

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.