Skip to content

Instantly share code, notes, and snippets.

@ccarouge
Created October 27, 2019 23:15
Show Gist options
  • Save ccarouge/24b1419cfd009900e5f618f615bd25db to your computer and use it in GitHub Desktop.
Save ccarouge/24b1419cfd009900e5f618f615bd25db to your computer and use it in GitHub Desktop.
Add line to a bunch of files and run the files
#!/usr/bin/env python
import pathlib
import subprocess
# Get the list of files we want to modify
p=pathlib.Path('mom6')
filelist=list(p.glob('**/sync_output_to_gdata.sh'))
# Loop on the files
for f in filelist:
# Add the line
with f.open('a') as fo:
# I've added an 'echo' for testing but feel free to remove it
fo.write('echo rsync --ignore-existing --exclude ".nc." -vrltoD --safe-links restart*0 ${GDATADIR}\n')
# Make sure file is executable
f.chmod(0o700)
# Execute script
subprocess.run(str(f))
@navidcy
Copy link

navidcy commented Oct 28, 2019

thanks @ccarouge

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