FlamongOle Posted March 9 Share Posted March 9 On 2/27/2024 at 1:25 AM, FlamongOle said: root@Odin:~# /usr/local/emhttp/plugins/user.scripts/startSchedule.php hourly bash: /usr/local/emhttp/plugins/user.scripts/startSchedule.php: Permission denied root@Odin:~# php /usr/local/emhttp/plugins/user.scripts/startSchedule.php hourly /usr/local/emhttp/plugins/user.scripts/backgroundScript.sh "/tmp/user.scripts/tmpScripts/dynu_updater_hourly/script" >/dev/null 2>&1/usr/local/emhttp/plugins/user.scripts/backgroundScript.sh "/tmp/user.scripts/tmpScripts/pfsense_firewall/script" >/dev/null 2>&1 Noticed that I got a permission error in the logs from the User Scripts plugin, it looks like Unraid does not accept the #!/usr/bin/php anymore. I had to add "php" in front of the startSchedule.php in the crontab file to make it work. Can someone test this, I wanna know if it's just my system or a bug/glitch.. Looks like it resolved after a reboot, dunno why or what happened there. Quote Link to comment
sjtuross Posted March 12 Share Posted March 12 Is it possible to have docker daemon start complete trigger? My script depends on some docker network interfaces which only become available after docker daemon starts. Quote Link to comment
GeeMan Posted March 17 Share Posted March 17 Hi, First post.... I have tried to use crontab inside a VM but it does not seem to run a script I have, run's manually fine. I have seen mention of using User Scripts to run commands in docker....e.g docker exec "etc", is there a way to run a script inside a VM on a schedule. I need wake up an SMB share in Proxmox Backup Server VM from a TrueNAS VM on the same Unraid server. I have the fstab built and it remembers it but needs a manual "mount -a" after a reboot to restore the share. Many Thanks Quote Link to comment
alturismo Posted March 18 Share Posted March 18 5 hours ago, GeeMan said: is there a way to run a script inside a VM on a schedule. nope, virsh doesnt support this Alternativ, you could run a script which does ssh into your VM and run the command ... either keypair or install sshpass on unraid (unsafe !!!) but rather you should look into your VM why the cron aint running there ... assuming you already did so 1 Quote Link to comment
nraygun Posted March 22 Share Posted March 22 Is there a way to make the length of the log that's displayed in the dashboard longer? I know I can go to /tmp/user.scripts/tmpScripts/scriptname/log.txt, but I'd rather check it with the little log icon right in the dashboard. Another 26 lines should do it. Quote Link to comment
Dukobpa3 Posted April 1 Share Posted April 1 Hi all. Can I join to running script session somehow? Quote Link to comment
Tucubanito07 Posted April 2 Share Posted April 2 Does anyone know if is possible to stop a running backup for a container? I accidentally thought that the check mark was to select what you wanted backup but I see it says disable. Quote Link to comment
orlando500 Posted April 10 Share Posted April 10 Hi, what user is this plugin running as? when i run a script in console and i have placed the config files in /root/.config its running ok. but when i call the script in plugin it makes a new config file at //.config/ somewhere. Quote Link to comment
nraygun Posted April 11 Share Posted April 11 On 3/22/2024 at 12:28 PM, nraygun said: Is there a way to make the length of the log that's displayed in the dashboard longer? I know I can go to /tmp/user.scripts/tmpScripts/scriptname/log.txt, but I'd rather check it with the little log icon right in the dashboard. Another 26 lines should do it. Any ideas anyone? Quote Link to comment
Kilrah Posted April 11 Share Posted April 11 (edited) 2 hours ago, nraygun said: Any ideas anyone? AFAIK it uses unraid's standard "popup window" and that's fixed size/doesn't support scrolling. Edited April 11 by Kilrah 1 Quote Link to comment
nraygun Posted April 11 Share Posted April 11 2 hours ago, Kilrah said: AFAIK it uses unraid's standard "popup window" and that's fixed size/doesn't support scrolling. OK, thanks for the response! Quote Link to comment
Amane Posted April 12 Share Posted April 12 (edited) On 4/1/2024 at 9:31 AM, Dukobpa3 said: Can I join to running script session somehow? Use tmux 😉 #!/bin/bash # Start with TMUX SESSION_NAME="$(basename "$(dirname $0)" | sed 's/ //g')" export TERM=xterm-256color if [ -z "$TMUX" ]; then if [ $(tmux ls 2> /dev/null | grep "$SESSION_NAME" | wc -l) -gt 0 ]; then echo "Attach to exist TMUX-Session: $SESSION_NAME" tmux send-keys -t "$SESSION_NAME" "$0" C-m else echo "Create a new TMUX-Session: $SESSION_NAME" tmux new-session -d -s "$SESSION_NAME" tmux send-keys -t "$SESSION_NAME" "$0" C-m fi fi your script here.. Then you can show your scripts and attach to a session: Thats my variant.. If you have problems with tmux and 256-color settings (until the restart) : grep -q 'set -g default-terminal "xterm-256color"' ~/.tmux.conf || sed -i '1iset -g default-terminal "xterm-256color"' ~/.tmux.conf grep -q 'export TERM=xterm-256color' ~/.bash_profile || echo -e '\nexport TERM=xterm-256color' >> ~/.bash_profile . ~/.bash_profile For permanent workaround, you must add the following to the go file (/boot/config/go) : # TMUX 256-color workaround echo -e '\n# TMUX 256-color workaround' >> /root/.bash_profile echo 'export TERM=xterm-256color' >> /root/.bash_profile # TMUX configuration echo 'set -g default-terminal "xterm-256color"' > /root/.tmux.conf Edited April 12 by Amane 1 Quote Link to comment
sasbro97 Posted April 16 Share Posted April 16 Hey there. I'm maximum confused with a script I created. It works when I trigger it manually but never does on schedule / cronjob. I mean it runs but does not what it should and does when triggered manually. #!/bin/bash #description=This script updates all apps in Nextcloud. #arrayStarted=true #name=Nextcloud Auto-Update Apps # Befehl ausführen und Exit-Status speichern docker exec -u www-data nextcloud php /var/www/html/occ app:update --all docker_exit_status=$? if [ $docker_exit_status -eq 0 ]; then curl -fsS -m 10 --retry 5 --data-raw "$m" http://unraid-server:8003/ping/1505e87d-84e2-4806-a2a0-fa214d96cb17 echo -e "\nScript succeeded" This is the script. My docker container named nextcloud should automatically update the newer apps. When I press "Run Script" it works and apps are updated in the logs. On my set schedule "0 3 * * *" it does not work. I know the script is running because the curl request is sent. The logs look like this: Script Starting Apr 14, 2024 03:00.01 Full logs for this script are available at /tmp/user.scripts/tmpScripts/nextcloud_auto_update_apps/log.txt OK Script succeeded Script Finished Apr 14, 2024 03:00.10 Full logs for this script are available at /tmp/user.scripts/tmpScripts/nextcloud_auto_update_apps/log.txt Script Starting Apr 15, 2024 03:00.01 Full logs for this script are available at /tmp/user.scripts/tmpScripts/nextcloud_auto_update_apps/log.txt OK Script succeeded Script Finished Apr 15, 2024 03:00.10 Full logs for this script are available at /tmp/user.scripts/tmpScripts/nextcloud_auto_update_apps/log.txt Script Starting Apr 16, 2024 03:00.01 Full logs for this script are available at /tmp/user.scripts/tmpScripts/nextcloud_auto_update_apps/log.txt OK Script succeeded Script Finished Apr 16, 2024 03:00.02 Full logs for this script are available at /tmp/user.scripts/tmpScripts/nextcloud_auto_update_apps/log.txt And if I run the script manually now: Script location: /tmp/user.scripts/tmpScripts/nextcloud_auto_update_apps/script Note that closing this window will abort the execution of this script spreed new version available: 18.0.7 spreed updated keeweb new version available: 0.6.18 keeweb updated OK Script succeeded What could be the reason it does not work on schedule? Quote Link to comment
Amane Posted April 16 Share Posted April 16 (edited) Hi sasbro 2 hours ago, sasbro97 said: On my set schedule "0 3 * * *" it does not work Cron jobs do not run with the full user environment, which means some environment variables needed by docker or your script might not be set correctly. This can affect the execution of commands that rely on these variables. Add the line on top of your script: PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin I hope it helps. If not, test whether you can copy the script into the container and execute it with the scheduled user script - just for test Grüsse Edited April 16 by Amane 1 Quote Link to comment
JoeUnraidUser Posted April 17 Share Posted April 17 (edited) 22 hours ago, sasbro97 said: Hey there. I'm maximum confused with a script I created. It works when I trigger it manually but never does on schedule / cronjob. I mean it runs but does not what it should and does when triggered manually. What could be the reason it does not work on schedule? 20 hours ago, Amane said: Cron jobs do not run with the full user environment, which means some environment variables needed by docker or your script might not be set correctly. This can affect the execution of commands that rely on these variables. Try adding the "-l" option to bash and source the ".bash_profile". Example: #!/bin/bash -l source /root/.bash_profile set > /boot/logs/test.log Output: test.log Edited April 17 by JoeUnraidUser 1 Quote Link to comment
dopeytree Posted April 20 Share Posted April 20 Hi, Would this script work to monitor the GUI's nginx instance & restart if necessary? I'm trying to find out if "504 Gateway Time-out" actually appears in the log or is just displayed. #!/bin/bash NGINX_LOG="/var/log/nginx/error.log" # Monitor NGINX error log for specific error messages tail -n0 -F ${NGINX_LOG} | while read LINE; do if echo $LINE | grep -q "504 Gateway Time-out"; then echo "NGINX error detected: $LINE" echo "Restarting NGINX..." systemctl restart nginx fi done Its very occasionally but I want to avoid the GUI locking up like this: Quote Link to comment
Amane Posted April 20 Share Posted April 20 (edited) 11 hours ago, dopeytree said: GUI's nginx instance I hope you don't mean unraid? If so: (/etc/rc.d/rc.nginx {check|start|stop|term|restart|reload|renew|update|port|status|upgrade|rotate}) I think it should work and "504" should be enough, here are a few additional parameters: (just for starters - so that the script does not always restart nginx) #!/bin/bash NGINX_LOG="/var/log/nginx/error.log" MAX_RESTARTS=3 RESTART_COUNT=0 SLEEP_TIME=30 # secounds # Monitor NGINX error log for specific error messages tail -n0 -F ${NGINX_LOG} | while read LINE; do if echo $LINE | grep -q "504"; then if [ $RESTART_COUNT -lt $MAX_RESTARTS ]; then echo "NGINX error detected: $LINE" echo "Restarting NGINX..." /etc/rc.d/rc.nginx restart ((RESTART_COUNT++)) sleep $SLEEP_TIME else echo "Maximum restart limit reached, not restarting NGINX." break fi fi done Greetings Edited April 20 by Amane edit for unraid nginx 1 Quote Link to comment
camldr69 Posted April 20 Share Posted April 20 I have been using unraid for 5+ years. I am just getting in to CRON scheduling now. I am trying to set the schedule for an rsync job to run on the 1st-7th of the month ONLY if it is Saturday (so only the first Saturday of the month). I have set the following which I checked "crontab guru". It resolves to what I want there, but does not even execute in unraid. 25 12 */100,1-7 * SAT So it "should run at 12:25pm only on the 1st thru 7th of the month IF it is a Saturday Is there anyone that can help me out? Quote Link to comment
dopeytree Posted April 20 Share Posted April 20 Ace! Yeah just the unraid GUI nginx instance locks up & becomes un reachable, but ping all ok & all other sevices (shares, docker, VMs) are working and accessible. It's rare but it's annoying when it does happen. Quote Link to comment
Amane Posted April 20 Share Posted April 20 (edited) 21 minutes ago, dopeytree said: Yeah just the unraid GUI nginx instance ok, then you must change "systemctl restart nginx" to "rc.nginx restart". Unraid do not use systemd. /etc/rc.d/rc.nginx restart And I think you should backup your settings and reinstall unraid... or have you already tried that? Edited April 20 by Amane Quote Link to comment
Amane Posted April 20 Share Posted April 20 (edited) 5 hours ago, camldr69 said: I have been using unraid for 5+ years. I am just getting in to CRON scheduling now. I am trying to set the schedule for an rsync job to run on the 1st-7th of the month ONLY if it is Saturday (so only the first Saturday of the month). I have set the following which I checked "crontab guru". It resolves to what I want there, but does not even execute in unraid. 25 12 */100,1-7 * SAT So it "should run at 12:25pm only on the 1st thru 7th of the month IF it is a Saturday Is there anyone that can help me out? ok, that's tricky.. Try this: 25 12 1-7 * * [ "$(date +\%u)" -eq 6 ] && You can use the costom schedule in the user scripts an input this "workaround". At 12:25 on every day-of-month from 1 through 7, run and check if it Saturday ([ "$(date +\%u)" -eq 6 ]) and if so (&&), execute the command - But does it really have to be that complicated 😅 Edited April 20 by Amane Quote Link to comment
sasbro97 Posted April 21 Share Posted April 21 @Amane that actually worked! I would have never known that but now I learned something new. Thank you! 1 Quote Link to comment
camldr69 Posted April 21 Share Posted April 21 Thank you for the response, I will try this later today. The reason it seems so complicated, is I have rotating backups. I have a backup to a HDD on the 1st, 3rd and 5th saturday of the month and to a different HDD on the 2nd and 4th Saturday of the month. so I wouild have a 2 week window to recover a file if needed. Doing it this way should allow me to only need 2 scheduled backup jobs. Quote Link to comment
camldr69 Posted April 21 Share Posted April 21 Thank you so much, I have this running now. I have added to the above details to do what I am aiming at. below is what I have now got setup 00 8 1-7,15-21,29-31 * * [ "$(date +\%u)" -eq 6 ] && this runs at 8:00am ONLY on 1st, 3rd and 5th Saturday of the month 00 8 8-14,22-28 * * [ "$(date +\%u)" -eq 6 ] && this runs at 8:00am ONLY on 2nd, 4th Saturday of the month 1 Quote Link to comment
Dukobpa3 Posted April 22 Share Posted April 22 On 4/12/2024 at 3:20 AM, Amane said: Use tmux 😉 Thanks! 1 Quote Link to comment
Recommended Posts
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.