Linux - GeneralThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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.
#!/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
#!/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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.