Skip to content

Instantly share code, notes, and snippets.

@xnumad
Last active May 1, 2020 22:00
Show Gist options
  • Save xnumad/074bc4373a547f52eecb23a0f7ea2f06 to your computer and use it in GitHub Desktop.
Save xnumad/074bc4373a547f52eecb23a0f7ea2f06 to your computer and use it in GitHub Desktop.
Check if files in list (TXT) do exist (and which files don't exist)
#!/bin/bash
input="$1" #The file to read from given as first argument
#File content looks like this:
#/a.txt
#/subdir/b.txt
#File needs to have a newline at the end to have the last line processed!
while IFS= read -r line #Repetitively read lines
do
line=$(echo "$line"|tr -d '\r') #remove \r character
line=$(echo "$line"|tr -d '\n') #remove \n character
#https://mywiki.wooledge.org/BashFAQ/089 if you run another command here
if [[ ! -f ".$line" ]]; then #if file at .$line (dot for current directory) does not exist, then
echo "$line" #output the path of the missing file
fi #end of "if branch"
done < "$input" #Give while loop an input value
@xnumad
Copy link
Author

xnumad commented Aug 3, 2019

Bash Shell Batch "DNS NXDOMAIN Check" and dirty output

Replace if branch with:
host -t ns "$line" | grep NXDOMAIN

Bash Shell Batch "DNS NXDOMAIN Check" and direct removal of line in file

Replace if branch with:

if host -t ns "$line" | grep NXDOMAIN; then #if domain in line does not exist, i.e. has no DNS records
  sed -i "/^$line/d" "$1" #remove line (remove the line that wholly contains the text of the current line in the file passed as argument) IRREVERSIBLE!
fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment