User Tools

Site Tools


strutture:roma1:experiments:ams2:internal_note_naia:bash_script

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

strutture:roma1:experiments:ams2:internal_note_naia:bash_script [2025/05/02 13:54] – created bartolon@infn.itstrutture:roma1:experiments:ams2:internal_note_naia:bash_script [2025/05/02 13:56] (current) bartolon@infn.it
Line 1: Line 1:
 +  #!/bin/bash 
 +  # Directory path where .root files are located 
 +  DIR="/storage/gpfs_ams/ams/groups/AMS-Italy/ntuples/v1.1.0/ISS.B1236/pass8" 
 +  # Output file path (explicitly in current directory) 
 +  OUTPUT="$(pwd)/file_list.txt" 
 +  # Minimum and maximum Unix timestamps for filtering 
 +  MIN_TIME=1640994629 
 +  MAX_TIME=1646093960 
 +  # Debug: Show current directory and permissions 
 +  echo "Current directory: $(pwd)" 
 +  echo "Permissions of current directory: $(ls -ld .)" 
 +  # Remove the output file if it already exists 
 +  echo "Removing $OUTPUT if it exists..." 
 +  rm -f "$OUTPUT" || { echo "Error: Cannot remove $OUTPUT, check permissions"; exit 1; } 
 +  # Test write permission 
 +  echo "Testing write permission in $(pwd)..." 
 +  touch "$OUTPUT" || { echo "Error: Cannot create $OUTPUT, no write permission"; exit 1; } 
 +  rm -f "$OUTPUT" 
 +  # Change to the input directory 
 +  echo "Changing to $DIR..." 
 +  cd "$DIR" || { echo "Error: Cannot change to $DIR"; exit 1; } 
 +  # Use ls and awk to filter and sort files in one go 
 +  echo "Generating $OUTPUT..." 
 +  ls -1 *.root | awk -v dir="$DIR" -v min="$MIN_TIME" -v max="$MAX_TIME"
 +  { 
 +  # Extract timestamp by removing .root extension 
 +  timestamp = substr($0, 1, length($0)-5) 
 +  # Check if timestamp is numeric and within range 
 +  if (timestamp ~ /^[0-9]+$/ && timestamp > min && timestamp < max) { 
 +  print dir "/" $0 
 +  } 
 +  }' | sort -n > "$OUTPUT" || { echo "Error: Cannot write to $OUTPUT during sort"; exit 1; } 
 +  # Count the number of lines in the output file 
 +  count=$(wc -l < "$OUTPUT"
 +  # Print completion message 
 +  echo "File $OUTPUT created successfully with $count entries."

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki