Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

My expect line "exec rm -fR /dir1/*" always errors out.

Status
Not open for further replies.

esterud

Technical User
Jan 30, 2003
7
US
I am writing an expect program which tests FTP security from file system ACLs. It is ran from a RedHat 9.0 machine. I need to do all preparation in the same expect program which tests FTP. The expect program first deletes all the files\dirs of a mounted dir and then copies over files and dirs which will later be tested against FTP.

On the preparation portion I am trying to run the line "exec /bin/rm -fR /mnt/servershare/*". However when this line runs it always errors out with the message "/bin/rm: cannot lstat '/mnt/servershare/*': No such file or directory". However the line "exec /bin/rm -f /mnt/servershare/filename" works just fine. Another note is that I can run "/bin/rm -fR /mnt/servershare/*" from the shell console and have no problems, nonetheless I will get the same message in the shell if no files exist in the directory I am deleting everything from.

I am thinking that expect is treating the asterix as a file name and not a wildcard. Anyone know how to solve my problem? I am using tcl-8.3.5-88 with expect 5.38.0.
 
I solved it myself! My solution was found thanks to my doing even more investigation in my always handy "Exploring Expect" book. The answer is using "glob". The following line (though rather long) performs my desired function:

foreach fileobject [glob -nocomplain /dir1/*] { catch {exec rm -fR $fileobject} }
 
Why you are spawning a shell process to do the unlink()
when file delete gives you better error traction is beyond
me, but glad it worked out for you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top