Posted on 04-30-2012 05:43 AM
I found this backup script in the forums and am using it to backup the office 2011 Database file. The script is not working. It seems as if the Casper Programming Argument of $3 is not passing through the user name. Any ideas would help.
#!/bin/bash
afp_server=""
afp_volume="backups"
AFP_Monitor_User=""
AFP_Monitor_PSWD="*"
if ! [ -d "/Volumes/$afp_volume" ] ; then
# Assume they do not have this volume mounted
mkdir "/Volumes/$afp_volume" ;
mount_afp "afp://$AFP_Monitor_User:$AFP_Monitor_PSWD@$afp_server/$afp_volume" "/Volumes/$afp_volume"
else
# They have a volume of the same name mounted [on some server]
# I would test for proper file rights here
touch "/Volumes/$afp_volume/Backups"
if [ -e "/Volumes/$afp_volume/Backups" ] ; then
true
# User can write here
else
false
# User can't write here
fi
fi
# create the users folder we are going to move. Casper uses $3 for the logged in user when running scripts.
# set a variable so we don't have to retype it a lot.
UsersCustomPath="/Volumes/$afp_volume/Backups/$3"
# use -p to create any needed sub directories
mkdir -p "$UsersCustomPath"
# Now let's do the copy.
# man says use -p to preserve the following attributes of each source file
# in the copy: modification time, access time, file flags, file mode,
# user ID, and group ID, as allowed by permissions. Access Control
# Lists (ACLs) and Extended Attributes (EAs), including resource
# forks, will also be preserved.
#
# There is more but you probably won't run into it... consult 'man cp' if you want to know more.
#
# we also likely want sub directories: use -R
#
# if you want to follow symbolic links add -L
# if you want each copy to show in the log use verbose mode: -v
cp -pRv "/Users/$3/Documents/Microsoft User Data/Office 2011 Identities/Main Identity/Database" "UsersCustomPath"
Error I get:
Script Result: cp: /Users//Documents/Microsoft User Data/Office 2011 Identities/Main Identity/Database: No such file or directory
Posted on 04-30-2012 06:01 AM
Is the script being run as a login or logout task?
Posted on 04-30-2012 06:09 AM
I tried running it from remote while I was logged in on my own machine, otherwise I would run it as a login script.
Posted on 04-30-2012 06:25 AM
The only instances where $3 will work is if you run it as a login or logout. The jamf binary grabs the user at this point and assigns it to $3. If you're running the script at some other trigger (e.g. Any or Every15) you need to obtain the logged in user with some other method. I do this:
user=`ls -la /dev/console | cut -d " " -f 4`
and then call $user instead of $3
Posted on 04-30-2012 06:47 AM
It'll also take the username of the user that logged into self service if the script is run from there.
https://jamfnation.jamfsoftware.com/article.html?id=146
Posted on 04-30-2012 07:10 AM
That worked, Thanks guys. I also had to modify my path as well as add a $ in "UsersCustomPath"