LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-23-2009, 01:45 AM   #1
packets
Member
 
Registered: Oct 2005
Posts: 339

Rep: Reputation: 32
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

Quote:
#!/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

Quote:
find: foo: No such file or directory
Any advise?
 
Old 11-23-2009, 02:31 AM   #2
deepinlife
Member
 
Registered: Apr 2006
Posts: 78

Rep: Reputation: 15
Code:
#!/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
 
Old 11-23-2009, 02:33 AM   #3
packets
Member
 
Registered: Oct 2005
Posts: 339

Original Poster
Rep: Reputation: 32
Quote:
Originally Posted by deepinlife View Post
Code:
#!/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
Thanks. I forgot to change USERS to users ... what a noob
 
Old 11-23-2009, 02:37 AM   #4
packets
Member
 
Registered: Oct 2005
Posts: 339

Original Poster
Rep: Reputation: 32
Is there a way I can modify this script to find the file from the month it was created? Example I want to find all files that was created last January 2009 and tar it. I think there will be no problem on tar. Problem could be in how to find files based on the month it was created.

Can find command has this option to do so? Any other command I can use?
 
Old 11-23-2009, 11:12 AM   #5
deepinlife
Member
 
Registered: Apr 2006
Posts: 78

Rep: Reputation: 15
well i m not quite sure , u need to do more search , but i think indoe structure don't contain creation time for a file , so simply there is nothing called creation time in linux.

although there is something confusing( for me ) in the inode called i think change indoe time , which sometimes confused with creation of the file , but it is not the creation time .

u have to change the logic of ur script , and not depend on teh creation date of files
 
Old 11-23-2009, 11:29 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,348

Rep: Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749
Unix does NOT store creation times, just atime (access), mtime (modify), ctime (inode info changed). Go with mtime generally..

http://linux.die.net/man/2/stat
 
Old 11-24-2009, 12:21 AM   #7
deepinlife
Member
 
Registered: Apr 2006
Posts: 78

Rep: Reputation: 15
Quote:
Originally Posted by chrism01 View Post
Unix does NOT store creation times, just atime (access), mtime (modify), ctime (inode info changed). Go with mtime generally..

http://linux.die.net/man/2/stat
so we consider st_ctime the time of the creation of the inode(file) unless the stat of the file changed , chmod , hard links ,owner or group change
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Using squid to apply download limit on users on LAN doode31 Linux - Server 2 01-12-2009 06:35 AM
bash script to apply sed command only to a specific text area mauran Programming 6 07-13-2007 04:38 PM
How to use bash shell to create many users Linx2003 Linux - Software 1 09-04-2003 11:14 PM
How to use bash shell to create many users Linx2003 Programming 7 09-02-2003 01:00 PM
How to use bash shell to create many users Linx2003 Linux - General 1 09-02-2003 08:18 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration