Thread: copying file from one user directory to another

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    113

    copying file from one user directory to another

    Hi,

    I am writing a shell script for copying file from one user account directory to another.
    The code is:
    Code:
    #!/bin/sh
    src_path=/home/bargi
    tgt_path=/home/abc
    cp ${src_path}/a* ${tgt_path}/
    bargi and abc are user's.
    When I run the script it gives me error of permission denied.
    I know that since I am logging with bargi account, I can't copy file to abc account directory.

    I have following question:
    1: Is there a way so that abc allow copying other's user to its account? (may be forcefully applying some techniques to abc account with root access )
    2: How can I implement it in shell script ?

    Can any body help me regarding this ?

    Thanks
    Bargi

  2. #2
    Making mistakes
    Join Date
    Dec 2008
    Posts
    476
    You can't have two permissions at once. Use sudo (or maybe su root) instead. Or ask abc to give bargi permission to write in his home directory and execute that script as bargi (or vice versa)

  3. #3
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    You may also want to chown the resulting file to the destination uid and gid.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  4. #4
    Registered User
    Join Date
    Jan 2007
    Posts
    113
    How can I make abc to give permission to bargi for write permission?

  5. #5
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by Bargi View Post
    How can I make abc to give permission to bargi for write permission?
    Read the chmod man page. If this is not super sensitive stuff, just set the permission the same for everyone, eg, "700" means I can do everything and no one else can even look. "777" means anyone can do whatever they want. It's a bitmask (read=4, write=2, execute=1, so "6" is read+write).

    I'm pretty sure that a sub directory might be subject to the constraints of it's parent, you will have to experiment. I always play root so I don't care, but that is a bad attitude to have
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  6. #6
    Making mistakes
    Join Date
    Dec 2008
    Posts
    476
    The best way is propably to give abc read permission for the files. Abc can then copy them into his/her home directory.

  7. #7
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    The best approach is to ask root to create a group containing all the users which are allowed to share files with each other. The UNIX group system leaves much to be desires, but isn't totally useless...
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  3. Lost in C
    By David670 in forum C Programming
    Replies: 8
    Last Post: 10-31-2005, 11:19 PM
  4. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM