LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-08-2016, 06:53 AM   #1
robertkwild
Member
 
Registered: Feb 2015
Posts: 382

Rep: Reputation: Disabled
script help needed to automate tar/rsync/rm


hi all,

at work i have a real boring job sometimes of when a new project folder is ready to be archived i have to do the following

tar the project folder

rsync the .tar file to a remote directory

remove the tar file

remove the project folder

i would like to make this all automatic

i want to automate the whole process but i want to make a watch folder on linux, so when the watch folder has got a project folder in it, it does all the above so

is this possible

cheers,

rob
 
Old 04-08-2016, 07:02 AM   #2
ilesterg
Member
 
Registered: Jul 2012
Location: München
Distribution: Debian, CentOS/RHEL
Posts: 587

Rep: Reputation: 72
Yes, it is possible. What have you done so far?
 
Old 04-08-2016, 10:45 AM   #3
robertkwild
Member
 
Registered: Feb 2015
Posts: 382

Original Poster
Rep: Reputation: Disabled
i havnt started yet, atm im manually doing it
 
Old 04-08-2016, 01:13 PM   #4
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by robertkwild View Post
i havnt started yet, atm im manually doing it
Which part is causing you to pause?
Quote:
Originally Posted by robertkwild View Post
tar the project folder
rsync the .tar file to a remote directory
remove the tar file
remove the project folder
#!/bin/bash
tar stuff
rsync stuff
rm file
rm directory
 
1 members found this post helpful.
Old 04-08-2016, 06:12 PM   #5
robertkwild
Member
 
Registered: Feb 2015
Posts: 382

Original Poster
Rep: Reputation: Disabled
lets say i have loads of projects in the "to_be_archived" folder like

superman/

batman/

spiderman/

hulk/

iron_man/

etc, etc...

but my script looks like this

#!/bin/bash

cd /to_be_archived/

tar -cf superman.tar superman/

rsync -avh superman.tar /archived_projects/

rm -f superman.tar

rm -rf superman/

now superman is done i want it to do the next folder down then so forth and so on

for this do i need to add a variable

and after they rsync the project of i want to double check if it has actually rsynced before deleting it as if i delete it and it hasnt worked, im in the bad books

Last edited by robertkwild; 04-08-2016 at 06:13 PM.
 
Old 04-13-2016, 10:54 AM   #6
robertkwild
Member
 
Registered: Feb 2015
Posts: 382

Original Poster
Rep: Reputation: Disabled
getting there

#!/bin/bash
cd /to_be_archived/
for DIR in * ; do
fSaveDir="${DIR##*/}"
tar -cf "${fSaveDir}".tar "${fSaveDir}"
rsync -a "${fSaveDir}".tar /archived_projects/
rm -f "${fSaveDir}".tar
rm -rf "${fSaveDir}"
done
 
Old 04-13-2016, 11:12 AM   #7
ilesterg
Member
 
Registered: Jul 2012
Location: München
Distribution: Debian, CentOS/RHEL
Posts: 587

Rep: Reputation: 72
Not familiar with rsync, but maybe it has a return code to let you know if it was successful before deleting the file.

Also, you may want to wrap your code with CODE tag for readability.
 
Old 04-13-2016, 11:18 AM   #8
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,800

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
rsync has a remove source option.
 
Old 04-13-2016, 12:41 PM   #9
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
rsync dry-run is
Code:
-n
Try using
Code:
rsync -an "${fSaveDir}".tar /archived_projects/
 
Old 04-15-2016, 11:29 AM   #10
robertkwild
Member
 
Registered: Feb 2015
Posts: 382

Original Poster
Rep: Reputation: Disabled
job done -

#!/bin/bash
cd /to_be_archived/
for DIR in * ; do
fSaveDir="${DIR##*/}"
tar -cf "${fSaveDir}".tar "${fSaveDir}"
rsync -a "${fSaveDir}".tar /archived_projects/
if [ $? -ne 0 ]
then
mail -s "${fSaveDir}" robertw@molinare.co.uk <<< "project "${fSaveDir}" aborted due to error"
else
rm -f "${fSaveDir}".tar
rm -rf "${fSaveDir}"
fi
done
 
Old 04-15-2016, 11:45 AM   #11
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,800

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
great!
If you think your problem is solved please mark the thread solved.
Also if you wish to say thanks to someone just click on yes.
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to automate archiving of log files using tar? profi81 Linux - Newbie 2 03-29-2011 06:39 PM
LXer: Speaking Unix, Part 6: Automate, automate, automate! LXer Syndicated Linux News 0 01-04-2007 09:54 AM
cannot automate rsync backup jahjr Linux - Server 6 12-21-2006 04:54 AM
using rsync and tar disorderly Linux - Software 4 11-19-2005 06:40 PM
Help needed to Automate the wi-fi roaming nevarlen Linux - Networking 1 08-05-2005 12:25 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:51 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