# Shell script that copies to OneDrive

**URL:** <https://the.fmsoup.org/t/shell-script-that-copies-to-onedrive/2603>\
**Category:** Questions\
**Tags:** filemaker-server\
**Created:** [November 26, 2021, 3:52pm UTC](https://the.fmsoup.org/t/shell-script-that-copies-to-onedrive/2603 "2021-11-26T15:52:38Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![LucThomaere](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/lucthomaere/32/3108_2.png) [@LucThomaere](https://the.fmsoup.org/u/LucThomaere)\
**Post date:** [November 26, 2021, 3:52pm UTC](https://the.fmsoup.org/t/shell-script-that-copies-to-onedrive/2603/1 "2021-11-26T15:52:38Z")

</div>

I'm trying to create a shell script on mac os that does copy a certain folder from the Filemaker backup-directory to a directory in OneDrive and run it on certain moments from within Filemaker Server  
The script does work from within Filemaker Server when the destination is NOT OneDrive but a directory somewhere on the same Mac  
The script does work when I run it form the Terminal, even to the OneDrive directory.  
But it does not work from Filemaker Server to the OneDrive directory.

The OneDrive directory has permissions 770.  
 ![image](https://canada1.discourse-cdn.com/flex030/uploads/fmsoup/original/2X/c/cc9db33f916fd0eff541536ed6cd6225eb73bd7d.png)

The Script is the simplicity itself: just 1 line, a cp-command but as it works from with the Terminal the cause is not the script.

What do I forget? Or is it impossible to save a backup file to a remote location?

---

<div class="post-metadata">

**Author:** ![OliverBarrett](https://avatars.discourse-cdn.com/v4/letter/o/f19dbf/32.png) [@OliverBarrett](https://the.fmsoup.org/u/OliverBarrett)\
**Post date:** [November 26, 2021, 4:36pm UTC](https://the.fmsoup.org/t/shell-script-that-copies-to-onedrive/2603/2 "2021-11-26T16:36:59Z")

</div>

Perhaps the utility "ExpanDrive" could help you? ExpanDrive maps drives or volumes (mac/pc) so you can access them like any other drive making file operations much simpler in many cases.

---

<div class="post-metadata">

**Author:** ![Malcolm](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/malcolm/32/196_2.png) [@Malcolm](https://the.fmsoup.org/u/Malcolm)\
**Post date:** [November 26, 2021, 6:33pm UTC](https://the.fmsoup.org/t/shell-script-that-copies-to-onedrive/2603/3 "2021-11-26T18:33:01Z")

</div>

Sounds like permission settings. Can you run it with sudo?

---

<div class="post-metadata">

**Author:** ![AndyHibbs](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/andyhibbs/32/3089_2.png) [@AndyHibbs](https://the.fmsoup.org/u/AndyHibbs)\
**Post date:** [November 26, 2021, 9:49pm UTC](https://the.fmsoup.org/t/shell-script-that-copies-to-onedrive/2603/4 "2021-11-26T21:49:11Z")

</div>

Not an answer to your exact question, but we’ve been using the AWS CLI to copy local files to AWS S3 Storage for a few years from Windows and Macs using a system script run by FileMaker Server. It’s run flawlessly and there are great tools like Transmit (Macs) and S3 Browser (Windows) to access the files.

The key thing about these type of scripts is first, do they run successfully when executed directly in Terminal on the Mac, or when double clicked in Windows, which you’ve confirmed you script does.

Therefore, look at the ‘Run as’ options in the FileMaker Server script, which has always been the problem (and solution) when we’ve had the same issue as it appears you have.

Regards  
Andy

---

<div class="post-metadata">

**Author:** ![AndyHibbs](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/andyhibbs/32/3089_2.png) [@AndyHibbs](https://the.fmsoup.org/u/AndyHibbs)\
**Post date:** [November 26, 2021, 10:05pm UTC](https://the.fmsoup.org/t/shell-script-that-copies-to-onedrive/2603/5 "2021-11-26T22:05:53Z")

</div>

It’s late here, but just checked my setup notes before heading to bed, these may be of help:

If the shell script works:  
To check it is executable via the default fmserver account, run:  
sudo -u fmserver ./filename.sh and enter the Mac admin password when prompted

If all runs OK, then this can be run from a FileMaker Server schedule

Create a FileMaker Schedule for a System script  
Point to the new script  
Leave the default account to run  
Run the script and check the Macintosh HD/Library/FileMaker Server/Logs/Event.Log in Console - check the script runs successfully before continuing

If there is a problem running the script, add the following to the /etc/sudoers file:  
In Terminal run:  
hostname  
copy and paste the result for use below  
run:  
sudo visudo and enter the Mac admin password when prompted  
Use the arrow keys to navigate down until the line after:  
# User privilege specification  
root ALL=(ALL) ALL  
%admin ALL=(ALL) ALL  
In the line below the above:  
press the 'A' key to insert text  
Enter:  
Host\_Alias FMSHOST = hostname  
replace 'hostname' with the result from entering 'hostname' at the beginning above  
Create a new line (in the normal way) and enter:  
Defaults:fmserver targetpw, timestamp\_timeout=0, passwd\_tries=1  
Create another new line and enter:  
fmserver FMSHOST = (ALL) /Library/FileMaker\ Server/Data/Scripts/\*, /bin/kill  
Press the 'ESC' escape key to finish editing the file  
Press the colon key and type wq (:wq) then the Enter/Return key to save the changes and to exit visudo (vi)  
vi is used rather than other Terminal based text editors as it confirms proper syntax prior to saving the file.

---

<div class="post-metadata">

**Author:** ![EdwinS](https://avatars.discourse-cdn.com/v4/letter/e/57b2e6/32.png) [@EdwinS](https://the.fmsoup.org/u/EdwinS)\
**Post date:** [November 27, 2021, 3:47am UTC](https://the.fmsoup.org/t/shell-script-that-copies-to-onedrive/2603/6 "2021-11-27T03:47:44Z")

</div>

Maybe an issue similar to the one happening with cron?

> <https://apple.stackexchange.com/questions/378553/crontab-operation-not-permitted>

"In your case you have to add cron as "parent" app to the user's Security & Privacy \> Privacy \> Full Disk Access apps/execs."

---

<div class="post-metadata">

**Author:** ![xochi](https://avatars.discourse-cdn.com/v4/letter/x/0ea827/32.png) [@xochi](https://the.fmsoup.org/u/xochi)\
**Post date:** [November 27, 2021, 3:00pm UTC](https://the.fmsoup.org/t/shell-script-that-copies-to-onedrive/2603/7 "2021-11-27T15:00:34Z")

</div>

Inside the FileMaker server folder, you can find console.log and error.log files that will show you standard error and standard out for any shell scripts run from within FMS.

You should be able to see errors there, or you can add logging to your script file with echo commands etc.

Edit: correction, the files are located in **/Library/FileMaker Server/Logs** and are named **stdout** and **stderr** and although they don't have filename extensions, they are text files and you can manually open them in the Console.app

![image](https://canada1.discourse-cdn.com/flex030/uploads/fmsoup/original/2X/2/21d202ef716b3219d222ed016966a687e7344b50.png)

---

<div class="post-metadata">

**Author:** ![LucThomaere](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/lucthomaere/32/3108_2.png) [@LucThomaere](https://the.fmsoup.org/u/LucThomaere)\
**Post date:** [November 30, 2021, 10:56am UTC](https://the.fmsoup.org/t/shell-script-that-copies-to-onedrive/2603/8 "2021-11-30T10:56:28Z")

</div>

Thanks for all your comments but nothing works. What worked with Dropbox seems impossible with OneDrive. I guess the people at Microsoft make it impossible.  
I've spend enough time with this, I will find another solution.

---

<div class="post-metadata">

**Author:** ![OliverBarrett](https://avatars.discourse-cdn.com/v4/letter/o/f19dbf/32.png) [@OliverBarrett](https://the.fmsoup.org/u/OliverBarrett)\
**Post date:** [November 30, 2021, 1:15pm UTC](https://the.fmsoup.org/t/shell-script-that-copies-to-onedrive/2603/9 "2021-11-30T13:15:37Z")

</div>

**Three options below.**

**1.** If you try the idea I suggested, namely, **ExpanDrive** , you can create a local drive "mapping" of your OneDrive folder (personal or business type). At that point, you can do a regular copy using whatever shell method or other you want.

Here are the connections supported by **ExpanDrive**.

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/fmsoup/original/2X/c/c163617c3c237561b5e2e732a114ebb7293c4944.png)

--

**2.** You could also use the MS **API** :

**[Copy a file or folder - OneDrive API - OneDrive dev center | Microsoft Docs](https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_copy?view=odsp-graph-online)**

--

**3.** You could also use **Zapier** which has built-in connectors to OneDrive and the free FileMaker connector for FMS. Zapier is incredible!

**[OneDrive Integrations | Connect Your Apps with Zapier](https://zapier.com/apps/onedrive/integrations)**

I'm sure one of (it not all of) these options will work.

---

<div class="post-metadata">

**Author:** ![samfmp](https://avatars.discourse-cdn.com/v4/letter/s/a9a28c/32.png) [@samfmp](https://the.fmsoup.org/u/samfmp)\
**Post date:** [November 30, 2021, 3:52pm UTC](https://the.fmsoup.org/t/shell-script-that-copies-to-onedrive/2603/10 "2021-11-30T15:52:42Z")

</div>

Hi, For option 2, you could also check the demo file from Soliant Consulting.

> **[Microsoft Graph API for Office 365 Integrations in FileMaker](https://www.soliantconsulting.com/blog/microsoft-graph-api-filemaker-one/)**
>
> Learn more about changes to Microsoft’s Graph API for Office 365 in FileMaker, specifically the demise of basic authentication.
