Im working on a unix script which gets connected to a remote server through SFTP and gets file mentioned in a pattern.
I have to change the permissions of those files.
Problem is i can not create a temp file to hold patterns. Patterns will be stored in variable.
I have developed a code to capture the files which we get in FTP process.
FILES="pattern1" ### Patterns used to get
GETFILES=`for i in $FILES; do print "get "$i""; done`
echo "cd /$FILEDIR/Inbox
bye" > $BATCHFILE ### creating temp BATCHFILE to use in SFTP process
## FTP PART ###
MFTCMD="sftp $SSHOPTIONS -o IdentityFile=$HDIR/.ssh/$PRIVATEKEY -b $BATCHFILE $SFTPUSER@$MFTHOST"
MYFILES=`find . -newer $BATCHFILE | grep "$FILES" `
if [ "$PERMISSIONS" != "" ]; then
chmod $PERMISSIONS $MYFILES
if [ $? -eq 0 ] ; then
echo " SSH set permissions of $MYFILES to $PERMISSIONS"
echo "SSH command \"chmod $PERMISSIONS $MYFILES\" failed with exit code $?"
This works fine when there is only one pattern.
The grep can not work search multiple patterns unless patterns are fed through a file.
I tried using a while loop. but not able to find a solution.
echo $FILES | while read line
find . -newer $BATCHFILE | grep "$line"
Please help me how to use grep to read multiple patterns from a variable.
Thanks very much in advance.