Need bash script to move software from /Applications to /Users/admin/Applications

I need a BASH script to check to see if iTunes.app exists in /Applications and if it does, to then move it to /Users/admin/Applications , and to overwrite iTunes if it already exists in /Users/admin/Applications

The reason is we want to keep iTunes up to date, but SUS always reinstalls the new version to /Applications, so it would be nice to have a script to run after updating and to overwrite the older version in the target directory.

Thanks!
LVL 1
stconairAsked:
Who is Participating?
 
TintinCommented:
Probably a better way is to simply create a link, so that whenever the /Applications/iTunes.app is updated, then you'll instantly have the latest version.

To create a link, do

rm /Users/admin/Applications/iTunes.app
ln -s /Applications/iTunes.app /Users/admin/Applications/iTunes.app
0
 
TintinCommented:

#!/bin/bash
[ -f /Applications/iTunes.app ] && mv /Applications/iTunes.app /Users/admin/Applications

Open in new window

0
 
stconairAuthor Commented:
Doesn't seem to work, what does the -f do in the beginning?  iTunes remains in /Applications after I chmod the script to 755 and run it.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
stconairAuthor Commented:
OK I see [ -f ] checks to see if the file exists, but something isn't working, it doesn't report an error, just no result.
0
 
TintinCommented:
Are you 100% sure /Applications/iTunes.app exists?

Run the script with

bash -x scriptname

and post the output.
0
 
stconairAuthor Commented:
+ '[' -f /Applications/iTunes.app ']'
Here is the output of your script, Tintin.
0
 
omarfaridCommented:
When you want to move file from one dir to another, you need to be root or owner of directories or have priv on those directories.

Are really interested in moving or in copying the file?
0
 
stconairAuthor Commented:
I want to move the file because the whole point is I dont want it in /Applications which is where it gets reinstalled every time SUS updates iTunes.  I want it in /Users/admin/Applications it will have to overwrite the previous version that is in /Users/admin/Applications and will be moved out of /Applications , that is all I want to accomplish, to have the most up to date version in /Users/admin/Applications
0
 
stconairAuthor Commented:
And Yes, I have admin/sudo rights
0
 
omarfaridCommented:
ok, what are the permissions on the existing file

/Users/admin/Applications/iTunes.app

try

mv  -f  /Applications/iTunes.app  /Users/admin/Applications
0
 
omarfaridCommented:
can you post error message if any?
0
 
ahoffmannCommented:
#!/bin/bash
dest=/User/admin/Applications/iTunes.app
[ -f "$dest" ] && rm -rf "$dest"
 mv  -f  /Applications/iTunes.app  "$dest" || error move failed

# script must run as root (sudo or whatever)
0
 
stconairAuthor Commented:
Tintin, wouldnt that result in the /Users/admin/Applications/iTunes.app  not getting updated when SUS tries to write to iTunes default location of /Applications when each new update is released?
0
 
TintinCommented:
It means that whenever /Applications/iTunes.app is updated, /Users/admin/Applications/iTunes.app is instantly updated as it is linked to /Applications/iTunes.app
0
 
stconairAuthor Commented:
I see.. The one concern is that we don't really want users accessing iTunes, and if it is in /Applications, they will be able to.I guess I could set permissions so that only admin can access it I guess I can set it to admin:wheel with 770 since our users dont know admins password and none of them are in the wheel group.  Does that make sense to you?
0
 
TintinCommented:
Doesn't really make much sense to me.

Whether you move the file from /Applications to /Users or use a link, the result is going to be the same, except that using a link is much easier.

Changing perms will work if your intention is to restrict who has access to itunes updates.
0
 
stconairAuthor Commented:
That's what I mean, we dont want our non admin users to be able to launch iTunes, so I was going to restrict the users by making admin the owner of iTunes and setting others to 0.  Thanks for your help, i will give you the solution accepted.
0
 
ahoffmannCommented:
> .. by making admin the owner of iTunes and setting others to 0
keep in mind that you now should no longer use Apple's "sophisticated" repair permissions in the disk utility
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.