Posted on 10-04-2017 01:25 PM
Hello I am looking to rename a folder via a script. I am trying to use
mv ~/Google Drive ~/OldGoogleDrive
This worked on my computer, but when I tried it on another it gave me the following error.
Executing Policy Rename Google Drive Folder
Running script Rename Google Drive Folder...
Script exit code: 1
Script result: mv: rename /var/root/Google Drive to /var/root/OldGoogleDrive: No such file or directory<br/>
Error running script: return code was 1.
For some reason on this computer it is looking for the folder in the var/root location, even though on my computer it did not look there. Any help is greatly appreciated.
Solved! Go to Solution.
Posted on 10-04-2017 01:30 PM
~
doesn't work in scripts run from Jamf Pro, because that typically evaluates to /var/root/
just as the error message indicated. The ~
is used as a placeholder for, "path to the home folder of whoever is running the script". When you run the script it correctly looks in your home folder, but when Jamf Pro runs it, it goes to the root account, since that's who's actually running the script.
Anyway, use a variable placeholder for the logged in user, if there is one.
#!/bin/sh
loggedInUser=$(stat -f%Su /dev/console)
mv /Users/$loggedInUser/Google Drive /Users/$loggedInUser/OldGoogleDrive
Posted on 10-04-2017 01:26 PM
Here is the file path of the folder I am renaming.
/Users/davidharborth/Google Drive
Posted on 10-04-2017 01:30 PM
~
doesn't work in scripts run from Jamf Pro, because that typically evaluates to /var/root/
just as the error message indicated. The ~
is used as a placeholder for, "path to the home folder of whoever is running the script". When you run the script it correctly looks in your home folder, but when Jamf Pro runs it, it goes to the root account, since that's who's actually running the script.
Anyway, use a variable placeholder for the logged in user, if there is one.
#!/bin/sh
loggedInUser=$(stat -f%Su /dev/console)
mv /Users/$loggedInUser/Google Drive /Users/$loggedInUser/OldGoogleDrive