Moving user home folders?

wstewart3
New Contributor III

I am working on making a script to move from a local account to a mobile account. However of all the things I am failing on something ridiculous... what’s am I missing?

(Script ran with sudo sh accounts.sh)

oldLocation="/Users/testuser/" newLocation="/Users/$domainUser/" mv $oldLocation $newLocation

And the script outputs this error:

mv: rename /Users/testuser/ to /Users/jsmith3/: Operation not permitted

Ok... So I type directly into the terminal:
sudo mv /Users/testuser/ /Users/jsmith3/
Works fine... The heck am I missing?

2 REPLIES 2

mm2270
Legendary Contributor III

I assume the snippet you posted is not the full script, because I don't see the variable $domainUser defined anywhere. Given this, where is that being set in the script and how? Is it possible it's not getting populated correctly? Usually with things like this, it's a good idea to echo back the variables that get set using commands so you can see in the policy output what the script was seeing, since those things aren't hardcoded, presumably. Maybe it will reveal an issue.

wstewart3
New Contributor III

So turns out, the sysadminctl -deleteUser command takes a few seconds to remove the folder of the user and the system wouldn't let the folder go.

But the time I got out of the shell it was working fine. Simply added a while loop to wait for the folder to no longer exist.

Sorry for the dumb question!