Skip to content
View in the app

A better way to browse. Learn more.

Unraid

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[Plugin] CA User Scripts

Featured Replies

I'm trying to run a script with the following custom cron schedule:

 

50 2 * * 2 [[ $(date +%e) -le 7 ]]

 

I wanted the script to run the 1st week of every month on Tuesday at 2:50am but it didn't run this past Tuesday.  I just copied the cron schedule for my parity check and made some modifications.  Do you see anything wrong with this cron schedule?

 

  • Replies 2.1k
  • Views 567.1k
  • Created
  • Last Reply

Top Posters In This Topic

Most Popular Posts

  • I could make up something long, convoluted, and technical as a reason why it doesn't do that but it would all be bs.  The simple answer is that when I did this, I never thought of that, and why it sti

  • Hi All - We have a fix and are publishing a Connect plugin update to fix it today. Thanks for letting us know.

  • @Squid I tried many commands and by that I found out that pkill does not kill (all) child processes: root@Thoth:/tmp# pgrep -f isleep2m | xargs --no-run-if-empty ps fp PID TTY STAT T

Posted Images

28 minutes ago, niwmik said:

I'm trying to run a script with the following custom cron schedule:

 

50 2 * * 2 [[ $(date +%e) -le 7 ]]

 

I wanted the script to run the 1st week of every month on Tuesday at 2:50am but it didn't run this past Tuesday.  I just copied the cron schedule for my parity check and made some modifications.  Do you see anything wrong with this cron schedule?

 

I have a cron I run in Ubuntu that is for the first Saturday of every month. My syntax is:

 

0 0 * * 6 [ $(date +\%d) -le 07 ] && /script/path/follows/here.sh

21 hours ago, cybrnook said:

I have a cron I run in Ubuntu that is for the first Saturday of every month. My syntax is:

 

0 0 * * 6 [ $(date +\%d) -le 07 ] && /script/path/follows/here.sh

 

Thanks for the tip.  I changed the cron schedule to "50 2 * * 4 [ $(date +%d) -le 07 ]" and it appears to have run this morning based on what it is in the logs.

 

Nov  4 02:50:01 Atlas crond[2264]: exit status 2 from user root [ $(date +\%d) -le 07 ] /usr/local/emhttp/plugins/user.scripts/startCustom.php /boot/config/plugins/user.scripts/scripts/AutoBackupVM/script > /dev/null 2>&1
 

However, AutoBackupVM script doesn't appeared to have ran.  I just ran it manually to test and it ran successfully.  Is there something else I'm missing?

 

What is AutoBackupVM? I use my own script to backup VM's. Seems the script is exiting with status 2, so something is not happy.

 

When you run it by hand, after it completes what does "echo $?" return

Edited by cybrnook

i'm running the clear_array_drive script. The status window shows 2.2 MB/s. At this rate it's going to take about 21 days to complete.

Will it speed up? It's a part of the shrink array process but is it really necessary?

2 minutes ago, wgstarks said:

i'm running the clear_array_drive script. The status window shows 2.2 MB/s. At this rate it's going to take about 21 days to complete.

Will it speed up? It's a part of the shrink array process but is it really necessary?

Speed sounds about right, the script is not optimized at all.

 

You can either write all zeroes to the data drive, or rebuild parity, either way works, but rebuilding parity is much quicker.

4 minutes ago, JonathanM said:

Speed sounds about right, the script is not optimized at all.

 

You can either write all zeroes to the data drive, or rebuild parity, either way works, but rebuilding parity is much quicker.

That's what I thought. Drive has already been emptied, so now I can just stop the array, remove the drive, create new config and rebuild parity. Did I miss anything?  

Edited by wgstarks
typo

1 minute ago, wgstarks said:

That's what I thought. Drive has already been emptied, so now I can just stop the array, remove the drive, create new config and rebuild parity. Did I miss anything?  

Sounds good!

Will closing the terminal window stop the script?

 

20 hours ago, cybrnook said:

What is AutoBackupVM? I use my own script to backup VM's. Seems the script is exiting with status 2, so something is not happy.

 

When you run it by hand, after it completes what does "echo $?" return

 

AutoBackupVM is a script written by an Unraid user that I use to backup my Windows 10 VM.  I've never had an issue with it before.

 

I clicked "RUN SCRIPT" in User Scripts to manually run the script so I didn't have access to a terminal screen.

 

As a test, I changed the cron schedule from "Custom" to "Scheduled Monthly" and changed Monthly schedule in Scheduler to run on the 5th.

 

I didn't see anything in the logs this morning but AutoBackupVM did run successfully.  As far as I can tell, the script only fails when I set it to a custom cron schedule.

 

 

 

  • 2 weeks later...

Does anyone know the GitHub repo for this plugin?  I'd like to look though the source code.

 

Thanks,

Harry

4 hours ago, HarryMuscle said:

Does anyone know the GitHub repo for this plugin?  I'd like to look though the source code.

 

Thanks,

Harry

If you have the plugin installed then you can always look at the .txz file in the plugins folder on the flash drive without bothering to go to GitHub.

  • Author
On 11/4/2021 at 9:47 AM, niwmik said:

50 2 * * 4 [ $(date +%d) -le 07 ]

You're going to want to add a cron job via crontab or by placing an application .cron file within /config/dynamix on the flash drive.  User scripts will eventually disallow a cron entry like this  (when I get to it)

I don't know if this belongs here:

Had serious trouble with rsync commands running wild. Started something like "rsync -avh --delete \\A \\b - huge job, almost 10 TB. I canceled it via userscript-plugin but it did not work. In the end i had about 10 rsync scripts copying the same stuff over and over (because the first ones altered the date/time and the later scripts did not notice). Annoying...

Is there a way to include this (i needed "killall rsync" to clean up this mess) or should i provide something with the script to avoid this behaviour.

I love this - I have so many scripts for automation of everything.  I just added a new one to rsync the radarr and sonarr backups out of appdata to external backup disks.

What would make this perfect is if I could move the scripts around ?  

I just noticed my cron based scripts last ran on 19th Nov.  The dropdown daily, weekly, hourly ones are running fine.

I have some scripts for this however :

 

*/5 * * * *   - very 5 minutes sync video camera data to hidden laptop

30 23 * * * - Backups every night at 23:30

 

Any idea where I can go to rectify this ?  In there a cron process that has stopped or something ?

On 10/27/2021 at 4:51 PM, Noim said:

@Squid 

My issue still persists. Here is a test script:

61713642_Screenshot2021-10-27at16_44_25.thumb.png.4047f199b5c9e7ae2deb2263f4e98974.png

 

After aborting it, the script process is still running:

 

1366726180_Screenshot2021-10-27at16_45_20.png.5644734dc475c1f64e11ea83d4d7d675.png

 

What am I doing wrong?!

 

This is how it gets spawned if I press background process:

550709164_Screenshot2021-10-27at16_48_27.png.0be54c7f5dc6a3931b9911edca04c345.png

The process 10197 survives if I press abort.

 

Plugin is up-to-date and running on unraid 6.9.2. 

 

Because nobody cared, and the dev doesn't even publish the plugin on GitHub, so I could make a pull request I investigated by myself.

The abort how it is implemented is flawed.

 

This is my fix. Not elegant, but it works better than the current version.

Starting at line 115 in exec.php:

  case 'abortScript':
    $script = isset($_POST['name']) ? urldecode(($_POST['name'])) : "";
    
    $pid = file_get_contents("/tmp/user.scripts/running/$script");
    exec("pkill -TERM -P $pid");
    exec("kill -9 $pid");
    $processListOutput = null;
    exec("ps aux | grep -i '/tmp/user.scripts/tmpScripts/$script' | grep -v grep", $processListOutput);
    foreach ($processListOutput as $emergencyKill) {
      $emergencyKill = str_replace("root","",$emergencyKill);
      $emergencyKill = trim($emergencyKill);
      $rawKill = explode(" ",$emergencyKill);
      logger("Kill pid: ".$rawKill[0]);
      exec("kill -9 ".$rawKill[0]);
    }
    @unlink("/tmp/user.scripts/running/$script");
    file_put_contents("/tmp/user.scripts/finished/$script","aborted");
    file_put_contents("/tmp/user.scripts/tmpScripts/$script/log.txt","Execution was aborted by user\n\n",FILE_APPEND);
    break;

 

The original version didn't kill all running script instances. And the grep command not even found the correct processes if I tried it manual. 

43 minutes ago, Squid said:

Oh, I am sorry. There was no response to @HarryMuscle question and a quick google search wasn't helpful either. So, I just expected there is no repo. I will do a proper pull request.

  • 4 weeks later...

I created a script to run in the background, but today the log shows Full logs for this script are available at /tmp/user.scripts/tmpScripts/bypy_mmd/log.txt.Then the script failed to run after retrying several times automatically, and I had to restart the server to run normally.How to solve my trouble?

Is there a possiblity of a GUI update to be able to organize the scripts within some type of folder structure to help keep them organized?

  • 2 weeks later...

Is there a way to skip the Userscript from triggering if the previous run is still running? Currently it seems like the userscript will trigger a new run at the scheduled time even if the previous one is not complete.

2 hours ago, bobokun said:

Is there a way to skip the Userscript from triggering if the previous run is still running? Currently it seems like the userscript will trigger a new run at the scheduled time even if the previous one is not complete.

I believe that the script itself would be responsible for ensuring that only a single instance can run at a time. Adding one of the solutions from this page https://unix.stackexchange.com/questions/48505/how-to-make-sure-only-one-instance-of-a-bash-script-runs would probably do the trick.

I have a problem with the plugin. I updated the user scripts plugin and afterwards it disappeared from my unraid menu and if I try to open it via the plugins > installed plugins tab and click on it, I get a black screen. Reinstall did not fix the problem.
I am on Unraid Version: 6.10.0-rc1
Any ideas?

Hi i dont know the first thing about scripts but am able to follow instructions well. I am looking for a script that will start my pfsense VM when the array is brought up manually, i found something like "virsh start pfsense" which does not seem to work unless i run it manually after the array has started. can anyone assist me with this ?

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...

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.