logo
down
shadow

If count of files in directory greater than x then restart service


If count of files in directory greater than x then restart service

By : Fodor Adrian
Date : October 18 2020, 01:08 AM
this one helps. Good Day, , This is very possible with PowerShell.
code :
If ((Get-ChildItem "C:\Q").Count -gt 12){
    # Restart you service here
    # The cmdlets Stop-service and Start-Service should help you
}


Share : facebook icon twitter icon
Shell script - read contents of directory and display those who have greater than 20 word count

Shell script - read contents of directory and display those who have greater than 20 word count


By : Ajay Kumar
Date : March 29 2020, 07:55 AM
hope this fix your issue I believe your question is: how can a shell script print the names of the files in a given directory that contain more than 20 words. If that is the case, one simple solution would be:
code :
for i in $dir/*; do 
    test -f "$i" && test $( wc -w < "$i" ) -gt 20 && echo "$i"
done
How to delete all files and directory under a given directory based on modification time greater than 2 days

How to delete all files and directory under a given directory based on modification time greater than 2 days


By : Nitish
Date : March 29 2020, 07:55 AM
To fix the issue you can do Based on what I read from the the python docs, the following wouldn't be equivalent, but it would be close:
code :
do {
   opendir(my $dh, $path)
      or die("Can't open directory \"$path\": $!\n");

   my @files = grep !/^\.\.?\z/, readdir($dh);

   closedir($dh)
      or die("Error reading directory \"$path\": $!\n");

   @files
}
count the files and delete the remaining files if the count is greater the given limit

count the files and delete the remaining files if the count is greater the given limit


By : Fahim Siddiqui
Date : March 29 2020, 07:55 AM
may help you . find has already provided the number of sub-directories below START. The count is increased by 1 due to inclusion of the PWD (.). So to get the number of sub-directories below START excluding START itself:
code :
find "$START" -type d | echo "subdirs: $(($(wc -l)-1))"
subdirs: 6
find "$START" -type f | echo "files: $(wc -l)"
files: 128
#!/bin/bash

start="${1:-$PWD}"

[ -d "$start" ] || {
    printf "error: directory not accessible '%s'\n", "$start"
    exit 1;
}

declare -a files                                # declare an array to hold files

for i in $(find "$start" -type d); do           # find all subdirs

    [ "$i" = "$PWD" ] && continue               # skip the current (top) dir

    printf "\nprocessing: %s\n\n" "$i"          # simple dir info output (not needed)

    files=( $(find "$i" -maxdepth 1 -type f) )  # fill array w/files in each dir (no subs)
    if [ "${#files[@]}" -gt 0 ]; then           # if subdir has files
        echo "num files: ${#files[@]}"          # No. of files in dir info (not needed)
        for ((j=0; j<${#files[@]}; j++)); do    # for each file
            if [ "$j" -lt 3 ]; then             # if first 3, keep
                printf "  keeping : %s\n" "${files[j]}"
            else                                # files 4+ delete
                printf "  deleting: %s\n" "${files[j]}"
            fi
        done
    fi
done
$ bash del3dirs.sh

processing: /home/david/scr/tmp/stack/sav

num files: 5
  keeping : /home/david/scr/tmp/stack/sav/dna.sh
  keeping : /home/david/scr/tmp/stack/sav/dict-sort_1.sh
  keeping : /home/david/scr/tmp/stack/sav/_20140702-211202.tar.xz
  deleting: /home/david/scr/tmp/stack/sav/dict-sort.sh
  deleting: /home/david/scr/tmp/stack/sav/dict-sort_2.sh

processing: /home/david/scr/tmp/stack/tmp

num files: 13
  keeping : /home/david/scr/tmp/stack/tmp/File1950text.doc
  keeping : /home/david/scr/tmp/stack/tmp/vcs1dump
  keeping : /home/david/scr/tmp/stack/tmp/File2014text.xls
  deleting: /home/david/scr/tmp/stack/tmp/File307list.cvs
  deleting: /home/david/scr/tmp/stack/tmp/vcsa1dump
  (snip)

processing: /home/david/scr/tmp/stack/tmp/a

num files: 2
  keeping : /home/david/scr/tmp/stack/tmp/a/b/b.txt
  keeping : /home/david/scr/tmp/stack/tmp/a/b/b.txt.bac

processing: /home/david/scr/tmp/stack/dat

num files: 68
  keeping : /home/david/scr/tmp/stack/dat/outlier.dat
  keeping : /home/david/scr/tmp/stack/dat/3line.dat.sav
  keeping : /home/david/scr/tmp/stack/dat/f1f2.dat
  deleting: /home/david/scr/tmp/stack/dat/datb.dat
  deleting: /home/david/scr/tmp/stack/dat/lline.dat
  deleting: /home/david/scr/tmp/stack/dat/vowels.txt
How to provide a restart count to systemd service

How to provide a restart count to systemd service


By : user7328045
Date : March 29 2020, 07:55 AM
will help you Do you have the journal ? If you do, then you can get the count like this:
code :
journalctl -b -u myservicename.service |grep -c Started
ECS Service in hung state if desired count of container is greater than 1

ECS Service in hung state if desired count of container is greater than 1


By : Sabrina S.
Date : March 29 2020, 07:55 AM
this will help To help troubleshooting, you can go to the AWS console, ECS, click your cluster, then on the service tab, click your service name. Then, click the events tab, and you'll probably see something like:
shadow
Privacy Policy - Terms - Contact Us © soohba.com