How do you pass an expect command result into a variable and then use it again?
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:
Are you sure you can use -L switch ?
It is giving me an error in my RHEL machine.
The -L switch works for me. i'm using fedora 8.
I found a way to get the variable. Kind of a round about, unclean way to get it but i got it.
what I do is get the length of the string and just copy over the string minus 2 characters.
expect -re "(.*)\n"
set OLDEST_PATH [lindex [split $expect_out(buffer) "\n"] 1]
set LENGTH [string length "$OLDEST_PATH"]
set LENGTH [expr $LENGTH - 2]
set OLDEST_PATH [string range "$OLDEST_PATH" 0 $LENGTH]
this seems to work to get rid of the \n character.
|All times are GMT -5. The time now is 05:24 AM.|