I've built a script for applying a patch to a server. It works great(ish) and makes backups of any files it overwrites using the --backup=t
syntax. Now I need to move these backups as they are no longer ending .php
but are ending instead .php.~1~
which means if you view the file via a web browser you'd get the plain text output of the php
script
I can almost do this when logged on to the webserver fine using the following command
for I in `sudo find /path/to/web/root -type f \( -name "*.*~1~" \)` ; do sudo mv $I ~/$I`date +%Y%m%d` ; done
There's a slight issue that the find command returns the fullpath to the file and as such $I
needs truncating after it's been used in the mv, but that's another issue and outside the scope of this question
The problem I'm having is that when I try to execute this command remotely I get the following error
find: command not found
date: command not found
To address concerns raised about the output of find
not being suitable to iterate over I knocked up this quick test
findtest lukes$ ls web
1 1.~1~ 2 2.~1~ 3 4 6 6.~1~ 7 8 9
findtest lukes$ for I in `sudo find web -type f \( -name "*.*~1~" \)` ; do sudo mv $I $I`date +%Y%m%d` ; done
findtest lukes$ ls web
1 2 3 6 7 9
1.~1~20140201 2.~1~20140201 4 6.~1~20140201 8