Register
It is currently Fri Jul 25, 2014 3:02 am

Script for Mac using sheel script Bash


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Mon Apr 14, 2014 9:03 am   

Joined: Mon Apr 14, 2014 8:15 am
Posts: 1
Hello,

I have a problem figuring out how to create a script that when I will add it in Automator on Mac it will execute and do what I want.

I want the script to check if a file exist on the USB drive. If it does than copy what is there from usb onto the computer and check again if the file is there every 5 minutes lets say. If the file is not there anymore than execute another command , delete some files from my computer.
What am I trying to accomplish ? Because I haven't figured a way to run an auto script when the usb is ejected/removed I am trying to find a way around to make the script check a file on the usb stick, and if the file is not there ( usb unplugged) then it will execute the other command. This is on MAC, on Linux I would have to edit udev and would be easy but here I have no clue .

What I have done so far: This I done just for some testing and it works.
testfile="/Volumes/Sith/abc.txt"
if [ -e "$testfile" ]
then
mkdir /Users/text/text
else
rm -R /Users/text/text
fi

I am missing the part where I tell the script to start checking every 5 minutes and if the file is not there anymore then it should execute the else.

If there is any other way to accomplish what I want than please tell me


Top
 Profile  
 PostPosted: Tue Apr 15, 2014 3:36 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 532
hi,

you need an infinite while loop:
Code:
file="/mnt/usb/file"
while sleep $((5*60))
do
   test -f '$file' && echo "$file is there" || echo "$file is not there"
done


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: Google [Bot] and 8 guests


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