I'm trying to create a program that would locate the oldest file of a certain type on a server. Here's the commands:
OLDEST_PATH=`find -L / -depth -maxdepth 6 -mindepth 6 -type d | sort -f | head -1`
OLDEST_FILE=`find -L $OLDEST_PATH | grep .mp3 | sort -f | head -1`
ls -al $OLDEST_FILE
I'm writing this all in expect but I'm having problems. The main problem I have is whenever I try to run the first command, I can't seem to isolate the result of the OLDEST_PATH so that the 2nd command will work. There always seems to be a newline in the variable and the result is only "find -L" command running and it bypasses the variable. If I can just figure out how to get the 1st and 2nd command to work, then I can figure out the 3rd. Here's some code:
send "find -L / -depth -maxdepth 6 -mindepth 6 -type d | sort -f | head -1\r"
expect -re "(.*)\n"
set OLDEST_PATH [lindex [split $expect_out(buffer) " "] 16]
set OLDEST_PATH [string trimleft "$OLDEST_PATH" "-1"]
set OLDEST_PATH [string trim "$OLDEST_PATH" "\n"]
send "find -L $OLDEST_PATH | grep al2 | sort -f | head -1\r"
I know there is a better way to write this. I've tried multiple ways and this just happens to be the last way I've tried it. If you try running this, you'll notice that there is still carriage returns after the result of OLDEST_PATH and it prevents the 2nd "find" command from working properly. Any help would be great.