Register
It is currently Tue Dec 06, 2016 3:50 pm

sync content only when content


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Tue Jul 19, 2016 4:18 am   

Joined: Tue Jul 19, 2016 4:13 am
Posts: 1
Hello!
I'm fairly new to the script scene, but done quite a bit of progress.
I've been trying to create the following script:

# mount drive
# check if files in source directory
# if no files exist in source directory, do nothing
# if files in source directory, check if destination directory exists
# if destination directory exists, don't create destination directory
# if destination directory doesn't, create destination directory
# if files exist and destination directory exists, copy files from source directory
# once all files from source directory have been copied to d-directory, delete files in s-directory

what I cam up with so far:
###############if no dir create dir and if files copy files
file="/Desktop/A/"
directory_name="inbound"

if ((test -s "$file") & (-d $directory_name))
then
echo "Directory already existing"

else
mkdir $directory_name


#copy files

find A/ -name "*.mp3" -type f -print0 | xargs -0 -I '{}' /usr/bin/rsync -av "{}" inbound/
echo "*********copying files"

fi


#ask to delete files in transfer folder


=====
but I am lost in this, as I have to connect several if statements.


Top
 Profile  
 PostPosted: Wed Jul 20, 2016 3:01 pm   

Joined: Mon Oct 20, 2014 9:53 am
Posts: 508
Please use code tags, if posting code.
This is unreadable.

There is no such test command like ( )
Either use [ ] which is often is just a link to the test command
or use [[ ]] .
Double brackets is the syntax for the internal Bash construct.
Read about it with help "[["
Read about the posix compatible test commands with man test or man "[".

And finally there is no need to test whether a directory exist.
Just use mkdir -p /some/deeply/nested/directory This will create the entire path for you and does not complain on already existing parts or the complete path.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP