[Plugin] CA User Scripts


Recommended Posts

3 minutes ago, jowi said:

Yeah ok but why then use the user script module anyway at all, and not just run my python script (like i did before....) as a cron job or daemon.... 

IMHO CA User Script is just a GUI for simplifying the process of setting up cronjobs. If you know what you are doing, you absolutely could just setup the cronjobs yourself.

Link to comment

In my case - when i use a python script that needs the home directory - the program is not raising an exception but does not find the config file in the home directory and therefore not initialized properly.

 

Some more detail about home directory is not set correctly issue.

If i install a script in the plugin that relies on the home directory than if it is executed from the crontab, then it works.

So the "run script" and "run in background" buttons are malfunctioning in such cases.

Link to comment
4 minutes ago, l4t3b0 said:

In my case - when i use a python script that needs the home directory - the program is not raising an exception but does not find the config file in the home directory and therefore not initialized properly.

 

Some more detail about home directory is not set correctly issue.

If i install a script in the plugin that relies on the home directory than if it is executed from the crontab, then it works.

So the "run script" and "run in background" buttons are malfunctioning in such cases.

Did you try running the script in a login shell like I suggested above?

Link to comment

Dear @Squid

 

I dont know too much about php, but i tried to debug your plugin.

I have figured out, that the startScript.sh file already has the symtom that the HOME directory is not set.

 

But with a 2 line modification i could fix the problem.

 

I kindly ask you to examine my modification and if you agree, than please add it to your plugin, so others will have the fix too.

 

Quote

#!/bin/bash
echo "Script location: <b>$1</b>"
export HOME=$(grep $(whoami) /etc/passwd | cut -d: -f 6)
source ${HOME}/.bashrc
echo "<font color='red'>Note that closing this window will abort the execution of this script</font>"
"$1" "$2" 2>&1

With this modification my python plugin works too :)

 

Actually i need only the export command and not the source. I thought that it could be useful for others in the future to try to initialize the environment as much close to the login shell as possible.

 

What is your opinion?

Link to comment

I have been using User Scripts with no problem for a long time. I tried to modify the timings of my some of my tasks, and APPLY and DONE does nothing. The button is clicked, but no action is taken and refreshing the page leads to old settings. Not working in chrome, IE or Firefox.

 

How can i save my updated changes.

 

NOTE: I also have one user script with an @ in the title and the cog is completely unclickable, not sure if this is related. If i could remove that too would be great.

 

image.thumb.png.a6c6e0d014efd9cd62323f99cd71b5ef.png

bigrig-diagnostics-20200815-1326.zip

Edited by mihcox
Link to comment
27 minutes ago, mihcox said:

How can i manually remove this, as the gui does not respond when i click on it.

I tried it by myself. You can bypass this error by right mouse click -> inspect element and then remove the "@" symbol of the "id" attribut as shown in this screenshot (so it becomes id="nametest")

 

1300506083_2020-08-1522_45_32.png.2ec9815b0a4a523f938e0f79d74ddd7d.png

 

After that the cog works and you are able to delete this script (and add a new one without the @ symbol in the name).

Link to comment
6 minutes ago, mgutt said:

I tried it by myself. You can bypass this error by right mouse click -> inspect element and then remove the "@" symbol of the "id" attribut as shown in this screenshot (so it becomes id="nametest")

 

1300506083_2020-08-1522_45_32.png.2ec9815b0a4a523f938e0f79d74ddd7d.png

 

After that the cog works and you are able to delete this script (and add a new one without the @ symbol in the name).

Resolved both issues, thank you!

Link to comment
  • 2 weeks later...
  • 4 weeks later...
On 8/23/2020 at 9:55 PM, Marcel_Costa said:

Hi Squid,

 

Great plugin !

I have more than 25 scripts runing daily thanks to you.

Could be possible to implement something like "Docker Folder" ? It would be much easier to organize large amounts of scripts.

That would be awesome !

 

Thanks !

 

 

wow, this is what i was coming here for too! my scripts are starting to stack up, would love to be able to organize them in a folder type structure. i.e. array scripts, backup scripts, VM scripts, etc. Goes without saying, Squid, great plugin for sure.

  • Like 1
Link to comment

Thanks for the plugin! I have a question about permissions. I am in the process of migrating my Plex/NAS server from a Mac. On my Mac I have a script that syncs new files every 5 minutes from a remote seedbox. I have altered this script for UnRAID to download to my "Downloads" share. It appears to work fine as far as the syncing goes, but the files on the share are read-only and I can't do anything about that. What should I do to make it so I can have read/write permissions from my other devices when I access the share? Thanks!

 

Here's the script:

#!/bin/bash
#### Seedbox Sync
#
# Sync various directories between home and seedbox, do some other things also.

SCRIPT_NAME="$(basename "$0")"
LOG_DIR="/mnt/user/Downloads/Seedbox/Scripts/Logs"
SYNC_LOG="$SCRIPT_NAME.log"

LOG_FILE="$LOG_DIR/$SYNC_LOG"

USERNAME='***'
PASS='***'
HOST='***'
PORT='***'

# Number of files to download simultaneouslyvupv
# Number of segments/parts to split the downloads into
# Minimum size each chunk (part) should be

nfile='2'
nsegment='10'
minchunk='1'

# Location of remote files ready for pickup, no trailing slash
REMOTE_MEDIA="***/downloads/Sync/"
# Destination for remote media to be stored for further processing
LOCAL_MEDIA="/mnt/user/Downloads/Seedbox/Sync"
# Local processing directory files get moved to after sync
PROC_MEDIA="/mnt/user/Downloads/Seedbox/Processing"

# Test for local lockfile, exit if it exists
BASE_NAME="$(basename "$0")"
LOCK_FILE="/mnt/user/Downloads/Seedbox/Scripts/$BASE_NAME.lock"

# Test for remote lockfile, exit if exists
REMOTE_LOCK_FILE="***/scripts/post_process.sh.lock"

# Fix permissions issue
umask 002

# If a log file exists, rename it
if [ -f $LOG_FILE ]; then
    mv $LOG_FILE $LOG_FILE.last
fi

echo "${0} Starting at $(date)"
trap "rm -f ${LOCK_FILE}" SIGINT SIGTERM
    if [ -e "${LOCK_FILE}" ]
    then
        echo "${base_name} is running already."
        exit
    else
		ssh $USERNAME@$HOST "test -e $REMOTE_LOCK_FILE"
		if [ "$?" -eq "0" ]; then
			echo "Post Process is running on remote server, exiting..."
			exit
		fi
        touch "$LOCK_FILE"
        lftp -p "${PORT}" -u "${USERNAME},${PASS}" sftp://"${HOST}" << EOF
        set ftp:list-options -a
        set sftp:auto-confirm yes
        set pget:min-chunk-size ${minchunk}
        set pget:default-n ${nsegment}
        set mirror:use-pget-n ${nsegment}
        set mirror:parallel-transfer-count ${nfile}
        set mirror:parallel-directories yes
        set xfer:use-temp-file yes
        set xfer:temp-file-name *.lftp
        mirror -c -v --loop --Remove-source-dirs "${REMOTE_MEDIA}" "${LOCAL_MEDIA}"
        quit
EOF
    echo "${0} Remote sync finished at $(date)"

	# Move sync'd files to processing directory
	rsync -av --progress --ignore-existing --remove-source-files --prune-empty-dirs -O \
	--log-file=$LOG_FILE \
	--log-file-format="%f - %n" \
	${LOCAL_MEDIA}/ \
	${PROC_MEDIA}/

	# Clear Sync directory of empty folders and .DS_Store files
	find $LOCAL_MEDIA -name '.DS_Store' -type f -delete
	find $LOCAL_MEDIA -depth -type d -empty -exec rmdir "{}" \;
	mkdir -p $LOCAL_MEDIA
	rm -f "$LOCK_FILE"
	trap - SIGINT SIGTERM
	exit
fi

 

Link to comment
On 3/28/2020 at 10:37 PM, Derek_ said:
  • When i run Borg with a user.script - it performs its operations as root (as expected) and the dir/file ownership is root:root
  • When i run and rsync copy with a user.script - it performs its operations as root (as expected) and the file ownership is with nobody:users.

 

@Derek_ did you ever figure this out? I am having the same issue. When I run lftp, any folders/files it creates are root:root and i need it to be nobody:users. Thanks!

Edited by cmarshall85
Link to comment
1 hour ago, Alex.b said:

/mnt/user/disk2/Nextcloud_backup

Are you sure this is the actual path? That is a user share named disk2. I recommend not having a user share named the same as a disk. It will only lead to confusion.

 

If this is indeed the correct path, maybe it was not what you had in mind. What did you have in mind?

Link to comment

Found a weird little bug that made for some interesting troubleshooting.

 

I created a script with an exclamation point at the start.  User scripts did not like this.  Started throwing errors in the console.  wouldn't allow me to delete so I removed from console.

 

Lesson learnt, don't start scripts with a ! 

Link to comment

I have a problem where whenever an rsync script is ran via user scripts,

Quote

rsync -avu --chown=nobody:users --chmod=Du=rwx,Dgo=rwx,Fu=rw,Fog=rw --delete --stats --exclude=/cache/ -e "ssh -i /root/.ssh/NAS-rsync-key -T -o Compression=no -x" "[email protected]:/var/www/html" "/mnt/user/Backup/test" >> /home/nasbackuplogs/logs/$(date +"%Y%m%d")-test-backup.log

When i test running this in the CLI it works fine, it sets both directories and files that are being backed up to the correct permissions for unraid, but whenever the same command runs via user scripts it for whatever reason sets the directory permissions to drwxrwx--- instead of drwxrwxrwx+, please advise?

Link to comment
1 hour ago, je82 said:

I have a problem where whenever an rsync script is ran via user scripts,

When i test running this in the CLI it works fine, it sets both directories and files that are being backed up to the correct permissions for unraid, but whenever the same command runs via user scripts it for whatever reason sets the directory permissions to drwxrwx--- instead of drwxrwxrwx+, please advise?

Try adding the following to the beginning of your command so it runs in a login shell:

sudo -i -u root 

 

Link to comment

Hi

 

Love this plugin, have one issue, where only the first entry get the three icons (Log file, Download Log, and Delete Log)

Ive inspected the dom, and the icons are there for the other lines, but display:none is applied

 

Does any one know why, or is this a bug?

 

Thanks

 

Added to CA:March 30, 2018

Date Updated:August 21, 2020

Current Version:2020.08.22

 

 

Link to comment
4 minutes ago, Matt_UK said:

Hi

 

Love this plugin, have one issue, where only the first entry get the three icons (Log file, Download Log, and Delete Log)

Ive inspected the dom, and the icons are there for the other lines, but display:none is applied

 

Does any one know why, or is this a bug?

 

Thanks

 

Added to CA:March 30, 2018

Date Updated:August 21, 2020

Current Version:2020.08.22

 

 

Until the script actually HAS a log file, the buttons are hidden. Or are you saying the scripts seem to be running on schedule, but still no buttons?

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.