Monday, April 3, 2017

Bash: Scripting - part 4 - File Info ( Find files with the word "backup" in them (grep))

  1 #!/bin/bash
  2 #
  3 #  fileinfo.sh
  4 #  Find files with the word "backup" in them
  5 #
  6 MYFILES="/auto/home/homeb/d54712/sandbox/scripts/bash.d/*"
  7 #
  8 echo
  9
 10 for file in $MYFILES
 11 do
 12         if [  -f "$file" ] && [ "$(grep -i "backup" $file)" ]
 13         then
 14
 15                 ls -l $file |awk '{ print "Filename: " $9 "\n" "Timestamp: " $8"\n" "File size: " $5"\n" }' # print 3 field    s
 16
 17                 echo
 18         fi
 19
 20
 21
 22 done
 23
 24 exit 0







Results:

$ ./fileinfo2.sh
Filename: /auto/home/homeb/d54712/sandbox/scripts/bash.d/backup_t3psolarwebl2.inet_dev.sh
Timestamp: 10:23
File size: 1197

Filename: /auto/home/homeb/d54712/sandbox/scripts/bash.d/Daily_Archive.sh
Timestamp: 14:16
File size: 1756

Filename: /auto/home/homeb/d54712/sandbox/scripts/bash.d/fileinfo2.sh
Timestamp: 12:47
File size: 328

Filename: /auto/home/homeb/d54712/sandbox/scripts/bash.d/hourly_backup_t3psolarwebl2.inet_dev.sh
Timestamp: 14:23
File size: 1473

Filename: /auto/home/homeb/d54712/sandbox/scripts/bash.d/read2.sh
Timestamp: 10:11
File size: 628

Filename: /auto/home/homeb/d54712/sandbox/scripts/bash.d/read3.sh
Timestamp: 12:20
File size: 1152

Filename: /auto/home/homeb/d54712/sandbox/scripts/bash.d/read4.sh
Timestamp: 11:34
File size: 1334

Filename: /auto/home/homeb/d54712/sandbox/scripts/bash.d/read_file_create_variable1.sh
Timestamp: 14:46
File size: 1214

No comments:

Post a Comment