Can anyone help me with the while loop in expect script. Following is my scenario:
one of my process is running and looking for a file
as soon as the file is dropped the proces then processes the file and creates a control file ".ctl" to indicate end of process for that file
after the above process, I need to rename the ".ctl" file to ".done" as part of the second processing
How do I write an expect script to check if the file exists in the directory and then only rename the file from ".ctl" to ".done" extension. I can work with the if condition, but my expect script is the one that drops the file and will have to wait till the ".ctl" file is created by the process and then my expect script will rename the .ctl file to .done
For some reason the above code doesnt do anything. I am not sure if it's the syntax or something that I am overlooking. Or is it plain that I cant use "file exists" command in a while loop.
Please advice
Ouch. I could probably advise but your outlined procedure is very wrong.
If all in tcl this will require a moderate amount of work and very little expect as
explained.
I could do that using shell script, but I am automating some tests where in the script auto logs-in a remote server, then navigate to the specific directory where the data is, then touch the data file with .ready extension, and then waits for the process to complete processing (creates a .ctl file), after which my using my expect script, I'll have to rename .ctl file to .done extension
Since you are driving the interaction remotely and possibly dealing with multiple logins concurrently the way I'd do this is to use an interact for each spawn_id (after successful setup) with a procedure that periodically polls the remote filesystem, makes the necessary changes and informs you of completion or error.
Here is a basic example from some code I wrote several years ago. You may want to check the interact examples out at the expect site and at active state.
Thanks for your help ramen_noodle. I tried something else last night and it worked. The while statement support "file exists" feature and I was able to work it out. I will use your input regarding multiple access/login which will boost my script. Thanks a bunch for your quick responses and help.
Hi there sorry to dig up an old thread but I couldn't find a thread that was similiar.
I'm trying to get an expect script to look for a specific shell prompt and then execute some simples commands when it detects that prompt.
So say I log in to a box, and the shell prompt is
abc#
it executes commands
and if my script logs in to another box, it would be a different shell prompt like:
def#
How do i get my expect script to recognize that? Reason being is because i need to login as root to execute these commands and the prompts are different from server to server.