Find the answer to your Linux question:
Results 1 to 4 of 4
I created a bash script that will tar all files inside a user's directory after 30 days but it seems not working. All my users has a directory named documents ...
  1. #1
    Linux Newbie
    Join Date
    Mar 2006
    Posts
    101

    how to apply to all users using bash

    I created a bash script that will tar all files inside a user's directory after 30 days but it seems not working. All my users has a directory named documents and inside that was a file. I want to backup all files inside their home directory and named it according to their usernam. If there is a user foo, the tar file should be foo.tar.gz

    #!/bin/bash

    USERS=`cat /etc/passwd | awk '{print $1}' | awk -F: '{print $1}'`

    for users in $USERS;do
    find /home/$USERS/back_up/new -type f -mtime +30 | xargs tar rvf /backup/emails/$USERS.tar
    done

    I encountered this error

    find: foo: No such file or directory
    Any advise?

  2. #2
    Linux Engineer RobinVossen's Avatar
    Join Date
    Aug 2007
    Location
    The Netherlands
    Posts
    1,422
    Why do you use your /etc/password file for this??
    As there might be (and will be) users in there that don't have a homefolder.
    My advice is to just ls -l the /home folder

    Hope that fixes it a bit.
    New Users, please read this..
    Google first, then ask..

  3. #3
    Just Joined!
    Join Date
    Aug 2005
    Posts
    65
    should we consider that linuxquestion is faster in replaying or what do u think packets ?

  4. #4
    Linux Newbie
    Join Date
    Mar 2006
    Posts
    101
    Quote Originally Posted by deepinlife View Post
    should we consider that linuxquestion is faster in replaying or what do u think packets ?
    Was it against the rules posting from another forum with the same content? If yes please let me know.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...