Bash script not working to delete logs

I have the following script. Not sure what I am missing. I simply want to delete all logs older than 7 days

#!/bin/bash

# find and remove files last modified over 7 days ago from call recording directory
/usr/bin/find /var/spool/asterisk/monitor -type f -mtime +7 -exec rm -f {} \;

# remove empty directories
/usr/bin/find /var/spool/asterisk/monitor -type d -empty -delete

what happens when you run that script?
where do run ot from?
as what user?
what permissions does have?

I am running it as root. Owner and group are asterisk. Permissions 755

. . . .what happens when you run that script? . . .

bash -x /path/and/name/of/your.script

sorry. It doesn’t work either. I am pretty sure it did at one time.

Yes, but what gets printed to the terminal, (no mind-readers here :slight_smile: )

no errors. Is there a way to log it?

Copy and paste the poutput of the bash -x command from a shell. β€˜no errors’ is not likely what it printed.

You are pointing to the call recordings directory. If you want to delete logs, point at /var/log/asterisk. Better, use logrotate to do the work.

now it appears all of a sudden to work when I run manually. Maybe the crontab isn’t running which I have is:

0 0 * * * ~/scripts/archive.sh

Bash -x gives:
[root@PBX ~]# bash -x
+ bash -x
+ alias β€˜rm=rm -i’
+ alias β€˜cp=cp -i’
+ alias β€˜mv=mv -i’
+ β€˜[’ -f /etc/bashrc β€˜]’
+ . /etc/bashrc
++ β€˜[’ β€˜\s-\v$ ’ β€˜]’
++ β€˜[’ -z β€˜β€™ β€˜]’
++ case $TERM in
++ β€˜[’ -e /etc/sysconfig/bash-prompt-xterm β€˜]’
++ β€˜[’ 0 -ge 3405 β€˜]’
++ PROMPT_COMMAND=β€˜printf β€œ\033]0;%s@%s:%s\007” β€œ${USER}” "${HOSTNAME%%.}" β€œ${PWD/#$HOME/~}”’
++ shopt -s histappend
++ history -a
++ shopt -s checkwinsize
++ β€˜[’ '\s-\v$ ’ = β€˜\s-\v$ ’ β€˜]’
++ PS1=’[\u@\h \W]$ ’
++ shopt -q login_shell
++ β€˜[’ 0 -gt 199 β€˜]’
++ umask 022
++ SHELL=/bin/bash
++ for i in '/etc/profile.d/
.sh’
++ β€˜[’ -r /etc/profile.d/256term.sh β€˜]’
++ β€˜[’ β€˜[\u@\h \W]$ ’ β€˜]’
++ . /etc/profile.d/256term.sh
+++ local256=
+++ β€˜[’ -n β€˜β€™ β€˜]’
+++ β€˜[’ -n β€˜β€™ β€˜]’
+++ unset local256
++ for i in β€˜/etc/profile.d/.sh’
++ β€˜[’ -r /etc/profile.d/colorgrep.sh β€˜]’
++ β€˜[’ '[\u@\h \W]$ ’ β€˜]’
++ . /etc/profile.d/colorgrep.sh
+++ /usr/libexec/grepconf.sh -c
+++ alias β€˜grep=grep --color=auto’
+++ alias β€˜egrep=egrep --color=auto’
+++ alias β€˜fgrep=fgrep --color=auto’
++ for i in '/etc/profile.d/
.sh’
++ β€˜[’ -r /etc/profile.d/colorls.sh β€˜]’
++ β€˜[’ β€˜[\u@\h \W]$ ’ β€˜]’
++ . /etc/profile.d/colorls.sh
+++ β€˜[’ β€˜!’ -t 0 β€˜]’
+++ β€˜[’ -z β€˜β€™ β€˜]’
+++ alias β€˜ll=ls -l’
+++ alias β€˜l.=ls -d .’
+++ INCLUDE=
+++ COLORS=
+++ for colors in β€˜β€œ$HOME/.dir_colors.$TERM”’ β€˜β€œ$HOME/.dircolors.$TERM”’ β€˜β€œ$HOME/.dir_colors”’ β€˜β€œ$HOME/.dircolors”’
+++ β€˜[’ -e /root/.dir_colors.xterm-256color β€˜]’
+++ for colors in β€˜β€œ$HOME/.dir_colors.$TERM”’ β€˜β€œ$HOME/.dircolors.$TERM”’ β€˜β€œ$HOME/.dir_colors”’ β€˜β€œ$HOME/.dircolors”’
+++ β€˜[’ -e /root/.dircolors.xterm-256color β€˜]’
+++ for colors in β€˜β€œ$HOME/.dir_colors.$TERM”’ β€˜β€œ$HOME/.dircolors.$TERM”’ β€˜β€œ$HOME/.dir_colors”’ β€˜β€œ$HOME/.dircolors”’
+++ β€˜[’ -e /root/.dir_colors β€˜]’
+++ for colors in β€˜β€œ$HOME/.dir_colors.$TERM”’ β€˜β€œ$HOME/.dircolors.$TERM”’ β€˜β€œ$HOME/.dir_colors”’ β€˜β€œ$HOME/.dircolors”’
+++ β€˜[’ -e /root/.dircolors β€˜]’
+++ β€˜[’ -z β€˜β€™ β€˜]’
+++ β€˜[’ -e /etc/DIR_COLORS.xterm-256color β€˜]’
+++ β€˜[’ -z β€˜β€™ β€˜]’
+++ β€˜[’ -e /etc/DIR_COLORS.256color β€˜]’
++++ /usr/bin/tty -s
++++ /usr/bin/tput colors
+++ β€˜[’ x256 = x256 β€˜]’
+++ COLORS=/etc/DIR_COLORS.256color
+++ β€˜[’ -z /etc/DIR_COLORS.256color β€˜]’
+++ β€˜[’ -n /etc/DIR_COLORS.256color β€˜]’
+++ β€˜[’ -e β€˜β€™ β€˜]’
++++ /usr/bin/dircolors --sh /etc/DIR_COLORS.256color
+++ eval β€˜LS_COLORS=’''rs=0:di=38;5;27:ln=38;5;51:mh=44;38;5;15:pi=40;38;5;11:so=38;5;13:do=38;5;5:bd=48;5;232;38;5;11:cd=48;5;232;38;5;3:or=48;5;232;38;5;9:mi=05;48;5;232;38;5;15:su=48;5;196;38;5;15:sg=48;5;11;38;5;16:ca=48;5;196;38;5;226:tw=48;5;10;38;5;16:ow=48;5;10;38;5;21:st=48;5;21;38;5;15:ex=38;5;34:
.tar=38;5;9:.tgz=38;5;9:.arc=38;5;9:.arj=38;5;9:.taz=38;5;9:.lha=38;5;9:.lz4=38;5;9:.lzh=38;5;9:.lzma=38;5;9:.tlz=38;5;9:.txz=38;5;9:.tzo=38;5;9:.t7z=38;5;9:.zip=38;5;9:.z=38;5;9:.Z=38;5;9:.dz=38;5;9:.gz=38;5;9:.lrz=38;5;9:.lz=38;5;9:.lzo=38;5;9:.xz=38;5;9:.bz2=38;5;9:.bz=38;5;9:.tbz=38;5;9:.tbz2=38;5;9:.tz=38;5;9:.deb=38;5;9:.rpm=38;5;9:.jar=38;5;9:.war=38;5;9:.ear=38;5;9:.sar=38;5;9:.rar=38;5;9:.alz=38;5;9:.ace=38;5;9:.zoo=38;5;9:.cpio=38;5;9:.7z=38;5;9:.rz=38;5;9:.cab=38;5;9:.jpg=38;5;13:.jpeg=38;5;13:.gif=38;5;13:.bmp=38;5;13:.pbm=38;5;13:.pgm=38;5;13:.ppm=38;5;13:.tga=38;5;13:.xbm=38;5;13:.xpm=38;5;13:.tif=38;5;13:.tiff=38;5;13:.png=38;5;13:.svg=38;5;13:.svgz=38;5;13:.mng=38;5;13:.pcx=38;5;13:.mov=38;5;13:.mpg=38;5;13:.mpeg=38;5;13:.m2v=38;5;13:.mkv=38;5;13:.webm=38;5;13:.ogm=38;5;13:.mp4=38;5;13:.m4v=38;5;13:.mp4v=38;5;13:.vob=38;5;13:.qt=38;5;13:.nuv=38;5;13:.wmv=38;5;13:.asf=38;5;13:.rm=38;5;13:.rmvb=38;5;13:.flc=38;5;13:.avi=38;5;13:.fli=38;5;13:.flv=38;5;13:.gl=38;5;13:.dl=38;5;13:.xcf=38;5;13:.xwd=38;5;13:.yuv=38;5;13:.cgm=38;5;13:.emf=38;5;13:.axv=38;5;13:.anx=38;5;13:.ogv=38;5;13:.ogx=38;5;13:.aac=38;5;45:.au=38;5;45:.flac=38;5;45:.mid=38;5;45:.midi=38;5;45:.mka=38;5;45:.mp3=38;5;45:.mpc=38;5;45:.ogg=38;5;45:.ra=38;5;45:.wav=38;5;45:.axa=38;5;45:.oga=38;5;45:.spx=38;5;45:.xspf=38;5;45:’'’;
export LS_COLORS’
++++ LS_COLORS=β€˜rs=0:di=38;5;27:ln=38;5;51:mh=44;38;5;15:pi=40;38;5;11:so=38;5;13:do=38;5;5:bd=48;5;232;38;5;11:cd=48;5;232;38;5;3:or=48;5;232;38;5;9:mi=05;48;5;232;38;5;15:su=48;5;196;38;5;15:sg=48;5;11;38;5;16:ca=48;5;196;38;5;226:tw=48;5;10;38;5;16:ow=48;5;10;38;5;21:st=48;5;21;38;5;15:ex=38;5;34:.tar=38;5;9:.tgz=38;5;9:.arc=38;5;9:.arj=38;5;9:.taz=38;5;9:.lha=38;5;9:.lz4=38;5;9:.lzh=38;5;9:.lzma=38;5;9:.tlz=38;5;9:.txz=38;5;9:.tzo=38;5;9:.t7z=38;5;9:.zip=38;5;9:.z=38;5;9:.Z=38;5;9:.dz=38;5;9:.gz=38;5;9:.lrz=38;5;9:.lz=38;5;9:.lzo=38;5;9:.xz=38;5;9:.bz2=38;5;9:.bz=38;5;9:.tbz=38;5;9:.tbz2=38;5;9:.tz=38;5;9:.deb=38;5;9:.rpm=38;5;9:.jar=38;5;9:.war=38;5;9:.ear=38;5;9:.sar=38;5;9:.rar=38;5;9:.alz=38;5;9:.ace=38;5;9:.zoo=38;5;9:.cpio=38;5;9:.7z=38;5;9:.rz=38;5;9:.cab=38;5;9:.jpg=38;5;13:.jpeg=38;5;13:.gif=38;5;13:.bmp=38;5;13:.pbm=38;5;13:.pgm=38;5;13:.ppm=38;5;13:.tga=38;5;13:.xbm=38;5;13:.xpm=38;5;13:.tif=38;5;13:.tiff=38;5;13:.png=38;5;13:.svg=38;5;13:.svgz=38;5;13:.mng=38;5;13:.pcx=38;5;13:.mov=38;5;13:.mpg=38;5;13:.mpeg=38;5;13:.m2v=38;5;13:.mkv=38;5;13:.webm=38;5;13:.ogm=38;5;13:.mp4=38;5;13:.m4v=38;5;13:.mp4v=38;5;13:.vob=38;5;13:.qt=38;5;13:.nuv=38;5;13:.wmv=38;5;13:.asf=38;5;13:.rm=38;5;13:.rmvb=38;5;13:.flc=38;5;13:.avi=38;5;13:.fli=38;5;13:.flv=38;5;13:.gl=38;5;13:.dl=38;5;13:.xcf=38;5;13:.xwd=38;5;13:.yuv=38;5;13:.cgm=38;5;13:.emf=38;5;13:.axv=38;5;13:.anx=38;5;13:.ogv=38;5;13:.ogx=38;5;13:.aac=38;5;45:.au=38;5;45:.flac=38;5;45:.mid=38;5;45:.midi=38;5;45:.mka=38;5;45:.mp3=38;5;45:.mpc=38;5;45:.ogg=38;5;45:.ra=38;5;45:.wav=38;5;45:.axa=38;5;45:.oga=38;5;45:.spx=38;5;45:.xspf=38;5;45:’
++++ export LS_COLORS
+++ β€˜[’ -z 'rs=0:di=38;5;27:ln=38;5;51:mh=44;38;5;15:pi=40;38;5;11:so=38;5;13:do=38;5;5:bd=48;5;232;38;5;11:cd=48;5;232;38;5;3:or=48;5;232;38;5;9:mi=05;48;5;232;38;5;15:su=48;5;196;38;5;15:sg=48;5;11;38;5;16:ca=48;5;196;38;5;226:tw=48;5;10;38;5;16:ow=48;5;10;38;5;21:st=48;5;21;38;5;15:ex=38;5;34:
.tar=38;5;9:.tgz=38;5;9:.arc=38;5;9:.arj=38;5;9:.taz=38;5;9:.lha=38;5;9:.lz4=38;5;9:.lzh=38;5;9:.lzma=38;5;9:.tlz=38;5;9:.txz=38;5;9:.tzo=38;5;9:.t7z=38;5;9:.zip=38;5;9:.z=38;5;9:.Z=38;5;9:.dz=38;5;9:.gz=38;5;9:.lrz=38;5;9:.lz=38;5;9:.lzo=38;5;9:.xz=38;5;9:.bz2=38;5;9:.bz=38;5;9:.tbz=38;5;9:.tbz2=38;5;9:.tz=38;5;9:.deb=38;5;9:.rpm=38;5;9:.jar=38;5;9:.war=38;5;9:.ear=38;5;9:.sar=38;5;9:.rar=38;5;9:.alz=38;5;9:.ace=38;5;9:.zoo=38;5;9:.cpio=38;5;9:.7z=38;5;9:.rz=38;5;9:.cab=38;5;9:.jpg=38;5;13:.jpeg=38;5;13:.gif=38;5;13:.bmp=38;5;13:.pbm=38;5;13:.pgm=38;5;13:.ppm=38;5;13:.tga=38;5;13:.xbm=38;5;13:.xpm=38;5;13:.tif=38;5;13:.tiff=38;5;13:.png=38;5;13:.svg=38;5;13:.svgz=38;5;13:.mng=38;5;13:.pcx=38;5;13:.mov=38;5;13:.mpg=38;5;13:.mpeg=38;5;13:.m2v=38;5;13:.mkv=38;5;13:.webm=38;5;13:.ogm=38;5;13:.mp4=38;5;13:.m4v=38;5;13:.mp4v=38;5;13:.vob=38;5;13:.qt=38;5;13:.nuv=38;5;13:.wmv=38;5;13:.asf=38;5;13:.rm=38;5;13:.rmvb=38;5;13:.flc=38;5;13:.avi=38;5;13:.fli=38;5;13:.flv=38;5;13:.gl=38;5;13:.dl=38;5;13:.xcf=38;5;13:.xwd=38;5;13:.yuv=38;5;13:.cgm=38;5;13:.emf=38;5;13:.axv=38;5;13:.anx=38;5;13:.ogv=38;5;13:.ogx=38;5;13:.aac=38;5;45:.au=38;5;45:.flac=38;5;45:.mid=38;5;45:.midi=38;5;45:.mka=38;5;45:.mp3=38;5;45:.mpc=38;5;45:.ogg=38;5;45:.ra=38;5;45:.wav=38;5;45:.axa=38;5;45:.oga=38;5;45:.spx=38;5;45:.xspf=38;5;45:’ β€˜]’
+++ /usr/bin/grep -qi β€˜^COLOR.none’ /etc/DIR_COLORS.256color
+++ unset TMP COLORS INCLUDE
+++ alias β€˜ll=ls -l --color=auto’
+++ alias 'l.=ls -d .
--color=auto’
+++ alias β€˜ls=ls --color=auto’
++ for i in β€˜/etc/profile.d/.sh’
++ β€˜[’ -r /etc/profile.d/lang.sh β€˜]’
++ β€˜[’ '[\u@\h \W]$ ’ β€˜]’
++ . /etc/profile.d/lang.sh
+++ sourced=0
+++ β€˜[’ -n en_US.UTF-8 β€˜]’
+++ saved_lang=en_US.UTF-8
+++ β€˜[’ -f /root/.i18n β€˜]’
+++ LANG=en_US.UTF-8
+++ unset saved_lang
+++ β€˜[’ 0 = 1 β€˜]’
+++ unset sourced
+++ unset langfile
++ for i in '/etc/profile.d/
.sh’
++ β€˜[’ -r /etc/profile.d/less.sh β€˜]’
++ β€˜[’ β€˜[\u@\h \W]$ ’ β€˜]’
++ . /etc/profile.d/less.sh
+++ β€˜[’ -x /usr/bin/lesspipe.sh β€˜]’
+++ export β€˜LESSOPEN=||/usr/bin/lesspipe.sh %s’
+++ LESSOPEN=’||/usr/bin/lesspipe.sh %s’
++ for i in β€˜/etc/profile.d/*.sh’
++ β€˜[’ -r /etc/profile.d/motd.sh β€˜]’
++ β€˜[’ β€˜[\u@\h \W]$ ’ β€˜]’
++ . /etc/profile.d/motd.sh
+++ RUNAS=asterisk
++++ /usr/bin/id -u
+++ β€˜[’ 0 == 0 β€˜]’
+++ SU=’/bin/su asterisk -c’
+++ β€˜[’ '[\u@\h \W]$ ’ β€˜]’
+++ β€˜[’ -L /usr/sbin/fwconsole β€˜]’
++++ /bin/readlink /usr/sbin/fwconsole
+++ FWCONSOLE=/var/lib/asterisk/bin/fwconsole
+++ β€˜[’ -e /var/lib/asterisk/bin/fwconsole β€˜]’
+++ β€˜[’ β€˜/bin/su asterisk -c’ β€˜]’
+++ /bin/su asterisk -c β€˜/var/lib/asterisk/bin/fwconsole motd’
______ ______ ______ __ __
| | | ___ | ___ \ \ / /
| |
_ __ ___ ___ | |
/ /| |
/ / \ V /
| | | '__| / _ \ / _ | __/ | ___ \ /
| | | | | __/| __/| | | |
/ // /^\
_| || _| _|_| ___/ / /

    Current Network Configuration
    +-----------+-------------------+--------------------------+
    | Interface | MAC Address       | IP Addresses             |
    +-----------+-------------------+--------------------------+
    | eth0      | 00:00:00:00:00:00 | x.x.x.x           |
    |           |                   | fe80::xxx:xxxx:xxxx:xxxx |
    +-----------+-------------------+--------------------------+

    Please note most tasks should be handled through the GUI.
    You can access the GUI by typing one of the above IPs in to your web browser.
    For support please visit: 
        http://www.freepbx.org/support-and-professional-services

    ++ for i in '/etc/profile.d/*.sh'
    ++ '[' -r /etc/profile.d/vim.sh ']'
    ++ '[' '[\u@\h \W]\$ ' ']'
    ++ . /etc/profile.d/vim.sh
    +++ '[' -n '4.2.46(2)-release' -o -n '' -o -n '' ']'
    +++ '[' -x /usr/bin/id ']'
    ++++ /usr/bin/id -u
    +++ ID=0
    +++ '[' -n 0 -a 0 -le 200 ']'
    +++ return
    ++ for i in '/etc/profile.d/*.sh'
    ++ '[' -r /etc/profile.d/which2.sh ']'
    ++ '[' '[\u@\h \W]\$ ' ']'
    ++ . /etc/profile.d/which2.sh
    +++ alias 'which=alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
    ++ for i in '/etc/profile.d/*.sh'
    ++ '[' -r /etc/profile.d/z001-updates.sh ']'
    ++ '[' '[\u@\h \W]\$ ' ']'
    ++ . /etc/profile.d/z001-updates.sh
    +++ '[' '!' -e /etc/sangoma/schmooze.zl -a '!' -e /etc/sangoma/sangoma.zl ']'
    +++ '[' '!' xterm-256color -o xterm-256color == dumb ']'
    +++ WIDTH=60
    ++++ tput bold
    ++++ tput smul
    +++ BOLD=''
    ++++ tput sgr0
    +++ NORMAL=''
    ++++ tput setaf 1
    +++ RED=''
    ++++ tput setaf 2
    +++ GREEN=''
    ++++ tput setaf 3
    +++ YELLOW=''
    +++ '[' '' == update ']'
    +++ '[' '' == unicode ']'
    ++++ eval printf %.0s- '{1..60}'
    +++++ printf %.0s- 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
    +++ FULLWIDTH=------------------------------------------------------------
    ++++ eval printf '%.0s\ ' '{1..60}'
    +++++ printf '%.0s ' 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
    +++ BLANK='|                                                            |'
    +++ '[' '' == unicode ']'
    +++ echo -e +------------------------------------------------------------+
    +------------------------------------------------------------+
    +++ show_updates
    ++++ get_cacheage
    +++++ head -1
    +++++ ls --color=auto -t /var/cache/yum/x86_64/7/sng-pkgs/cachecookie
    ++++ COOKIEFILE=/var/cache/yum/x86_64/7/sng-pkgs/cachecookie
    ++++ '[' '!' -s /var/cache/listonline -o '!' /var/cache/yum/x86_64/7/sng-pkgs/cachecookie ']'
    +++++ stat -c %Y /var/cache/yum/x86_64/7/sng-pkgs/cachecookie
    ++++ S=1596585066
    +++++ date +%s
    ++++ echo 462
    ++++ return
    +++ AGE=462
    +++ '[' 462 == ERROR ']'
    +++ '[' 462 -gt 86400 ']'
    +++ '[' 462 -gt 3600 ']'
    +++ system_updates
    ++++ wc -l /var/cache/check-update
    ++++ awk ' { print $1 }'
    +++ UPDATES=0
    +++ '[' '!' 0 ']'
    +++ '[' 0 -eq 0 ']'
    +++ boxecho 'Your system is currently up to date!' 11
    +++ LINE='Your system is currently up to date!'
    +++ ANSIPADDING=11
    +++ PADDING=12
    +++ '[' 11 ']'
    +++ PADDING=23
    +++ '[' 23 -lt 0 ']'
    +++ '[' '' == unicode ']'
    ++++ eval printf '%.0s\ ' '{1..23}'
    +++++ printf '%.0s ' 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
    +++ echo -e '| Your system is currently up to date!                       |'
    | Your system is currently up to date!                       |
    +++ pbx_updates
    ++++ tail -1 /var/cache/listonline
    +++ LASTLINE=+----------------------+------------+-------------------------------------------+-------------+
    +++ [[ +----------------------+------------+-------------------------------------------+-------------+ != *\-\-\-\-\-\-\-\-\-\-* ]]
    ++++ wc -l
    ++++ grep --color=auto '| Broken' /var/cache/listonline
    +++ BROKEN=0
    ++++ wc -l
    ++++ grep --color=auto '| Not Installed' /var/cache/listonline
    +++ NOTINSTALLED=4
    ++++ grep --color=auto '| Online upgrade available' /var/cache/listonline
    ++++ wc -l
    +++ UPGRADEAVAIL=0
    ++++ wc -l
    ++++ grep --color=auto '| Disabled' /var/cache/listonline
    +++ DISABLED=0
    +++ '[' 0 -eq 0 ']'
    +++ boxecho 'Your PBX is up to date.' 11
    +++ LINE='Your PBX is up to date.'
    +++ ANSIPADDING=11
    +++ PADDING=25
    +++ '[' 11 ']'
    +++ PADDING=36
    +++ '[' 36 -lt 0 ']'
    +++ '[' '' == unicode ']'
    ++++ eval printf '%.0s\ ' '{1..36}'
    +++++ printf '%.0s ' 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
    +++ echo -e '| Your PBX is up to date.                                    |'
    | Your PBX is up to date.                                    |
    +++ '[' 0 -ne 0 ']'
    +++ DIS=
    +++ '[' 4 -ne 0 ']'
    ++++ plural 4
    ++++ '[' 4 -eq 1 ']'
    ++++ echo s
    +++ NI='4 Uninstalled modules'
    +++ '[' '' -a '4 Uninstalled modules' ']'
    +++ '[' '' ']'
    +++ '[' '4 Uninstalled modules' ']'
    +++ boxecho '  Also 4 Uninstalled modules.'
    +++ LINE='  Also 4 Uninstalled modules.'
    +++ ANSIPADDING=
    +++ PADDING=30
    +++ '[' '' ']'
    +++ '[' 30 -lt 0 ']'
    +++ '[' '' == unicode ']'
    ++++ eval printf '%.0s\ ' '{1..30}'
    +++++ printf '%.0s ' 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
    +++ echo -e '|   Also 4 Uninstalled modules.                              |'
    |   Also 4 Uninstalled modules.                              |
    +++ '[' 0 -ne 0 ']'
    +++ '[' '' == unicode ']'
    +++ echo -e +------------------------------------------------------------+
    +------------------------------------------------------------+
    ++ unset i
    ++ unset -f pathmunge
    ++ printf '\033]0;%s@%s:%s\007' root PBX '~'

am I supposed to give crontab asterisk rights maybe?

You are not making a lot of sense here. What are you trying to do? What is all this output supposed to be telling us?

I am just posting what bash -x gave me. No idea what its for lol. I just want to delete those logs and check nightly. Works manually

You keep saying logs but do you mean call recordings? Because that is what the commands will actually delete.

correct the recordings and logs. Sorry I had that added in my first script, but want to do both

Please read the instructions again carefully !!

bash -x

opens a bash shell noisily.

bash -x scriptname

opens a shell script named β€˜scriptname’ noisily in a bash shell.

Cron jobs are run by default in your β€˜sh’ environment (not bash) , as such your assumption of β€œ~/” needs to be explicitly rooted to the cron user the job belongs to, all jobs should be better tested with

su (youruser) -c β€œ/like/pulling/teeth.sh”

1 Like

Check the syntax for the mtime option. While I have been helping my inlaws move the the past two weeks, I’m thinking that doesn’t look like (I’m thinking β€œ-7d” instead of +7) but of course, after that long away, it could all just be a dream.

[root@PBX scripts]# bash -x archive.sh

  • /usr/bin/find /var/spool/asterisk/monitor -type f -mtime +7 -exec rm -f β€˜{}’ β€˜;’
  • /usr/bin/find /var/spool/asterisk/monitor -type d -empty -delete
    [root@PBX scripts]#

Better to use -delete instead of β€˜exec rm -f . . . .’ as you do for your directories because it is easy to get your β€˜quoting’ un escaped (’{}’ should be just {}) perhaps the forum mangled your post but that β€˜;’ at the end should be \;

Be that as it may, non-working quotes are other bad sysntax would have shown up if the script was run through bash -x

/usr/bin/find /var/spool/asterisk/monitor -type f -mtime +7

returned and of course

/usr/bin/find /var/spool/asterisk/monitor -type d -empty

would show any empty directories.

So before you try and delete anything make sure there is something to be deleted or you will be disappointed.

But again, these will be recorded calls older than 7 days, not logs

Out of curiosity, any reason for not using the logrotate application in linux?

I’m a google programmer lol. Not my thing but whatever makes it work. The script runs fine as stated and works but the crontab doesn’t seem to launch it