Should be simple?

Come up with a useful post-processing script? Share it here!
LakersFan
Newbie
Newbie
Posts: 18
Joined: August 12th, 2013, 11:54 pm

Should be simple?

Post by LakersFan »

Hey folks,
I have a script in unraid that works fine from a terminal, but not when used as a post-processing script in SAB.

Code: Select all

#!/bin/bash
#----------------------------------------------------------------------------
# Here you can add your own custom script eg.                                |
# rclone copy /local/path remote:path # copies /local/path to the remote     |
# rclone sync /local/path remote:path # syncs /local/path to the remote      |
#----------------------------------------------------------------------------

rclone sync /mnt/user/stern dropbox:misc
When I try to run it as a post-processing script in SAB, it fails and I get this error:
ScriptExit(-1) Cannot run script /config/scripts/db_sync.sh
Ultimately I want SAB to tell rclone (after something is done downloading), to sync with dropbox. Any help would be great.
User avatar
OneCD
Hero Member
Hero Member
Posts: 557
Joined: March 4th, 2017, 3:47 pm

Re: Should be simple?

Post by OneCD »

Is your script marked as executable? Please post the existing permissions.

When you run it at the CLI, what exactly are you typing?
Stuff I like: Apache bash cron DD-WRT Debian DNSMasq Entware FireFox GitHub ImageMagick Kate KDE LibreELEC Netrunner NFS NVIDIA OpenVPN Orvibo-S20 pfSense Python Raspberry-Pi RAID SABnzbd Transmission Usenet VirtualBox Watcher3 XFCE
LakersFan
Newbie
Newbie
Posts: 18
Joined: August 12th, 2013, 11:54 pm

Re: Should be simple?

Post by LakersFan »

Yes, I opened a terminal and typed:

Code: Select all

chmod +x /mnt/cache/apps/binhex-sabnzbdvpn/scripts/db_sync.sh
After typing it, I don’t get a response; no error or nothing saying it worked. Not sure if that is normal behavior.

In a CLI, I type “rclone sync /mnt/user/stern dropbox:misc” and it works.

Lastly, I am not sure how to obtain my existing permissions. Any guidance would be great. :)

Thank you!
User avatar
OneCD
Hero Member
Hero Member
Posts: 557
Joined: March 4th, 2017, 3:47 pm

Re: Should be simple?

Post by OneCD »

LakersFan wrote: April 9th, 2019, 10:44 pm Yes, I opened a terminal and typed:

Code: Select all

chmod +x /mnt/cache/apps/binhex-sabnzbdvpn/scripts/db_sync.sh
After typing it, I don’t get a response; no error or nothing saying it worked. Not sure if that is normal behavior.
Yes, that's the correct behaviour. Linux shells generally work on the idea that if the operation worked properly, nothing is shown. If there was a problem, you'll get an error message. It seems odd, but you get used to it. ;)
LakersFan wrote: April 9th, 2019, 10:44 pm In a CLI, I type “rclone sync /mnt/user/stern dropbox:misc” and it works.
OK, you're running the command contained within the shell-script, but you're not running the shell-script itself.

You can run your shell-script by specifying the absolute pathname to it (like you did when using chmod):

Code: Select all

/mnt/cache/apps/binhex-sabnzbdvpn/scripts/db_sync.sh
Or, if you're already in the correct directory:

Code: Select all

cd /mnt/cache/apps/binhex-sabnzbdvpn/scripts
... then run it like this:

Code: Select all

./db_sync.sh
LakersFan wrote: April 9th, 2019, 10:44 pm Lastly, I am not sure how to obtain my existing permissions. Any guidance would be great. :)
There are various ways to check this, but a simple long directory listing is sufficient:

Code: Select all

ls -l /mnt/cache/apps/binhex-sabnzbdvpn/scripts/db_sync.sh
... or, if you're already in the correct directory, use:

Code: Select all

ls -l db_sync.sh
Please post back what you see. :)
Stuff I like: Apache bash cron DD-WRT Debian DNSMasq Entware FireFox GitHub ImageMagick Kate KDE LibreELEC Netrunner NFS NVIDIA OpenVPN Orvibo-S20 pfSense Python Raspberry-Pi RAID SABnzbd Transmission Usenet VirtualBox Watcher3 XFCE
LakersFan
Newbie
Newbie
Posts: 18
Joined: August 12th, 2013, 11:54 pm

Re: Should be simple?

Post by LakersFan »

Okay, after running the shell-script, I get:

Code: Select all

root@Tower:~# /mnt/cache/apps/binhex-sabnzbdvpn/scripts/db_sync.sh
-bash: /mnt/cache/apps/binhex-sabnzbdvpn/scripts/db_sync.sh: /bin/bash^M: bad interpreter: No such file or directory
And for my permissions:

Code: Select all

root@Tower:~# ls -l /mnt/cache/apps/binhex-sabnzbdvpn/scripts/db_sync.sh
-rwxrwxrwx 1 nobody users 453 Apr  3 22:04 /mnt/cache/apps/binhex-sabnzbdvpn/scripts/db_sync.sh*
Hopefully you can make some sense of this. lol
User avatar
OneCD
Hero Member
Hero Member
Posts: 557
Joined: March 4th, 2017, 3:47 pm

Re: Should be simple?

Post by OneCD »

Permissions look good.

The error you’re seeing when attempting to run the shell-script is because it was written with a text-editor that didn't use the correct Unix line-ending character (LF). Instead, it’s using the standard DOS characters (CR+LF).

You can either:
  • edit in Windows but with a Unix compatible text editor like Notepad++,
  • you can convert your shell-script file within your Linux system with ‘dos2unix’,
  • or you can just edit that file within the Linux host system. Nano is a nice, simple text file editor that runs on Linux. :)
Stuff I like: Apache bash cron DD-WRT Debian DNSMasq Entware FireFox GitHub ImageMagick Kate KDE LibreELEC Netrunner NFS NVIDIA OpenVPN Orvibo-S20 pfSense Python Raspberry-Pi RAID SABnzbd Transmission Usenet VirtualBox Watcher3 XFCE
LakersFan
Newbie
Newbie
Posts: 18
Joined: August 12th, 2013, 11:54 pm

Re: Should be simple?

Post by LakersFan »

Okay, some progress... I did reset Notepad++ to Unix (it was on Windows by default), re-set the permissions and now I'm getting this in SAB:

Code: Select all

Exit(127) /config/scripts/dropbox_sync.sh: line 2: rclone: command not found
When running from a CLI, it appears to run as it should. No response after typing it and files seem to be synced up.
User avatar
OneCD
Hero Member
Hero Member
Posts: 557
Joined: March 4th, 2017, 3:47 pm

Re: Should be simple?

Post by OneCD »

May I suggest a change to your script?

Edit it so the first line says this:

Code: Select all

#!/usr/bin/env bash
Then try manually running your script again.
Stuff I like: Apache bash cron DD-WRT Debian DNSMasq Entware FireFox GitHub ImageMagick Kate KDE LibreELEC Netrunner NFS NVIDIA OpenVPN Orvibo-S20 pfSense Python Raspberry-Pi RAID SABnzbd Transmission Usenet VirtualBox Watcher3 XFCE
LakersFan
Newbie
Newbie
Posts: 18
Joined: August 12th, 2013, 11:54 pm

Re: Should be simple?

Post by LakersFan »

I did that and manually ran it. It ran without errors. I then tried it in SAB and got the same 127 error as before. Then I tried setting permissions again and got this??? After permissions were denied, I ran the code you gave me earlier so you can look at the permissions.

Code: Select all

root@Tower:~# chmod -x /mnt/cache/apps/binhex-sabnzbdvpn/scripts/dropbox_sync.sh
root@Tower:~# /mnt/cache/apps/binhex-sabnzbdvpn/scripts/dropbox_sync.sh
-bash: /mnt/cache/apps/binhex-sabnzbdvpn/scripts/dropbox_sync.sh: Permission denied
root@Tower:~# ls -l /mnt/cache/apps/binhex-sabnzbdvpn/scripts/dropbox_sync.sh
-rw-rw-rw- 1 nobody users 60 Apr 10 22:21 /mnt/cache/apps/binhex-sabnzbdvpn/scripts/dropbox_sync.sh
root@Tower:~#
side note -- I have to get up super early tomorrow so I'm off to bed. Thank you for the help tonight, hopefully we can pick it back up tomorrow.
User avatar
OneCD
Hero Member
Hero Member
Posts: 557
Joined: March 4th, 2017, 3:47 pm

Re: Should be simple?

Post by OneCD »

You'll need to set the execute bit again for your script. It looks like it's got a new filename. Also + enables, - disables:

Code: Select all

chmod +x  /mnt/cache/apps/binhex-sabnzbdvpn/scripts/dropbox_sync.sh
You might also investigate including the complete path to your 'rclone' binary. To find this:

Code: Select all

which rclone
Then prefix the 'rclone' command in your script with the path shown.

BTW: you're nearly there. ;D
Stuff I like: Apache bash cron DD-WRT Debian DNSMasq Entware FireFox GitHub ImageMagick Kate KDE LibreELEC Netrunner NFS NVIDIA OpenVPN Orvibo-S20 pfSense Python Raspberry-Pi RAID SABnzbd Transmission Usenet VirtualBox Watcher3 XFCE
LakersFan
Newbie
Newbie
Posts: 18
Joined: August 12th, 2013, 11:54 pm

Re: Should be simple?

Post by LakersFan »

I do feel close!
Thanks for the tip on the permissions. I got that worked out with the +x instead of -x.

I did the "which rclone" command and it came up with /usr/sbin/rclone

So I changed my script to this... (not sure if that's what you meant my prefixing the path):

Code: Select all

#!/usr/bin/env bash
/usr/sbin/rclone sync /mnt/user/stern dropbox:misc
I am still getting the error in SAB:

Code: Select all

ScriptExit(127) /config/scripts/dropbox_sync.sh: line 2: /usr/sbin/rclone: No such file or directory
User avatar
OneCD
Hero Member
Hero Member
Posts: 557
Joined: March 4th, 2017, 3:47 pm

Re: Should be simple?

Post by OneCD »

Re: prefixing the path - that's exactly right. ;D

OK, let's do some detective work. Please modify your shell-script so it looks like this (copy and paste it into your editor):

Code: Select all

#!/usr/bin/env bash
#/usr/sbin/rclone sync /mnt/user/stern dropbox:misc
{
	echo "date: $(date)"
	echo "PATH: $PATH"
	echo "EUID: $EUID"
	echo "which: $(which rclone)"
	echo "check direntry: $(ls -l /usr/sbin/nologin 2>&1)"
	echo "rclone direntry: $(ls -l /usr/sbin/rclone 2>&1)"
	echo
} >> /tmp/db-sync.log
Then run your script manually.

Afterward, check the logged output with:

Code: Select all

cat /tmp/db-sync.log
Then, get SABnzbd to run it as a post-processing script, and check the log file contents again (the new logged values will be appended to the original log).

Are the recorded values the same for the manual run as for the SABnzbd post-processing run?
Stuff I like: Apache bash cron DD-WRT Debian DNSMasq Entware FireFox GitHub ImageMagick Kate KDE LibreELEC Netrunner NFS NVIDIA OpenVPN Orvibo-S20 pfSense Python Raspberry-Pi RAID SABnzbd Transmission Usenet VirtualBox Watcher3 XFCE
LakersFan
Newbie
Newbie
Posts: 18
Joined: August 12th, 2013, 11:54 pm

Re: Should be simple?

Post by LakersFan »

Yes, they are the same.

Code: Select all

Linux 4.18.20-unRAID.
Last login: Thu Apr 11 21:46:41 -0700 2019 on /dev/pts/5.
root@Tower:~# /mnt/cache/apps/binhex-sabnzbdvpn/scripts/dropbox_sync.sh
root@Tower:~# cat /tmp/db-sync.log
date: Fri Apr 12 22:07:40 PDT 2019
PATH: .:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin
EUID: 0
which: /usr/sbin/rclone
check direntry: ls: cannot access '/usr/sbin/nologin': No such file or directory
rclone direntry: -rwxr-xr-x 1 root root 495 Apr  7 15:04 /usr/sbin/rclone

root@Tower:~# cat /tmp/db-sync.log
date: Fri Apr 12 22:07:40 PDT 2019
PATH: .:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin
EUID: 0
which: /usr/sbin/rclone
check direntry: ls: cannot access '/usr/sbin/nologin': No such file or directory
rclone direntry: -rwxr-xr-x 1 root root 495 Apr  7 15:04 /usr/sbin/rclone

root@Tower:~#
User avatar
OneCD
Hero Member
Hero Member
Posts: 557
Joined: March 4th, 2017, 3:47 pm

Re: Should be simple?

Post by OneCD »

OK, it seems the SAB post-processor hasn't run your script. There should be a second series of entries in that log file starting with a different datetime.

Can you please confirm you ran the script as a post-processor within SABnzbd?
Stuff I like: Apache bash cron DD-WRT Debian DNSMasq Entware FireFox GitHub ImageMagick Kate KDE LibreELEC Netrunner NFS NVIDIA OpenVPN Orvibo-S20 pfSense Python Raspberry-Pi RAID SABnzbd Transmission Usenet VirtualBox Watcher3 XFCE
LakersFan
Newbie
Newbie
Posts: 18
Joined: August 12th, 2013, 11:54 pm

Re: Should be simple?

Post by LakersFan »

Here's a screenshot showing it was ran:
Image
Post Reply