Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2008-10-29
18
Medium Priority
?
199 Views
Last Modified: 2013-12-26
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!
0
Comment
Question by:stconair
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
  • 3
  • +1
18 Comments
 
LVL 48

Expert Comment

by:Tintin
ID: 22835334

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

Open in new window

0
 
LVL 1

Author Comment

by:stconair
ID: 22835434
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
 
LVL 1

Author Comment

by:stconair
ID: 22835528
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
PowerShell Core for Advanced Linux Administrators

Understand advanced principals around Powershell Core with a focus on the Linux Administrator.  This course covers how to administer numerous environments across multiple platforms including Linux, Azure, AWS, and Google Cloud from a single shell instance.

 
LVL 48

Expert Comment

by:Tintin
ID: 22837007
Are you 100% sure /Applications/iTunes.app exists?

Run the script with

bash -x scriptname

and post the output.
0
 
LVL 1

Author Comment

by:stconair
ID: 22840475
+ '[' -f /Applications/iTunes.app ']'
Here is the output of your script, Tintin.
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 22840870
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
 
LVL 1

Author Comment

by:stconair
ID: 22841003
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
 
LVL 1

Author Comment

by:stconair
ID: 22841011
And Yes, I have admin/sudo rights
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 22841120
ok, what are the permissions on the existing file

/Users/admin/Applications/iTunes.app

try

mv  -f  /Applications/iTunes.app  /Users/admin/Applications
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 22841138
can you post error message if any?
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 22844361
#!/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
 
LVL 48

Accepted Solution

by:
Tintin earned 1500 total points
ID: 22845027
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
 
LVL 1

Author Comment

by:stconair
ID: 22845375
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
 
LVL 48

Expert Comment

by:Tintin
ID: 22845418
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
 
LVL 1

Author Comment

by:stconair
ID: 22845789
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
 
LVL 48

Expert Comment

by:Tintin
ID: 22845859
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
 
LVL 1

Author Comment

by:stconair
ID: 22849739
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 22850019
> .. 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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question