|
|
|
|
#1 |
|
Prospect
Join Date: Mar 2008
Location: University of Pittsburgh
Posts: 10
|
Cron fails to mount network share?
Hello!
I am attempting to automate a daily process by which certain folders will be backed up from a Mac running OS X (most machines are Leopard now, but we have some running Tiger as well.) The destination is a WIndows 2003 Server, with a share titled "mailbox". Since I work in a research facility on campus, everyone is a local admin to their box, WIndows or Mac, I should mention. Here is one of the scripts I came up with - when executed manually, this script works perfectly. This six-line one copies the Eudora folder out of the user's Documents folder. I would customize the script with their actual username, password and the IP address of the destination server. This was attempted on a 1.8GHz PowerPC G5, 1.5GB DDR, running OS X 10.5.2. ~~~~~~~~~~~~~~~~~~~~~~~~~~~ #!/bin/sh echo "Results of Eudora (Mac) Backup:" mkdir /Volumes/mailbox mount_smbfs //userbob assword@xxx.xxx.xxx.xxx/mailbox /Volumes/mailboxditto -V /Users/userbob/Documents/"Eudora Folder" "/Volumes/mailbox/userbob/mac/eudora" umount /Volumes/mailbox ~~~~~~~~~~~~~~~~~~~~~~~~~~~ When I execute this script manually, it creates a "mailbox" folder in the Volumes, mounts the Mailbox share from the remote server, and copies the entire contents of the Eudora Folder. Then at the end it unmounts the share. This is important because we want this to be as transparent to the user as possible, we don't even want them to see or realize it's done, nor do we want them to see the share. The problem happens when I tried to use Cron to automate this. I chose to run it from the system crontab. The script file, as you can see, holds the username and password in plain text, and as such I stored the script file in the /private/var/root/bin folder, so that the user cannot access it or see it themselves (nor can anyone who has access to their desktop). Once I put the script in that folder, I test executed it manually as root, and again it worked fine. Then I went into /etc/crontab and added the following line to the system crontab there (the tabs are taken out for spacing): 48 14 27 3 4 root sh /private/var/root/bin/eudorabackuptest.sh >> /Users/userbob/Documents/mailbackup.txt 2>&1 So that it would run today, Thursday 3/27, at 2:48PM. It executed the script in question, and wrote the output results to a file on the user's Documents folder for me to check later. So I did this twice, once logged in as the user, once as Root. Both times, I got the following output in the results file: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Results of Eudora (Mac) Backup: /private/var/root/bin/eudorabackuptest.sh: line 4: mount_smbfs: command not found >>> Copying /Users/userbob/Documents/Eudora Folder (Here it listed the copied files. The mkdir command had gone off ok, creating the actual folder /Volumes/mailbox. Apparently cron could not execute the script's mount command, and so the files were copied into the created "/Volumes/mailbox" local folder. /private/var/root/bin/eudorabackuptest.sh: line 6: umount: command not found ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ So it worked except for the mount and hence umount commands. I do not understand why it failed when cron ran the script..because the same script works just fine when I run it manually. And I did it logged in as root to test that. Why, exactly, would cron fail to recognize the mount_smbfs command like this? Your suggestions and ideas would be most welcome - I can't proceed past this point. |
|
|
|
|
|
#2 |
|
Site Admin
Join Date: Jan 2002
Location: Montreal
Posts: 31,940
|
You always should use full paths for all files and executables referred to in a script.
This goes double for cron scripts since cron sets up different environment than a regular shell. So find out where the 'mount_smbfs' command is (via 'which mount_smbfs') and use that full path. Similarly for other commands used.
__________________
hayne.net/macosx.html |
|
|
|
|
|
#3 |
|
Prospect
Join Date: Mar 2008
Location: University of Pittsburgh
Posts: 10
|
Bingo! That was the problem. Once I changed the script line to read:
/sbin/mount_smbfs //userbobassword@xxx.xxx.xxx.xxx/mailbox /Volumes/mailbox then Cron executed the script flawless. Thanks very much! |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|